Import asyncpg_0.18.2.orig.tar.gz
authorPiotr Ożarowski <piotr@debian.org>
Thu, 6 Dec 2018 23:01:28 +0000 (23:01 +0000)
committerPiotr Ożarowski <piotr@debian.org>
Thu, 6 Dec 2018 23:01:28 +0000 (23:01 +0000)
[dgit import orig asyncpg_0.18.2.orig.tar.gz]

121 files changed:
LICENSE [new file with mode: 0644]
MANIFEST.in [new file with mode: 0644]
Makefile [new file with mode: 0644]
PKG-INFO [new file with mode: 0644]
README.rst [new file with mode: 0644]
asyncpg.egg-info/PKG-INFO [new file with mode: 0644]
asyncpg.egg-info/SOURCES.txt [new file with mode: 0644]
asyncpg.egg-info/dependency_links.txt [new file with mode: 0644]
asyncpg.egg-info/not-zip-safe [new file with mode: 0644]
asyncpg.egg-info/requires.txt [new file with mode: 0644]
asyncpg.egg-info/top_level.txt [new file with mode: 0644]
asyncpg/__init__.py [new file with mode: 0644]
asyncpg/_testbase/__init__.py [new file with mode: 0644]
asyncpg/_testbase/fuzzer.py [new file with mode: 0644]
asyncpg/cluster.py [new file with mode: 0644]
asyncpg/compat.py [new file with mode: 0644]
asyncpg/connect_utils.py [new file with mode: 0644]
asyncpg/connection.py [new file with mode: 0644]
asyncpg/connresource.py [new file with mode: 0644]
asyncpg/cursor.py [new file with mode: 0644]
asyncpg/exceptions/__init__.py [new file with mode: 0644]
asyncpg/exceptions/_base.py [new file with mode: 0644]
asyncpg/introspection.py [new file with mode: 0644]
asyncpg/pgproto/__init__.pxd [new file with mode: 0644]
asyncpg/pgproto/__init__.py [new file with mode: 0644]
asyncpg/pgproto/buffer.pxd [new file with mode: 0644]
asyncpg/pgproto/buffer.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/__init__.pxd [new file with mode: 0644]
asyncpg/pgproto/codecs/bits.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/bytea.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/context.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/datetime.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/float.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/geometry.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/hstore.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/int.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/json.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/misc.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/network.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/numeric.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/text.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/tid.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/txid.pyx [new file with mode: 0644]
asyncpg/pgproto/codecs/uuid.pyx [new file with mode: 0644]
asyncpg/pgproto/consts.pxi [new file with mode: 0644]
asyncpg/pgproto/cpythonx.pxd [new file with mode: 0644]
asyncpg/pgproto/debug.h [new file with mode: 0644]
asyncpg/pgproto/debug.pxd [new file with mode: 0644]
asyncpg/pgproto/exceptions.py [new file with mode: 0644]
asyncpg/pgproto/frb.pxd [new file with mode: 0644]
asyncpg/pgproto/frb.pyx [new file with mode: 0644]
asyncpg/pgproto/hton.h [new file with mode: 0644]
asyncpg/pgproto/hton.pxd [new file with mode: 0644]
asyncpg/pgproto/pgproto.c [new file with mode: 0644]
asyncpg/pgproto/pgproto.pxd [new file with mode: 0644]
asyncpg/pgproto/pgproto.pyx [new file with mode: 0644]
asyncpg/pgproto/types.py [new file with mode: 0644]
asyncpg/pool.py [new file with mode: 0644]
asyncpg/prepared_stmt.py [new file with mode: 0644]
asyncpg/protocol/__init__.py [new file with mode: 0644]
asyncpg/protocol/codecs/__init__.py [new file with mode: 0644]
asyncpg/protocol/codecs/array.pyx [new file with mode: 0644]
asyncpg/protocol/codecs/base.pxd [new file with mode: 0644]
asyncpg/protocol/codecs/base.pyx [new file with mode: 0644]
asyncpg/protocol/codecs/pgproto.pyx [new file with mode: 0644]
asyncpg/protocol/codecs/range.pyx [new file with mode: 0644]
asyncpg/protocol/codecs/record.pyx [new file with mode: 0644]
asyncpg/protocol/codecs/textutils.pyx [new file with mode: 0644]
asyncpg/protocol/consts.pxi [new file with mode: 0644]
asyncpg/protocol/coreproto.pxd [new file with mode: 0644]
asyncpg/protocol/coreproto.pyx [new file with mode: 0644]
asyncpg/protocol/cpythonx.pxd [new file with mode: 0644]
asyncpg/protocol/encodings.pyx [new file with mode: 0644]
asyncpg/protocol/pgtypes.pxi [new file with mode: 0644]
asyncpg/protocol/prepared_stmt.pxd [new file with mode: 0644]
asyncpg/protocol/prepared_stmt.pyx [new file with mode: 0644]
asyncpg/protocol/protocol.c [new file with mode: 0644]
asyncpg/protocol/protocol.pxd [new file with mode: 0644]
asyncpg/protocol/protocol.pyx [new file with mode: 0644]
asyncpg/protocol/record/__init__.pxd [new file with mode: 0644]
asyncpg/protocol/record/recordobj.c [new file with mode: 0644]
asyncpg/protocol/record/recordobj.h [new file with mode: 0644]
asyncpg/protocol/settings.pxd [new file with mode: 0644]
asyncpg/protocol/settings.pyx [new file with mode: 0644]
asyncpg/serverversion.py [new file with mode: 0644]
asyncpg/transaction.py [new file with mode: 0644]
asyncpg/types.py [new file with mode: 0644]
asyncpg/utils.py [new file with mode: 0644]
docs/api/index.rst [new file with mode: 0644]
docs/conf.py [new file with mode: 0644]
docs/faq.rst [new file with mode: 0644]
docs/index.rst [new file with mode: 0644]
docs/installation.rst [new file with mode: 0644]
docs/usage.rst [new file with mode: 0644]
performance.png [new file with mode: 0644]
setup.cfg [new file with mode: 0644]
setup.py [new file with mode: 0644]
tests/__init__.py [new file with mode: 0644]
tests/certs/ca.cert.pem [new file with mode: 0644]
tests/certs/server.cert.pem [new file with mode: 0644]
tests/certs/server.key.pem [new file with mode: 0644]
tests/test__environment.py [new file with mode: 0644]
tests/test__sourcecode.py [new file with mode: 0644]
tests/test_adversity.py [new file with mode: 0644]
tests/test_cache_invalidation.py [new file with mode: 0644]
tests/test_cancellation.py [new file with mode: 0644]
tests/test_codecs.py [new file with mode: 0644]
tests/test_connect.py [new file with mode: 0644]
tests/test_copy.py [new file with mode: 0644]
tests/test_cursor.py [new file with mode: 0644]
tests/test_exceptions.py [new file with mode: 0644]
tests/test_execute.py [new file with mode: 0644]
tests/test_introspection.py [new file with mode: 0644]
tests/test_listeners.py [new file with mode: 0644]
tests/test_pool.py [new file with mode: 0644]
tests/test_prepare.py [new file with mode: 0644]
tests/test_record.py [new file with mode: 0644]
tests/test_test.py [new file with mode: 0644]
tests/test_timeout.py [new file with mode: 0644]
tests/test_transaction.py [new file with mode: 0644]
tests/test_utils.py [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..d931386
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (C) 2016-present the asyncpg authors and contributors.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright (C) 2016-present the asyncpg authors and contributors
+   <see AUTHORS file>
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644 (file)
index 0000000..e4cfbc3
--- /dev/null
@@ -0,0 +1,5 @@
+recursive-include docs *.py *.rst
+recursive-include examples *.py
+recursive-include tests *.py *.pem
+recursive-include asyncpg *.pyx *.pxd *.pxi *.py *.c *.h
+include LICENSE README.rst Makefile performance.png
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..698f011
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,46 @@
+.PHONY: compile debug test quicktest clean all
+
+
+PYTHON ?= python
+ROOT = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
+
+
+all: compile
+
+
+clean:
+       rm -fr dist/ doc/_build/
+       rm -fr asyncpg/pgproto/*.c asyncpg/pgproto/*.html
+       rm -fr asyncpg/pgproto/codecs/*.html
+       rm -fr asyncpg/protocol/*.c asyncpg/protocol/*.html
+       rm -fr asyncpg/protocol/*.so build *.egg-info
+       rm -fr asyncpg/protocol/codecs/*.html
+       find . -name '__pycache__' | xargs rm -rf
+
+
+compile:
+       $(PYTHON) setup.py build_ext --inplace --cython-always
+
+
+debug:
+       ASYNCPG_DEBUG=1 $(PYTHON) setup.py build_ext --inplace
+
+
+test:
+       PYTHONASYNCIODEBUG=1 $(PYTHON) setup.py test
+       $(PYTHON) setup.py test
+       USE_UVLOOP=1 $(PYTHON) setup.py test
+
+
+testinstalled:
+       cd /tmp && $(PYTHON) $(ROOT)/tests/__init__.py
+       cd /tmp && USE_UVLOOP=1 $(PYTHON) $(ROOT)/tests/__init__.py
+
+
+quicktest:
+       $(PYTHON) setup.py test
+
+
+htmldocs:
+       $(PYTHON) setup.py build_ext --inplace
+       $(MAKE) -C docs html
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644 (file)
index 0000000..30d507e
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,120 @@
+Metadata-Version: 2.1
+Name: asyncpg
+Version: 0.18.2
+Summary: An asyncio PosgtreSQL driver
+Home-page: https://github.com/MagicStack/asyncpg
+Author: MagicStack Inc
+Author-email: hello@magic.io
+License: Apache License, Version 2.0
+Description: asyncpg -- A fast PostgreSQL Database Client Library for Python/asyncio
+        =======================================================================
+        
+        .. image:: https://travis-ci.org/MagicStack/asyncpg.svg?branch=master
+            :target: https://travis-ci.org/MagicStack/asyncpg
+        
+        .. image:: https://ci.appveyor.com/api/projects/status/9rwppnxphgc8bqoj/branch/master?svg=true
+            :target: https://ci.appveyor.com/project/magicstack/asyncpg
+        
+        .. image:: https://img.shields.io/pypi/v/asyncpg.svg
+            :target: https://pypi.python.org/pypi/asyncpg
+        
+        **asyncpg** is a database interface library designed specifically for
+        PostgreSQL and Python/asyncio.  asyncpg is an efficient, clean implementation
+        of PostgreSQL server binary protocol for use with Python's ``asyncio``
+        framework.  You can read more about asyncpg in an introductory
+        `blog post <http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/>`_.
+        
+        asyncpg requires Python 3.5 or later and is supported for PostgreSQL
+        versions 9.2 to 11.
+        
+        
+        Documentation
+        -------------
+        
+        The project documentation can be found
+        `here <https://magicstack.github.io/asyncpg/current/>`_.
+        
+        
+        Performance
+        -----------
+        
+        In our testing asyncpg is, on average, **3x** faster than psycopg2
+        (and its asyncio variant -- aiopg).
+        
+        .. image:: performance.png
+            :target: http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/
+        
+        The above results are a geometric mean of benchmarks obtained with PostgreSQL
+        `client driver benchmarking toolbench <https://github.com/MagicStack/pgbench>`_.
+        
+        
+        Features
+        --------
+        
+        asyncpg implements PostgreSQL server protocol natively and exposes its
+        features directly, as opposed to hiding them behind a generic facade
+        like DB-API.
+        
+        This enables asyncpg to have easy-to-use support for:
+        
+        * **prepared statements**
+        * **scrollable cursors**
+        * **partial iteration** on query results
+        * automatic encoding and decoding of composite types, arrays,
+          and any combination of those
+        * straightforward support for custom data types
+        
+        
+        Installation
+        ------------
+        
+        asyncpg is available on PyPI and has no dependencies.
+        Use pip to install::
+        
+            $ pip install asyncpg
+        
+        
+        Basic Usage
+        -----------
+        
+        .. code-block:: python
+        
+            import asyncio
+            import asyncpg
+        
+            async def run():
+                conn = await asyncpg.connect(user='user', password='password',
+                                             database='database', host='127.0.0.1')
+                values = await conn.fetch('''SELECT * FROM mytable''')
+                await conn.close()
+        
+            loop = asyncio.get_event_loop()
+            loop.run_until_complete(run())
+        
+        
+        License
+        -------
+        
+        asyncpg is developed and distributed under the Apache 2.0 license.
+        
+Platform: macOS
+Platform: POSIX
+Platform: Windows
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Framework :: AsyncIO
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Programming Language :: Python :: 3 :: Only
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Programming Language :: Python :: 3.7
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Topic :: Database :: Front-Ends
+Provides: asyncpg
+Requires-Python: >=3.5.0
+Provides-Extra: docs
+Provides-Extra: test
+Provides-Extra: dev
diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..8b6d5a9
--- /dev/null
@@ -0,0 +1,90 @@
+asyncpg -- A fast PostgreSQL Database Client Library for Python/asyncio
+=======================================================================
+
+.. image:: https://travis-ci.org/MagicStack/asyncpg.svg?branch=master
+    :target: https://travis-ci.org/MagicStack/asyncpg
+
+.. image:: https://ci.appveyor.com/api/projects/status/9rwppnxphgc8bqoj/branch/master?svg=true
+    :target: https://ci.appveyor.com/project/magicstack/asyncpg
+
+.. image:: https://img.shields.io/pypi/v/asyncpg.svg
+    :target: https://pypi.python.org/pypi/asyncpg
+
+**asyncpg** is a database interface library designed specifically for
+PostgreSQL and Python/asyncio.  asyncpg is an efficient, clean implementation
+of PostgreSQL server binary protocol for use with Python's ``asyncio``
+framework.  You can read more about asyncpg in an introductory
+`blog post <http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/>`_.
+
+asyncpg requires Python 3.5 or later and is supported for PostgreSQL
+versions 9.2 to 11.
+
+
+Documentation
+-------------
+
+The project documentation can be found
+`here <https://magicstack.github.io/asyncpg/current/>`_.
+
+
+Performance
+-----------
+
+In our testing asyncpg is, on average, **3x** faster than psycopg2
+(and its asyncio variant -- aiopg).
+
+.. image:: performance.png
+    :target: http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/
+
+The above results are a geometric mean of benchmarks obtained with PostgreSQL
+`client driver benchmarking toolbench <https://github.com/MagicStack/pgbench>`_.
+
+
+Features
+--------
+
+asyncpg implements PostgreSQL server protocol natively and exposes its
+features directly, as opposed to hiding them behind a generic facade
+like DB-API.
+
+This enables asyncpg to have easy-to-use support for:
+
+* **prepared statements**
+* **scrollable cursors**
+* **partial iteration** on query results
+* automatic encoding and decoding of composite types, arrays,
+  and any combination of those
+* straightforward support for custom data types
+
+
+Installation
+------------
+
+asyncpg is available on PyPI and has no dependencies.
+Use pip to install::
+
+    $ pip install asyncpg
+
+
+Basic Usage
+-----------
+
+.. code-block:: python
+
+    import asyncio
+    import asyncpg
+
+    async def run():
+        conn = await asyncpg.connect(user='user', password='password',
+                                     database='database', host='127.0.0.1')
+        values = await conn.fetch('''SELECT * FROM mytable''')
+        await conn.close()
+
+    loop = asyncio.get_event_loop()
+    loop.run_until_complete(run())
+
+
+License
+-------
+
+asyncpg is developed and distributed under the Apache 2.0 license.
diff --git a/asyncpg.egg-info/PKG-INFO b/asyncpg.egg-info/PKG-INFO
new file mode 100644 (file)
index 0000000..30d507e
--- /dev/null
@@ -0,0 +1,120 @@
+Metadata-Version: 2.1
+Name: asyncpg
+Version: 0.18.2
+Summary: An asyncio PosgtreSQL driver
+Home-page: https://github.com/MagicStack/asyncpg
+Author: MagicStack Inc
+Author-email: hello@magic.io
+License: Apache License, Version 2.0
+Description: asyncpg -- A fast PostgreSQL Database Client Library for Python/asyncio
+        =======================================================================
+        
+        .. image:: https://travis-ci.org/MagicStack/asyncpg.svg?branch=master
+            :target: https://travis-ci.org/MagicStack/asyncpg
+        
+        .. image:: https://ci.appveyor.com/api/projects/status/9rwppnxphgc8bqoj/branch/master?svg=true
+            :target: https://ci.appveyor.com/project/magicstack/asyncpg
+        
+        .. image:: https://img.shields.io/pypi/v/asyncpg.svg
+            :target: https://pypi.python.org/pypi/asyncpg
+        
+        **asyncpg** is a database interface library designed specifically for
+        PostgreSQL and Python/asyncio.  asyncpg is an efficient, clean implementation
+        of PostgreSQL server binary protocol for use with Python's ``asyncio``
+        framework.  You can read more about asyncpg in an introductory
+        `blog post <http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/>`_.
+        
+        asyncpg requires Python 3.5 or later and is supported for PostgreSQL
+        versions 9.2 to 11.
+        
+        
+        Documentation
+        -------------
+        
+        The project documentation can be found
+        `here <https://magicstack.github.io/asyncpg/current/>`_.
+        
+        
+        Performance
+        -----------
+        
+        In our testing asyncpg is, on average, **3x** faster than psycopg2
+        (and its asyncio variant -- aiopg).
+        
+        .. image:: performance.png
+            :target: http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/
+        
+        The above results are a geometric mean of benchmarks obtained with PostgreSQL
+        `client driver benchmarking toolbench <https://github.com/MagicStack/pgbench>`_.
+        
+        
+        Features
+        --------
+        
+        asyncpg implements PostgreSQL server protocol natively and exposes its
+        features directly, as opposed to hiding them behind a generic facade
+        like DB-API.
+        
+        This enables asyncpg to have easy-to-use support for:
+        
+        * **prepared statements**
+        * **scrollable cursors**
+        * **partial iteration** on query results
+        * automatic encoding and decoding of composite types, arrays,
+          and any combination of those
+        * straightforward support for custom data types
+        
+        
+        Installation
+        ------------
+        
+        asyncpg is available on PyPI and has no dependencies.
+        Use pip to install::
+        
+            $ pip install asyncpg
+        
+        
+        Basic Usage
+        -----------
+        
+        .. code-block:: python
+        
+            import asyncio
+            import asyncpg
+        
+            async def run():
+                conn = await asyncpg.connect(user='user', password='password',
+                                             database='database', host='127.0.0.1')
+                values = await conn.fetch('''SELECT * FROM mytable''')
+                await conn.close()
+        
+            loop = asyncio.get_event_loop()
+            loop.run_until_complete(run())
+        
+        
+        License
+        -------
+        
+        asyncpg is developed and distributed under the Apache 2.0 license.
+        
+Platform: macOS
+Platform: POSIX
+Platform: Windows
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Framework :: AsyncIO
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Programming Language :: Python :: 3 :: Only
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Programming Language :: Python :: 3.7
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Topic :: Database :: Front-Ends
+Provides: asyncpg
+Requires-Python: >=3.5.0
+Provides-Extra: docs
+Provides-Extra: test
+Provides-Extra: dev
diff --git a/asyncpg.egg-info/SOURCES.txt b/asyncpg.egg-info/SOURCES.txt
new file mode 100644 (file)
index 0000000..37d91be
--- /dev/null
@@ -0,0 +1,119 @@
+LICENSE
+MANIFEST.in
+Makefile
+README.rst
+performance.png
+setup.py
+asyncpg/__init__.py
+asyncpg/cluster.py
+asyncpg/compat.py
+asyncpg/connect_utils.py
+asyncpg/connection.py
+asyncpg/connresource.py
+asyncpg/cursor.py
+asyncpg/introspection.py
+asyncpg/pool.py
+asyncpg/prepared_stmt.py
+asyncpg/serverversion.py
+asyncpg/transaction.py
+asyncpg/types.py
+asyncpg/utils.py
+asyncpg.egg-info/PKG-INFO
+asyncpg.egg-info/SOURCES.txt
+asyncpg.egg-info/dependency_links.txt
+asyncpg.egg-info/not-zip-safe
+asyncpg.egg-info/requires.txt
+asyncpg.egg-info/top_level.txt
+asyncpg/_testbase/__init__.py
+asyncpg/_testbase/fuzzer.py
+asyncpg/exceptions/__init__.py
+asyncpg/exceptions/_base.py
+asyncpg/pgproto/__init__.pxd
+asyncpg/pgproto/__init__.py
+asyncpg/pgproto/buffer.pxd
+asyncpg/pgproto/buffer.pyx
+asyncpg/pgproto/consts.pxi
+asyncpg/pgproto/cpythonx.pxd
+asyncpg/pgproto/debug.h
+asyncpg/pgproto/debug.pxd
+asyncpg/pgproto/exceptions.py
+asyncpg/pgproto/frb.pxd
+asyncpg/pgproto/frb.pyx
+asyncpg/pgproto/hton.h
+asyncpg/pgproto/hton.pxd
+asyncpg/pgproto/pgproto.c
+asyncpg/pgproto/pgproto.pxd
+asyncpg/pgproto/pgproto.pyx
+asyncpg/pgproto/types.py
+asyncpg/pgproto/codecs/__init__.pxd
+asyncpg/pgproto/codecs/bits.pyx
+asyncpg/pgproto/codecs/bytea.pyx
+asyncpg/pgproto/codecs/context.pyx
+asyncpg/pgproto/codecs/datetime.pyx
+asyncpg/pgproto/codecs/float.pyx
+asyncpg/pgproto/codecs/geometry.pyx
+asyncpg/pgproto/codecs/hstore.pyx
+asyncpg/pgproto/codecs/int.pyx
+asyncpg/pgproto/codecs/json.pyx
+asyncpg/pgproto/codecs/misc.pyx
+asyncpg/pgproto/codecs/network.pyx
+asyncpg/pgproto/codecs/numeric.pyx
+asyncpg/pgproto/codecs/text.pyx
+asyncpg/pgproto/codecs/tid.pyx
+asyncpg/pgproto/codecs/txid.pyx
+asyncpg/pgproto/codecs/uuid.pyx
+asyncpg/protocol/__init__.py
+asyncpg/protocol/consts.pxi
+asyncpg/protocol/coreproto.pxd
+asyncpg/protocol/coreproto.pyx
+asyncpg/protocol/cpythonx.pxd
+asyncpg/protocol/encodings.pyx
+asyncpg/protocol/pgtypes.pxi
+asyncpg/protocol/prepared_stmt.pxd
+asyncpg/protocol/prepared_stmt.pyx
+asyncpg/protocol/protocol.c
+asyncpg/protocol/protocol.pxd
+asyncpg/protocol/protocol.pyx
+asyncpg/protocol/settings.pxd
+asyncpg/protocol/settings.pyx
+asyncpg/protocol/codecs/__init__.py
+asyncpg/protocol/codecs/array.pyx
+asyncpg/protocol/codecs/base.pxd
+asyncpg/protocol/codecs/base.pyx
+asyncpg/protocol/codecs/pgproto.pyx
+asyncpg/protocol/codecs/range.pyx
+asyncpg/protocol/codecs/record.pyx
+asyncpg/protocol/codecs/textutils.pyx
+asyncpg/protocol/record/__init__.pxd
+asyncpg/protocol/record/recordobj.c
+asyncpg/protocol/record/recordobj.h
+docs/conf.py
+docs/faq.rst
+docs/index.rst
+docs/installation.rst
+docs/usage.rst
+docs/api/index.rst
+tests/__init__.py
+tests/test__environment.py
+tests/test__sourcecode.py
+tests/test_adversity.py
+tests/test_cache_invalidation.py
+tests/test_cancellation.py
+tests/test_codecs.py
+tests/test_connect.py
+tests/test_copy.py
+tests/test_cursor.py
+tests/test_exceptions.py
+tests/test_execute.py
+tests/test_introspection.py
+tests/test_listeners.py
+tests/test_pool.py
+tests/test_prepare.py
+tests/test_record.py
+tests/test_test.py
+tests/test_timeout.py
+tests/test_transaction.py
+tests/test_utils.py
+tests/certs/ca.cert.pem
+tests/certs/server.cert.pem
+tests/certs/server.key.pem
\ No newline at end of file
diff --git a/asyncpg.egg-info/dependency_links.txt b/asyncpg.egg-info/dependency_links.txt
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/asyncpg.egg-info/not-zip-safe b/asyncpg.egg-info/not-zip-safe
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/asyncpg.egg-info/requires.txt b/asyncpg.egg-info/requires.txt
new file mode 100644 (file)
index 0000000..60419c5
--- /dev/null
@@ -0,0 +1,22 @@
+
+[dev]
+Cython==0.29
+pytest>=3.6.0
+Sphinx~=1.7.3
+sphinxcontrib-asyncio~=0.2.0
+sphinx_rtd_theme~=0.2.4
+flake8~=3.5.0
+
+[dev:platform_system != "Windows"]
+uvloop>=0.8.0
+
+[docs]
+Sphinx~=1.7.3
+sphinxcontrib-asyncio~=0.2.0
+sphinx_rtd_theme~=0.2.4
+
+[test]
+flake8~=3.5.0
+
+[test:platform_system != "Windows"]
+uvloop>=0.8.0
diff --git a/asyncpg.egg-info/top_level.txt b/asyncpg.egg-info/top_level.txt
new file mode 100644 (file)
index 0000000..5789edd
--- /dev/null
@@ -0,0 +1 @@
+asyncpg
diff --git a/asyncpg/__init__.py b/asyncpg/__init__.py
new file mode 100644 (file)
index 0000000..4882c8a
--- /dev/null
@@ -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
+
+
+from .connection import connect, Connection  # NOQA
+from .exceptions import *  # NOQA
+from .pool import create_pool  # NOQA
+from .protocol import Record  # NOQA
+from .types import *  # NOQA
+
+
+__all__ = ('connect', 'create_pool', 'Record', 'Connection') + \
+          exceptions.__all__  # NOQA
+
+# The rules of changing __version__:
+#
+#    In a release revision, __version__ must be set to 'x.y.z',
+#    and the release revision tagged with the 'vx.y.z' tag.
+#    For example, asyncpg release 0.15.0 should have
+#    __version__ set to '0.15.0', and tagged with 'v0.15.0'.
+#
+#    In between releases, __version__ must be set to
+#    'x.y+1.0.dev0', so asyncpg revisions between 0.15.0 and
+#    0.16.0 should have __version__ set to '0.16.0.dev0' in
+#    the source.
+#
+#    Source and wheel distributions built from development
+#    snapshots will automatically include the git revision
+#    in __version__, for example: '0.16.0.dev0+ge06ad03'
+
+__version__ = '0.18.2'
diff --git a/asyncpg/_testbase/__init__.py b/asyncpg/_testbase/__init__.py
new file mode 100644 (file)
index 0000000..ebca750
--- /dev/null
@@ -0,0 +1,425 @@
+# 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
+
+
+import asyncio
+import atexit
+import contextlib
+import functools
+import inspect
+import logging
+import os
+import re
+import textwrap
+import time
+import traceback
+import unittest
+
+
+from asyncpg import cluster as pg_cluster
+from asyncpg import connection as pg_connection
+from asyncpg import pool as pg_pool
+
+from . import fuzzer
+
+
+@contextlib.contextmanager
+def silence_asyncio_long_exec_warning():
+    def flt(log_record):
+        msg = log_record.getMessage()
+        return not msg.startswith('Executing ')
+
+    logger = logging.getLogger('asyncio')
+    logger.addFilter(flt)
+    try:
+        yield
+    finally:
+        logger.removeFilter(flt)
+
+
+def with_timeout(timeout):
+    def wrap(func):
+        func.__timeout__ = timeout
+        return func
+
+    return wrap
+
+
+class TestCaseMeta(type(unittest.TestCase)):
+    TEST_TIMEOUT = None
+
+    @staticmethod
+    def _iter_methods(bases, ns):
+        for base in bases:
+            for methname in dir(base):
+                if not methname.startswith('test_'):
+                    continue
+
+                meth = getattr(base, methname)
+                if not inspect.iscoroutinefunction(meth):
+                    continue
+
+                yield methname, meth
+
+        for methname, meth in ns.items():
+            if not methname.startswith('test_'):
+                continue
+
+            if not inspect.iscoroutinefunction(meth):
+                continue
+
+            yield methname, meth
+
+    def __new__(mcls, name, bases, ns):
+        for methname, meth in mcls._iter_methods(bases, ns):
+            @functools.wraps(meth)
+            def wrapper(self, *args, __meth__=meth, **kwargs):
+                coro = __meth__(self, *args, **kwargs)
+                timeout = getattr(__meth__, '__timeout__', mcls.TEST_TIMEOUT)
+                if timeout:
+                    coro = asyncio.wait_for(coro, timeout, loop=self.loop)
+                    try:
+                        self.loop.run_until_complete(coro)
+                    except asyncio.TimeoutError:
+                        raise self.failureException(
+                            'test timed out after {} seconds'.format(
+                                timeout)) from None
+                else:
+                    self.loop.run_until_complete(coro)
+            ns[methname] = wrapper
+
+        return super().__new__(mcls, name, bases, ns)
+
+
+class TestCase(unittest.TestCase, metaclass=TestCaseMeta):
+
+    @classmethod
+    def setUpClass(cls):
+        if os.environ.get('USE_UVLOOP'):
+            import uvloop
+            asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
+
+        loop = asyncio.new_event_loop()
+        asyncio.set_event_loop(None)
+        cls.loop = loop
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.loop.close()
+        asyncio.set_event_loop(None)
+
+    def setUp(self):
+        self.loop.set_exception_handler(self.loop_exception_handler)
+        self.__unhandled_exceptions = []
+
+    def tearDown(self):
+        if self.__unhandled_exceptions:
+            formatted = []
+
+            for i, context in enumerate(self.__unhandled_exceptions):
+                formatted.append(self._format_loop_exception(context, i + 1))
+
+            self.fail(
+                'unexpected exceptions in asynchronous code:\n' +
+                '\n'.join(formatted))
+
+    @contextlib.contextmanager
+    def assertRunUnder(self, delta):
+        st = time.monotonic()
+        try:
+            yield
+        finally:
+            elapsed = time.monotonic() - st
+            if elapsed > delta:
+                raise AssertionError(
+                    'running block took {:0.3f}s which is longer '
+                    'than the expected maximum of {:0.3f}s'.format(
+                        elapsed, delta))
+
+    @contextlib.contextmanager
+    def assertLoopErrorHandlerCalled(self, msg_re: str):
+        contexts = []
+
+        def handler(loop, ctx):
+            contexts.append(ctx)
+
+        old_handler = self.loop.get_exception_handler()
+        self.loop.set_exception_handler(handler)
+        try:
+            yield
+
+            for ctx in contexts:
+                msg = ctx.get('message')
+                if msg and re.search(msg_re, msg):
+                    return
+
+            raise AssertionError(
+                'no message matching {!r} was logged with '
+                'loop.call_exception_handler()'.format(msg_re))
+
+        finally:
+            self.loop.set_exception_handler(old_handler)
+
+    def loop_exception_handler(self, loop, context):
+        self.__unhandled_exceptions.append(context)
+        loop.default_exception_handler(context)
+
+    def _format_loop_exception(self, context, n):
+        message = context.get('message', 'Unhandled exception in event loop')
+        exception = context.get('exception')
+        if exception is not None:
+            exc_info = (type(exception), exception, exception.__traceback__)
+        else:
+            exc_info = None
+
+        lines = []
+        for key in sorted(context):
+            if key in {'message', 'exception'}:
+                continue
+            value = context[key]
+            if key == 'source_traceback':
+                tb = ''.join(traceback.format_list(value))
+                value = 'Object created at (most recent call last):\n'
+                value += tb.rstrip()
+            else:
+                try:
+                    value = repr(value)
+                except Exception as ex:
+                    value = ('Exception in __repr__ {!r}; '
+                             'value type: {!r}'.format(ex, type(value)))
+            lines.append('[{}]: {}\n\n'.format(key, value))
+
+        if exc_info is not None:
+            lines.append('[exception]:\n')
+            formatted_exc = textwrap.indent(
+                ''.join(traceback.format_exception(*exc_info)), '  ')
+            lines.append(formatted_exc)
+
+        details = textwrap.indent(''.join(lines), '    ')
+        return '{:02d}. {}:\n{}\n'.format(n, message, details)
+
+
+_default_cluster = None
+
+
+def _init_cluster(ClusterCls, cluster_kwargs, initdb_options=None):
+    cluster = ClusterCls(**cluster_kwargs)
+    cluster.init(**(initdb_options or {}))
+    cluster.trust_local_connections()
+    atexit.register(_shutdown_cluster, cluster)
+    return cluster
+
+
+def _start_cluster(ClusterCls, cluster_kwargs, server_settings,
+                   initdb_options=None):
+    cluster = _init_cluster(ClusterCls, cluster_kwargs, initdb_options)
+    cluster.start(port='dynamic', server_settings=server_settings)
+    return cluster
+
+
+def _get_initdb_options(initdb_options=None):
+    if not initdb_options:
+        initdb_options = {}
+    else:
+        initdb_options = dict(initdb_options)
+
+    # Make the default superuser name stable.
+    if 'username' not in initdb_options:
+        initdb_options['username'] = 'postgres'
+
+    return initdb_options
+
+
+def _init_default_cluster(initdb_options=None):
+    global _default_cluster
+
+    if _default_cluster is None:
+        pg_host = os.environ.get('PGHOST')
+        if pg_host:
+            # Using existing cluster, assuming it is initialized and running
+            _default_cluster = pg_cluster.RunningCluster()
+        else:
+            _default_cluster = _init_cluster(
+                pg_cluster.TempCluster, cluster_kwargs={},
+                initdb_options=_get_initdb_options(initdb_options))
+
+    return _default_cluster
+
+
+def _shutdown_cluster(cluster):
+    if cluster.get_status() == 'running':
+        cluster.stop()
+    if cluster.get_status() != 'not-initialized':
+        cluster.destroy()
+
+
+def create_pool(dsn=None, *,
+                min_size=10,
+                max_size=10,
+                max_queries=50000,
+                max_inactive_connection_lifetime=60.0,
+                setup=None,
+                init=None,
+                loop=None,
+                pool_class=pg_pool.Pool,
+                connection_class=pg_connection.Connection,
+                **connect_kwargs):
+    return pool_class(
+        dsn,
+        min_size=min_size, max_size=max_size,
+        max_queries=max_queries, loop=loop, setup=setup, init=init,
+        max_inactive_connection_lifetime=max_inactive_connection_lifetime,
+        connection_class=connection_class,
+        **connect_kwargs)
+
+
+class ClusterTestCase(TestCase):
+    @classmethod
+    def get_server_settings(cls):
+        return {
+            'log_connections': 'on'
+        }
+
+    @classmethod
+    def new_cluster(cls, ClusterCls, *, cluster_kwargs={}, initdb_options={}):
+        cluster = _init_cluster(ClusterCls, cluster_kwargs,
+                                _get_initdb_options(initdb_options))
+        cls._clusters.append(cluster)
+        return cluster
+
+    @classmethod
+    def start_cluster(cls, cluster, *, server_settings={}):
+        cluster.start(port='dynamic', server_settings=server_settings)
+
+    @classmethod
+    def setup_cluster(cls):
+        cls.cluster = _init_default_cluster()
+
+        if cls.cluster.get_status() != 'running':
+            cls.cluster.start(
+                port='dynamic', server_settings=cls.get_server_settings())
+
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls._clusters = []
+        cls.setup_cluster()
+
+    @classmethod
+    def tearDownClass(cls):
+        super().tearDownClass()
+        for cluster in cls._clusters:
+            if cluster is not _default_cluster:
+                cluster.stop()
+                cluster.destroy()
+        cls._clusters = []
+
+    @classmethod
+    def get_connection_spec(cls, kwargs={}):
+        conn_spec = cls.cluster.get_connection_spec()
+        conn_spec.update(kwargs)
+        if not os.environ.get('PGHOST'):
+            if 'database' not in conn_spec:
+                conn_spec['database'] = 'postgres'
+            if 'user' not in conn_spec:
+                conn_spec['user'] = 'postgres'
+        return conn_spec
+
+    @classmethod
+    def connect(cls, **kwargs):
+        conn_spec = cls.get_connection_spec(kwargs)
+        return pg_connection.connect(**conn_spec, loop=cls.loop)
+
+    def setUp(self):
+        super().setUp()
+        self._pools = []
+
+    def tearDown(self):
+        super().tearDown()
+        for pool in self._pools:
+            pool.terminate()
+        self._pools = []
+
+    def create_pool(self, pool_class=pg_pool.Pool,
+                    connection_class=pg_connection.Connection, **kwargs):
+        conn_spec = self.get_connection_spec(kwargs)
+        pool = create_pool(loop=self.loop, pool_class=pool_class,
+                           connection_class=connection_class, **conn_spec)
+        self._pools.append(pool)
+        return pool
+
+
+class ProxiedClusterTestCase(ClusterTestCase):
+    @classmethod
+    def get_server_settings(cls):
+        settings = dict(super().get_server_settings())
+        settings['listen_addresses'] = '127.0.0.1'
+        return settings
+
+    @classmethod
+    def get_proxy_settings(cls):
+        return {'fuzzing-mode': None}
+
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        conn_spec = cls.cluster.get_connection_spec()
+        host = conn_spec.get('host')
+        if not host:
+            host = '127.0.0.1'
+        elif host.startswith('/'):
+            host = '127.0.0.1'
+        cls.proxy = fuzzer.TCPFuzzingProxy(
+            backend_host=host,
+            backend_port=conn_spec['port'],
+        )
+        cls.proxy.start()
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.proxy.stop()
+        super().tearDownClass()
+
+    @classmethod
+    def get_connection_spec(cls, kwargs):
+        conn_spec = super().get_connection_spec(kwargs)
+        conn_spec['host'] = cls.proxy.listening_addr
+        conn_spec['port'] = cls.proxy.listening_port
+        return conn_spec
+
+    def tearDown(self):
+        self.proxy.reset()
+        super().tearDown()
+
+
+def with_connection_options(**options):
+    if not options:
+        raise ValueError('no connection options were specified')
+
+    def wrap(func):
+        func.__connect_options__ = options
+        return func
+
+    return wrap
+
+
+class ConnectedTestCase(ClusterTestCase):
+
+    def setUp(self):
+        super().setUp()
+
+        # Extract options set up with `with_connection_options`.
+        test_func = getattr(self, self._testMethodName).__func__
+        opts = getattr(test_func, '__connect_options__', {})
+        self.con = self.loop.run_until_complete(self.connect(**opts))
+        self.server_version = self.con.get_server_version()
+
+    def tearDown(self):
+        try:
+            self.loop.run_until_complete(self.con.close())
+            self.con = None
+        finally:
+            super().tearDown()
diff --git a/asyncpg/_testbase/fuzzer.py b/asyncpg/_testbase/fuzzer.py
new file mode 100644 (file)
index 0000000..649e577
--- /dev/null
@@ -0,0 +1,296 @@
+# 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
+
+
+import asyncio
+import socket
+import threading
+import typing
+
+from asyncpg import cluster
+
+
+class StopServer(Exception):
+    pass
+
+
+class TCPFuzzingProxy:
+    def __init__(self, *, listening_addr: str='127.0.0.1',
+                 listening_port: typing.Optional[int]=None,
+                 backend_host: str, backend_port: int,
+                 settings: typing.Optional[dict]=None) -> None:
+        self.listening_addr = listening_addr
+        self.listening_port = listening_port
+        self.backend_host = backend_host
+        self.backend_port = backend_port
+        self.settings = settings or {}
+        self.loop = None
+        self.connectivity = None
+        self.connectivity_loss = None
+        self.stop_event = None
+        self.connections = {}
+        self.sock = None
+        self.listen_task = None
+
+    async def _wait(self, work):
+        work_task = asyncio.ensure_future(work, loop=self.loop)
+        stop_event_task = asyncio.ensure_future(self.stop_event.wait(),
+                                                loop=self.loop)
+
+        try:
+            await asyncio.wait(
+                [work_task, stop_event_task],
+                return_when=asyncio.FIRST_COMPLETED,
+                loop=self.loop)
+
+            if self.stop_event.is_set():
+                raise StopServer()
+            else:
+                return work_task.result()
+        finally:
+            if not work_task.done():
+                work_task.cancel()
+            if not stop_event_task.done():
+                stop_event_task.cancel()
+
+    def start(self):
+        started = threading.Event()
+        self.thread = threading.Thread(target=self._start, args=(started,))
+        self.thread.start()
+        if not started.wait(timeout=2):
+            raise RuntimeError('fuzzer proxy failed to start')
+
+    def stop(self):
+        self.loop.call_soon_threadsafe(self._stop)
+        self.thread.join()
+
+    def _stop(self):
+        self.stop_event.set()
+
+    def _start(self, started_event):
+        self.loop = asyncio.new_event_loop()
+
+        self.connectivity = asyncio.Event(loop=self.loop)
+        self.connectivity.set()
+        self.connectivity_loss = asyncio.Event(loop=self.loop)
+        self.stop_event = asyncio.Event(loop=self.loop)
+
+        if self.listening_port is None:
+            self.listening_port = cluster.find_available_port()
+
+        self.sock = socket.socket()
+        self.sock.bind((self.listening_addr, self.listening_port))
+        self.sock.listen(50)
+        self.sock.setblocking(False)
+
+        try:
+            self.loop.run_until_complete(self._main(started_event))
+        finally:
+            self.loop.close()
+
+    async def _main(self, started_event):
+        self.listen_task = asyncio.ensure_future(self.listen(), loop=self.loop)
+        # Notify the main thread that we are ready to go.
+        started_event.set()
+        try:
+            await self.listen_task
+        finally:
+            for c in list(self.connections):
+                c.close()
+            await asyncio.sleep(0.01, loop=self.loop)
+            if hasattr(self.loop, 'remove_reader'):
+                self.loop.remove_reader(self.sock.fileno())
+            self.sock.close()
+
+    async def listen(self):
+        while True:
+            try:
+                client_sock, _ = await self._wait(
+                    self.loop.sock_accept(self.sock))
+
+                backend_sock = socket.socket()
+                backend_sock.setblocking(False)
+
+                await self._wait(self.loop.sock_connect(
+                    backend_sock, (self.backend_host, self.backend_port)))
+            except StopServer:
+                break
+
+            conn = Connection(client_sock, backend_sock, self)
+            conn_task = self.loop.create_task(conn.handle())
+            self.connections[conn] = conn_task
+
+    def trigger_connectivity_loss(self):
+        self.loop.call_soon_threadsafe(self._trigger_connectivity_loss)
+
+    def _trigger_connectivity_loss(self):
+        self.connectivity.clear()
+        self.connectivity_loss.set()
+
+    def restore_connectivity(self):
+        self.loop.call_soon_threadsafe(self._restore_connectivity)
+
+    def _restore_connectivity(self):
+        self.connectivity.set()
+        self.connectivity_loss.clear()
+
+    def reset(self):
+        self.restore_connectivity()
+
+    def _close_connection(self, connection):
+        conn_task = self.connections.pop(connection, None)
+        if conn_task is not None:
+            conn_task.cancel()
+
+
+class Connection:
+    def __init__(self, client_sock, backend_sock, proxy):
+        self.client_sock = client_sock
+        self.backend_sock = backend_sock
+        self.proxy = proxy
+        self.loop = proxy.loop
+        self.connectivity = proxy.connectivity
+        self.connectivity_loss = proxy.connectivity_loss
+        self.proxy_to_backend_task = None
+        self.proxy_from_backend_task = None
+        self.is_closed = False
+
+    def close(self):
+        if self.is_closed:
+            return
+
+        self.is_closed = True
+
+        if self.proxy_to_backend_task is not None:
+            self.proxy_to_backend_task.cancel()
+            self.proxy_to_backend_task = None
+
+        if self.proxy_from_backend_task is not None:
+            self.proxy_from_backend_task.cancel()
+            self.proxy_from_backend_task = None
+
+        self.proxy._close_connection(self)
+
+    async def handle(self):
+        self.proxy_to_backend_task = asyncio.ensure_future(
+            self.proxy_to_backend(), loop=self.loop)
+
+        self.proxy_from_backend_task = asyncio.ensure_future(
+            self.proxy_from_backend(), loop=self.loop)
+
+        try:
+            await asyncio.wait(
+                [self.proxy_to_backend_task, self.proxy_from_backend_task],
+                loop=self.loop, return_when=asyncio.FIRST_COMPLETED)
+
+        finally:
+            # Asyncio fails to properly remove the readers and writers
+            # when the task doing recv() or send() is cancelled, so
+            # we must remove the readers and writers manually before
+            # closing the sockets.
+            self.loop.remove_reader(self.client_sock.fileno())
+            self.loop.remove_writer(self.client_sock.fileno())
+            self.loop.remove_reader(self.backend_sock.fileno())
+            self.loop.remove_writer(self.backend_sock.fileno())
+
+            self.client_sock.close()
+            self.backend_sock.close()
+
+    async def _read(self, sock, n):
+        read_task = asyncio.ensure_future(
+            self.loop.sock_recv(sock, n),
+            loop=self.loop)
+        conn_event_task = asyncio.ensure_future(
+            self.connectivity_loss.wait(),
+            loop=self.loop)
+
+        try:
+            await asyncio.wait(
+                [read_task, conn_event_task],
+                return_when=asyncio.FIRST_COMPLETED,
+                loop=self.loop)
+
+            if self.connectivity_loss.is_set():
+                return None
+            else:
+                return read_task.result()
+        finally:
+            if not read_task.done():
+                read_task.cancel()
+            if not conn_event_task.done():
+                conn_event_task.cancel()
+
+    async def _write(self, sock, data):
+        write_task = asyncio.ensure_future(
+            self.loop.sock_sendall(sock, data), loop=self.loop)
+        conn_event_task = asyncio.ensure_future(
+            self.connectivity_loss.wait(), loop=self.loop)
+
+        try:
+            await asyncio.wait(
+                [write_task, conn_event_task],
+                return_when=asyncio.FIRST_COMPLETED,
+                loop=self.loop)
+
+            if self.connectivity_loss.is_set():
+                return None
+            else:
+                return write_task.result()
+        finally:
+            if not write_task.done():
+                write_task.cancel()
+            if not conn_event_task.done():
+                conn_event_task.cancel()
+
+    async def proxy_to_backend(self):
+        buf = None
+
+        try:
+            while True:
+                await self.connectivity.wait()
+                if buf is not None:
+                    data = buf
+                    buf = None
+                else:
+                    data = await self._read(self.client_sock, 4096)
+                if data == b'':
+                    break
+                if self.connectivity_loss.is_set():
+                    if data:
+                        buf = data
+                    continue
+                await self._write(self.backend_sock, data)
+
+        except ConnectionError:
+            pass
+
+        finally:
+            self.loop.call_soon(self.close)
+
+    async def proxy_from_backend(self):
+        buf = None
+
+        try:
+            while True:
+                await self.connectivity.wait()
+                if buf is not None:
+                    data = buf
+                    buf = None
+                else:
+                    data = await self._read(self.backend_sock, 4096)
+                if data == b'':
+                    break
+                if self.connectivity_loss.is_set():
+                    if data:
+                        buf = data
+                    continue
+                await self._write(self.client_sock, data)
+
+        except ConnectionError:
+            pass
+
+        finally:
+            self.loop.call_soon(self.close)
diff --git a/asyncpg/cluster.py b/asyncpg/cluster.py
new file mode 100644 (file)
index 0000000..b6f1765
--- /dev/null
@@ -0,0 +1,681 @@
+# 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
+
+
+import asyncio
+import errno
+import os
+import os.path
+import platform
+import random
+import re
+import shutil
+import socket
+import subprocess
+import sys
+import tempfile
+import textwrap
+import time
+
+import asyncpg
+from asyncpg import serverversion
+
+
+_system = platform.uname().system
+
+if _system == 'Windows':
+    def platform_exe(name):
+        if name.endswith('.exe'):
+            return name
+        return name + '.exe'
+else:
+    def platform_exe(name):
+        return name
+
+
+if _system == 'Linux':
+    def ensure_dead_with_parent():
+        import ctypes
+        import signal
+
+        try:
+            PR_SET_PDEATHSIG = 1
+            libc = ctypes.CDLL(ctypes.util.find_library('c'))
+            libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
+        except Exception as e:
+            print(e)
+else:
+    ensure_dead_with_parent = None
+
+
+def find_available_port(port_range=(49152, 65535), max_tries=1000):
+    low, high = port_range
+
+    port = low
+    try_no = 0
+
+    while try_no < max_tries:
+        try_no += 1
+        port = random.randint(low, high)
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        try:
+            sock.bind(('127.0.0.1', port))
+        except socket.error as e:
+            if e.errno == errno.EADDRINUSE:
+                continue
+        finally:
+            sock.close()
+
+        break
+    else:
+        port = None
+
+    return port
+
+
+class ClusterError(Exception):
+    pass
+
+
+class Cluster:
+    def __init__(self, data_dir, *, pg_config_path=None):
+        self._data_dir = data_dir
+        self._pg_config_path = pg_config_path
+        self._pg_bin_dir = os.environ.get('PGINSTALLATION')
+        self._pg_ctl = None
+        self._daemon_pid = None
+        self._daemon_process = None
+        self._connection_addr = None
+        self._connection_spec_override = None
+
+    def is_managed(self):
+        return True
+
+    def get_data_dir(self):
+        return self._data_dir
+
+    def get_status(self):
+        if self._pg_ctl is None:
+            self._init_env()
+
+        process = subprocess.run(
+            [self._pg_ctl, 'status', '-D', self._data_dir],
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = process.stdout, process.stderr
+
+        if (process.returncode == 4 or not os.path.exists(self._data_dir) or
+                not os.listdir(self._data_dir)):
+            return 'not-initialized'
+        elif process.returncode == 3:
+            return 'stopped'
+        elif process.returncode == 0:
+            r = re.match(r'.*PID\s?:\s+(\d+).*', stdout.decode())
+            if not r:
+                raise ClusterError(
+                    'could not parse pg_ctl status output: {}'.format(
+                        stdout.decode()))
+            self._daemon_pid = int(r.group(1))
+            return self._test_connection(timeout=0)
+        else:
+            raise ClusterError(
+                'pg_ctl status exited with status {:d}: {}'.format(
+                    process.returncode, stderr))
+
+    async def connect(self, loop=None, **kwargs):
+        conn_info = self.get_connection_spec()
+        conn_info.update(kwargs)
+        return await asyncpg.connect(loop=loop, **conn_info)
+
+    def init(self, **settings):
+        """Initialize cluster."""
+        if self.get_status() != 'not-initialized':
+            raise ClusterError(
+                'cluster in {!r} has already been initialized'.format(
+                    self._data_dir))
+
+        if settings:
+            settings_args = ['--{}={}'.format(k, v)
+                             for k, v in settings.items()]
+            extra_args = ['-o'] + [' '.join(settings_args)]
+        else:
+            extra_args = []
+
+        process = subprocess.run(
+            [self._pg_ctl, 'init', '-D', self._data_dir] + extra_args,
+            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+        output = process.stdout
+
+        if process.returncode != 0:
+            raise ClusterError(
+                'pg_ctl init exited with status {:d}:\n{}'.format(
+                    process.returncode, output.decode()))
+
+        return output.decode()
+
+    def start(self, wait=60, *, server_settings={}, **opts):
+        """Start the cluster."""
+        status = self.get_status()
+        if status == 'running':
+            return
+        elif status == 'not-initialized':
+            raise ClusterError(
+                'cluster in {!r} has not been initialized'.format(
+                    self._data_dir))
+
+        port = opts.pop('port', None)
+        if port == 'dynamic':
+            port = find_available_port()
+
+        extra_args = ['--{}={}'.format(k, v) for k, v in opts.items()]
+        extra_args.append('--port={}'.format(port))
+
+        sockdir = server_settings.get('unix_socket_directories')
+        if sockdir is None:
+            sockdir = server_settings.get('unix_socket_directory')
+        if sockdir is None:
+            sockdir = '/tmp'
+
+        ssl_key = server_settings.get('ssl_key_file')
+        if ssl_key:
+            # Make sure server certificate key file has correct permissions.
+            keyfile = os.path.join(self._data_dir, 'srvkey.pem')
+            shutil.copy(ssl_key, keyfile)
+            os.chmod(keyfile, 0o600)
+            server_settings = server_settings.copy()
+            server_settings['ssl_key_file'] = keyfile
+
+        if self._pg_version < (9, 3):
+            sockdir_opt = 'unix_socket_directory'
+        else:
+            sockdir_opt = 'unix_socket_directories'
+
+        server_settings[sockdir_opt] = sockdir
+
+        for k, v in server_settings.items():
+            extra_args.extend(['-c', '{}={}'.format(k, v)])
+
+        if _system == 'Windows':
+            # On Windows we have to use pg_ctl as direct execution
+            # of postgres daemon under an Administrative account
+            # is not permitted and there is no easy way to drop
+            # privileges.
+            if os.getenv('ASYNCPG_DEBUG_SERVER'):
+                stdout = sys.stdout
+            else:
+                stdout = subprocess.DEVNULL
+
+            process = subprocess.run(
+                [self._pg_ctl, 'start', '-D', self._data_dir,
+                 '-o', ' '.join(extra_args)],
+                stdout=stdout, stderr=subprocess.STDOUT)
+
+            if process.returncode != 0:
+                if process.stderr:
+                    stderr = ':\n{}'.format(process.stderr.decode())
+                else:
+                    stderr = ''
+                raise ClusterError(
+                    'pg_ctl start exited with status {:d}{}'.format(
+                        process.returncode, stderr))
+        else:
+            if os.getenv('ASYNCPG_DEBUG_SERVER'):
+                stdout = sys.stdout
+            else:
+                stdout = subprocess.DEVNULL
+
+            self._daemon_process = \
+                subprocess.Popen(
+                    [self._postgres, '-D', self._data_dir, *extra_args],
+                    stdout=stdout, stderr=subprocess.STDOUT,
+                    preexec_fn=ensure_dead_with_parent)
+
+            self._daemon_pid = self._daemon_process.pid
+
+        self._test_connection(timeout=wait)
+
+    def reload(self):
+        """Reload server configuration."""
+        status = self.get_status()
+        if status != 'running':
+            raise ClusterError('cannot reload: cluster is not running')
+
+        process = subprocess.run(
+            [self._pg_ctl, 'reload', '-D', self._data_dir],
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        stderr = process.stderr
+
+        if process.returncode != 0:
+            raise ClusterError(
+                'pg_ctl stop exited with status {:d}: {}'.format(
+                    process.returncode, stderr.decode()))
+
+    def stop(self, wait=60):
+        process = subprocess.run(
+            [self._pg_ctl, 'stop', '-D', self._data_dir, '-t', str(wait),
+             '-m', 'fast'],
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        stderr = process.stderr
+
+        if process.returncode != 0:
+            raise ClusterError(
+                'pg_ctl stop exited with status {:d}: {}'.format(
+                    process.returncode, stderr.decode()))
+
+        if (self._daemon_process is not None and
+                self._daemon_process.returncode is None):
+            self._daemon_process.kill()
+
+    def destroy(self):
+        status = self.get_status()
+        if status == 'stopped' or status == 'not-initialized':
+            shutil.rmtree(self._data_dir)
+        else:
+            raise ClusterError('cannot destroy {} cluster'.format(status))
+
+    def _get_connection_spec(self):
+        if self._connection_addr is None:
+            self._connection_addr = self._connection_addr_from_pidfile()
+
+        if self._connection_addr is not None:
+            if self._connection_spec_override:
+                args = self._connection_addr.copy()
+                args.update(self._connection_spec_override)
+                return args
+            else:
+                return self._connection_addr
+
+    def get_connection_spec(self):
+        status = self.get_status()
+        if status != 'running':
+            raise ClusterError('cluster is not running')
+
+        return self._get_connection_spec()
+
+    def override_connection_spec(self, **kwargs):
+        self._connection_spec_override = kwargs
+
+    def reset_wal(self, *, oid=None, xid=None):
+        status = self.get_status()
+        if status == 'not-initialized':
+            raise ClusterError(
+                'cannot modify WAL status: cluster is not initialized')
+
+        if status == 'running':
+            raise ClusterError(
+                'cannot modify WAL status: cluster is running')
+
+        opts = []
+        if oid is not None:
+            opts.extend(['-o', str(oid)])
+        if xid is not None:
+            opts.extend(['-x', str(xid)])
+        if not opts:
+            return
+
+        opts.append(self._data_dir)
+
+        try:
+            reset_wal = self._find_pg_binary('pg_resetwal')
+        except ClusterError:
+            reset_wal = self._find_pg_binary('pg_resetxlog')
+
+        process = subprocess.run(
+            [reset_wal] + opts,
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        stderr = process.stderr
+
+        if process.returncode != 0:
+            raise ClusterError(
+                'pg_resetwal exited with status {:d}: {}'.format(
+                    process.returncode, stderr.decode()))
+
+    def reset_hba(self):
+        """Remove all records from pg_hba.conf."""
+        status = self.get_status()
+        if status == 'not-initialized':
+            raise ClusterError(
+                'cannot modify HBA records: cluster is not initialized')
+
+        pg_hba = os.path.join(self._data_dir, 'pg_hba.conf')
+
+        try:
+            with open(pg_hba, 'w'):
+                pass
+        except IOError as e:
+            raise ClusterError(
+                'cannot modify HBA records: {}'.format(e)) from e
+
+    def add_hba_entry(self, *, type='host', database, user, address=None,
+                      auth_method, auth_options=None):
+        """Add a record to pg_hba.conf."""
+        status = self.get_status()
+        if status == 'not-initialized':
+            raise ClusterError(
+                'cannot modify HBA records: cluster is not initialized')
+
+        if type not in {'local', 'host', 'hostssl', 'hostnossl'}:
+            raise ValueError('invalid HBA record type: {!r}'.format(type))
+
+        pg_hba = os.path.join(self._data_dir, 'pg_hba.conf')
+
+        record = '{} {} {}'.format(type, database, user)
+
+        if type != 'local':
+            if address is None:
+                raise ValueError(
+                    '{!r} entry requires a valid address'.format(type))
+            else:
+                record += ' {}'.format(address)
+
+        record += ' {}'.format(auth_method)
+
+        if auth_options is not None:
+            record += ' ' + ' '.join(
+                '{}={}'.format(k, v) for k, v in auth_options)
+
+        try:
+            with open(pg_hba, 'a') as f:
+                print(record, file=f)
+        except IOError as e:
+            raise ClusterError(
+                'cannot modify HBA records: {}'.format(e)) from e
+
+    def trust_local_connections(self):
+        self.reset_hba()
+
+        if _system != 'Windows':
+            self.add_hba_entry(type='local', database='all',
+                               user='all', auth_method='trust')
+        self.add_hba_entry(type='host', address='127.0.0.1/32',
+                           database='all', user='all',
+                           auth_method='trust')
+        self.add_hba_entry(type='host', address='::1/128',
+                           database='all', user='all',
+                           auth_method='trust')
+        status = self.get_status()
+        if status == 'running':
+            self.reload()
+
+    def trust_local_replication_by(self, user):
+        if _system != 'Windows':
+            self.add_hba_entry(type='local', database='replication',
+                               user=user, auth_method='trust')
+        self.add_hba_entry(type='host', address='127.0.0.1/32',
+                           database='replication', user=user,
+                           auth_method='trust')
+        self.add_hba_entry(type='host', address='::1/128',
+                           database='replication', user=user,
+                           auth_method='trust')
+        status = self.get_status()
+        if status == 'running':
+            self.reload()
+
+    def _init_env(self):
+        if not self._pg_bin_dir:
+            pg_config = self._find_pg_config(self._pg_config_path)
+            pg_config_data = self._run_pg_config(pg_config)
+
+            self._pg_bin_dir = pg_config_data.get('bindir')
+            if not self._pg_bin_dir:
+                raise ClusterError(
+                    'pg_config output did not provide the BINDIR value')
+
+        self._pg_ctl = self._find_pg_binary('pg_ctl')
+        self._postgres = self._find_pg_binary('postgres')
+        self._pg_version = self._get_pg_version()
+
+    def _connection_addr_from_pidfile(self):
+        pidfile = os.path.join(self._data_dir, 'postmaster.pid')
+
+        try:
+            with open(pidfile, 'rt') as f:
+                piddata = f.read()
+        except FileNotFoundError:
+            return None
+
+        lines = piddata.splitlines()
+
+        if len(lines) < 6:
+            # A complete postgres pidfile is at least 6 lines
+            return None
+
+        pmpid = int(lines[0])
+        if self._daemon_pid and pmpid != self._daemon_pid:
+            # This might be an old pidfile left from previous postgres
+            # daemon run.
+            return None
+
+        portnum = lines[3]
+        sockdir = lines[4]
+        hostaddr = lines[5]
+
+        if sockdir:
+            if sockdir[0] != '/':
+                # Relative sockdir
+                sockdir = os.path.normpath(
+                    os.path.join(self._data_dir, sockdir))
+            host_str = sockdir
+        else:
+            host_str = hostaddr
+
+        if host_str == '*':
+            host_str = 'localhost'
+        elif host_str == '0.0.0.0':
+            host_str = '127.0.0.1'
+        elif host_str == '::':
+            host_str = '::1'
+
+        return {
+            'host': host_str,
+            'port': portnum
+        }
+
+    def _test_connection(self, timeout=60):
+        self._connection_addr = None
+
+        loop = asyncio.new_event_loop()
+
+        try:
+            for i in range(timeout):
+                if self._connection_addr is None:
+                    conn_spec = self._get_connection_spec()
+                    if conn_spec is None:
+                        time.sleep(1)
+                        continue
+
+                try:
+                    con = loop.run_until_complete(
+                        asyncpg.connect(database='postgres',
+                                        user='postgres',
+                                        timeout=5, loop=loop,
+                                        **self._connection_addr))
+                except (OSError, asyncio.TimeoutError,
+                        asyncpg.CannotConnectNowError,
+                        asyncpg.PostgresConnectionError):
+                    time.sleep(1)
+                    continue
+                except asyncpg.PostgresError:
+                    # Any other error other than ServerNotReadyError or
+                    # ConnectionError is interpreted to indicate the server is
+                    # up.
+                    break
+                else:
+                    loop.run_until_complete(con.close())
+                    break
+        finally:
+            loop.close()
+
+        return 'running'
+
+    def _run_pg_config(self, pg_config_path):
+        process = subprocess.run(
+            pg_config_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = process.stdout, process.stderr
+
+        if process.returncode != 0:
+            raise ClusterError('pg_config exited with status {:d}: {}'.format(
+                process.returncode, stderr))
+        else:
+            config = {}
+
+            for line in stdout.splitlines():
+                k, eq, v = line.decode('utf-8').partition('=')
+                if eq:
+                    config[k.strip().lower()] = v.strip()
+
+            return config
+
+    def _find_pg_config(self, pg_config_path):
+        if pg_config_path is None:
+            pg_install = os.environ.get('PGINSTALLATION')
+            if pg_install:
+                pg_config_path = platform_exe(
+                    os.path.join(pg_install, 'pg_config'))
+            else:
+                pathenv = os.environ.get('PATH').split(os.pathsep)
+                for path in pathenv:
+                    pg_config_path = platform_exe(
+                        os.path.join(path, 'pg_config'))
+                    if os.path.exists(pg_config_path):
+                        break
+                else:
+                    pg_config_path = None
+
+        if not pg_config_path:
+            raise ClusterError('could not find pg_config executable')
+
+        if not os.path.isfile(pg_config_path):
+            raise ClusterError('{!r} is not an executable'.format(
+                pg_config_path))
+
+        return pg_config_path
+
+    def _find_pg_binary(self, binary):
+        bpath = platform_exe(os.path.join(self._pg_bin_dir, binary))
+
+        if not os.path.isfile(bpath):
+            raise ClusterError(
+                'could not find {} executable: '.format(binary) +
+                '{!r} does not exist or is not a file'.format(bpath))
+
+        return bpath
+
+    def _get_pg_version(self):
+        process = subprocess.run(
+            [self._postgres, '--version'],
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = process.stdout, process.stderr
+
+        if process.returncode != 0:
+            raise ClusterError(
+                'postgres --version exited with status {:d}: {}'.format(
+                    process.returncode, stderr))
+
+        version_string = stdout.decode('utf-8').strip(' \n')
+        prefix = 'postgres (PostgreSQL) '
+        if not version_string.startswith(prefix):
+            raise ClusterError(
+                'could not determine server version from {!r}'.format(
+                    version_string))
+        version_string = version_string[len(prefix):]
+
+        return serverversion.split_server_version_string(version_string)
+
+
+class TempCluster(Cluster):
+    def __init__(self, *,
+                 data_dir_suffix=None, data_dir_prefix=None,
+                 data_dir_parent=None, pg_config_path=None):
+        self._data_dir = tempfile.mkdtemp(suffix=data_dir_suffix,
+                                          prefix=data_dir_prefix,
+                                          dir=data_dir_parent)
+        super().__init__(self._data_dir, pg_config_path=pg_config_path)
+
+
+class HotStandbyCluster(TempCluster):
+    def __init__(self, *,
+                 master, replication_user,
+                 data_dir_suffix=None, data_dir_prefix=None,
+                 data_dir_parent=None, pg_config_path=None):
+        self._master = master
+        self._repl_user = replication_user
+        super().__init__(
+            data_dir_suffix=data_dir_suffix,
+            data_dir_prefix=data_dir_prefix,
+            data_dir_parent=data_dir_parent,
+            pg_config_path=pg_config_path)
+
+    def _init_env(self):
+        super()._init_env()
+        self._pg_basebackup = self._find_pg_binary('pg_basebackup')
+
+    def init(self, **settings):
+        """Initialize cluster."""
+        if self.get_status() != 'not-initialized':
+            raise ClusterError(
+                'cluster in {!r} has already been initialized'.format(
+                    self._data_dir))
+
+        process = subprocess.run(
+            [self._pg_basebackup, '-h', self._master['host'],
+             '-p', self._master['port'], '-D', self._data_dir,
+             '-U', self._repl_user],
+            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+        output = process.stdout
+
+        if process.returncode != 0:
+            raise ClusterError(
+                'pg_basebackup init exited with status {:d}:\n{}'.format(
+                    process.returncode, output.decode()))
+
+        with open(os.path.join(self._data_dir, 'recovery.conf'), 'w') as f:
+            f.write(textwrap.dedent("""\
+                standby_mode = 'on'
+                primary_conninfo = 'host={host} port={port} user={user}'
+            """.format(
+                host=self._master['host'],
+                port=self._master['port'],
+                user=self._repl_user)))
+
+        return output.decode()
+
+
+class RunningCluster(Cluster):
+    def __init__(self, **kwargs):
+        self.conn_spec = kwargs
+
+    def is_managed(self):
+        return False
+
+    def get_connection_spec(self):
+        return dict(self.conn_spec)
+
+    def get_status(self):
+        return 'running'
+
+    def init(self, **settings):
+        pass
+
+    def start(self, wait=60, **settings):
+        pass
+
+    def stop(self, wait=60):
+        pass
+
+    def destroy(self):
+        pass
+
+    def reset_hba(self):
+        raise ClusterError('cannot modify HBA records of unmanaged cluster')
+
+    def add_hba_entry(self, *, type='host', database, user, address=None,
+                      auth_method, auth_options=None):
+        raise ClusterError('cannot modify HBA records of unmanaged cluster')
diff --git a/asyncpg/compat.py b/asyncpg/compat.py
new file mode 100644 (file)
index 0000000..ff4f27b
--- /dev/null
@@ -0,0 +1,81 @@
+# 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
+
+
+import asyncio
+import functools
+import os
+import pathlib
+import platform
+import sys
+
+
+PY_36 = sys.version_info >= (3, 6)
+PY_37 = sys.version_info >= (3, 7)
+SYSTEM = platform.uname().system
+
+
+if sys.version_info < (3, 5, 2):
+    def aiter_compat(func):
+        @functools.wraps(func)
+        async def wrapper(self):
+            return func(self)
+        return wrapper
+else:
+    def aiter_compat(func):
+        return func
+
+
+if PY_36:
+    fspath = os.fspath
+else:
+    def fspath(path):
+        fsp = getattr(path, '__fspath__', None)
+        if fsp is not None and callable(fsp):
+            path = fsp()
+            if not isinstance(path, (str, bytes)):
+                raise TypeError(
+                    'expected {}() to return str or bytes, not {}'.format(
+                        fsp.__qualname__, type(path).__name__
+                    ))
+            return path
+        elif isinstance(path, (str, bytes)):
+            return path
+        else:
+            raise TypeError(
+                'expected str, bytes or path-like object, not {}'.format(
+                    type(path).__name__
+                )
+            )
+
+
+if SYSTEM == 'Windows':
+    import ctypes.wintypes
+
+    CSIDL_APPDATA = 0x001a
+
+    def get_pg_home_directory() -> pathlib.Path:
+        # We cannot simply use expanduser() as that returns the user's
+        # home directory, whereas Postgres stores its config in
+        # %AppData% on Windows.
+        buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
+        r = ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_APPDATA, 0, 0, buf)
+        if r:
+            return None
+        else:
+            return pathlib.Path(buf.value) / 'postgresql'
+
+else:
+    def get_pg_home_directory() -> pathlib.Path:
+        return pathlib.Path.home()
+
+
+if PY_37:
+    def current_asyncio_task(loop):
+        return asyncio.current_task(loop)
+else:
+    def current_asyncio_task(loop):
+        return asyncio.Task.current_task(loop)
diff --git a/asyncpg/connect_utils.py b/asyncpg/connect_utils.py
new file mode 100644 (file)
index 0000000..3b5b725
--- /dev/null
@@ -0,0 +1,648 @@
+# 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
+
+
+import asyncio
+import collections
+import functools
+import getpass
+import os
+import pathlib
+import platform
+import re
+import socket
+import ssl as ssl_module
+import stat
+import struct
+import time
+import typing
+import urllib.parse
+import warnings
+
+from . import compat
+from . import exceptions
+from . import protocol
+
+
+_ConnectionParameters = collections.namedtuple(
+    'ConnectionParameters',
+    [
+        'user',
+        'password',
+        'database',
+        'ssl',
+        'ssl_is_advisory',
+        'connect_timeout',
+        'server_settings',
+    ])
+
+
+_ClientConfiguration = collections.namedtuple(
+    'ConnectionConfiguration',
+    [
+        'command_timeout',
+        'statement_cache_size',
+        'max_cached_statement_lifetime',
+        'max_cacheable_statement_size',
+    ])
+
+
+_system = platform.uname().system
+
+
+if _system == 'Windows':
+    PGPASSFILE = 'pgpass.conf'
+else:
+    PGPASSFILE = '.pgpass'
+
+
+def _read_password_file(passfile: pathlib.Path) \
+        -> typing.List[typing.Tuple[str, ...]]:
+
+    passtab = []
+
+    try:
+        if not passfile.exists():
+            return []
+
+        if not passfile.is_file():
+            warnings.warn(
+                'password file {!r} is not a plain file'.format(passfile))
+
+            return []
+
+        if _system != 'Windows':
+            if passfile.stat().st_mode & (stat.S_IRWXG | stat.S_IRWXO):
+                warnings.warn(
+                    'password file {!r} has group or world access; '
+                    'permissions should be u=rw (0600) or less'.format(
+                        passfile))
+
+                return []
+
+        with passfile.open('rt') as f:
+            for line in f:
+                line = line.strip()
+                if not line or line.startswith('#'):
+                    # Skip empty lines and comments.
+                    continue
+                # Backslash escapes both itself and the colon,
+                # which is a record separator.
+                line = line.replace(R'\\', '\n')
+                passtab.append(tuple(
+                    p.replace('\n', R'\\')
+                    for p in re.split(r'(?<!\\):', line, maxsplit=4)
+                ))
+    except IOError:
+        pass
+
+    return passtab
+
+
+def _read_password_from_pgpass(
+        *, passfile: typing.Optional[pathlib.Path],
+        hosts: typing.List[str],
+        ports: typing.List[int],
+        database: str,
+        user: str):
+    """Parse the pgpass file and return the matching password.
+
+    :return:
+        Password string, if found, ``None`` otherwise.
+    """
+
+    passtab = _read_password_file(passfile)
+    if not passtab:
+        return None
+
+    for host, port in zip(hosts, ports):
+        if host.startswith('/'):
+            # Unix sockets get normalized into 'localhost'
+            host = 'localhost'
+
+        for phost, pport, pdatabase, puser, ppassword in passtab:
+            if phost != '*' and phost != host:
+                continue
+            if pport != '*' and pport != str(port):
+                continue
+            if pdatabase != '*' and pdatabase != database:
+                continue
+            if puser != '*' and puser != user:
+                continue
+
+            # Found a match.
+            return ppassword
+
+    return None
+
+
+def _validate_port_spec(hosts, port):
+    if isinstance(port, list):
+        # If there is a list of ports, its length must
+        # match that of the host list.
+        if len(port) != len(hosts):
+            raise exceptions.InterfaceError(
+                'could not match {} port numbers to {} hosts'.format(
+                    len(port), len(hosts)))
+    else:
+        port = [port for _ in range(len(hosts))]
+
+    return port
+
+
+def _parse_hostlist(hostlist, port):
+    if ',' in hostlist:
+        # A comma-separated list of host addresses.
+        hostspecs = hostlist.split(',')
+    else:
+        hostspecs = [hostlist]
+
+    hosts = []
+    hostlist_ports = []
+
+    if not port:
+        portspec = os.environ.get('PGPORT')
+        if portspec:
+            if ',' in portspec:
+                default_port = [int(p) for p in portspec.split(',')]
+            else:
+                default_port = int(portspec)
+        else:
+            default_port = 5432
+
+        default_port = _validate_port_spec(hostspecs, default_port)
+
+    else:
+        port = _validate_port_spec(hostspecs, port)
+
+    for i, hostspec in enumerate(hostspecs):
+        addr, _, hostspec_port = hostspec.partition(':')
+        hosts.append(addr)
+
+        if not port:
+            if hostspec_port:
+                hostlist_ports.append(int(hostspec_port))
+            else:
+                hostlist_ports.append(default_port[i])
+
+    if not port:
+        port = hostlist_ports
+
+    return hosts, port
+
+
+def _parse_connect_dsn_and_args(*, dsn, host, port, user,
+                                password, passfile, database, ssl,
+                                connect_timeout, server_settings):
+    # `auth_hosts` is the version of host information for the purposes
+    # of reading the pgpass file.
+    auth_hosts = None
+
+    if dsn:
+        parsed = urllib.parse.urlparse(dsn)
+
+        if parsed.scheme not in {'postgresql', 'postgres'}:
+            raise ValueError(
+                'invalid DSN: scheme is expected to be either '
+                '"postgresql" or "postgres", got {!r}'.format(parsed.scheme))
+
+        if not host and parsed.netloc:
+            if '@' in parsed.netloc:
+                auth, _, hostspec = parsed.netloc.partition('@')
+            else:
+                hostspec = parsed.netloc
+
+            if hostspec:
+                host, port = _parse_hostlist(hostspec, port)
+
+        if parsed.path and database is None:
+            database = parsed.path
+            if database.startswith('/'):
+                database = database[1:]
+
+        if parsed.username and user is None:
+            user = parsed.username
+
+        if parsed.password and password is None:
+            password = parsed.password
+
+        if parsed.query:
+            query = urllib.parse.parse_qs(parsed.query, strict_parsing=True)
+            for key, val in query.items():
+                if isinstance(val, list):
+                    query[key] = val[-1]
+
+            if 'port' in query:
+                val = query.pop('port')
+                if not port and val:
+                    port = [int(p) for p in val.split(',')]
+
+            if 'host' in query:
+                val = query.pop('host')
+                if not host and val:
+                    host, port = _parse_hostlist(val, port)
+
+            if 'dbname' in query:
+                val = query.pop('dbname')
+                if database is None:
+                    database = val
+
+            if 'database' in query:
+                val = query.pop('database')
+                if database is None:
+                    database = val
+
+            if 'user' in query:
+                val = query.pop('user')
+                if user is None:
+                    user = val
+
+            if 'password' in query:
+                val = query.pop('password')
+                if password is None:
+                    password = val
+
+            if 'passfile' in query:
+                val = query.pop('passfile')
+                if passfile is None:
+                    passfile = val
+
+            if 'sslmode' in query:
+                val = query.pop('sslmode')
+                if ssl is None:
+                    ssl = val
+
+            if query:
+                if server_settings is None:
+                    server_settings = query
+                else:
+                    server_settings = {**query, **server_settings}
+
+    if not host:
+        hostspec = os.environ.get('PGHOST')
+        if hostspec:
+            host, port = _parse_hostlist(hostspec, port)
+
+    if not host:
+        auth_hosts = ['localhost']
+
+        if _system == 'Windows':
+            host = ['localhost']
+        else:
+            host = ['/run/postgresql', '/var/run/postgresql',
+                    '/tmp', '/private/tmp', 'localhost']
+
+    if not isinstance(host, list):
+        host = [host]
+
+    if auth_hosts is None:
+        auth_hosts = host
+
+    if not port:
+        portspec = os.environ.get('PGPORT')
+        if portspec:
+            if ',' in portspec:
+                port = [int(p) for p in portspec.split(',')]
+            else:
+                port = int(portspec)
+        else:
+            port = 5432
+
+    elif isinstance(port, (list, tuple)):
+        port = [int(p) for p in port]
+
+    else:
+        port = int(port)
+
+    port = _validate_port_spec(host, port)
+
+    if user is None:
+        user = os.getenv('PGUSER')
+        if not user:
+            user = getpass.getuser()
+
+    if password is None:
+        password = os.getenv('PGPASSWORD')
+
+    if database is None:
+        database = os.getenv('PGDATABASE')
+
+    if database is None:
+        database = user
+
+    if user is None:
+        raise exceptions.InterfaceError(
+            'could not determine user name to connect with')
+
+    if database is None:
+        raise exceptions.InterfaceError(
+            'could not determine database name to connect to')
+
+    if password is None:
+        if passfile is None:
+            passfile = os.getenv('PGPASSFILE')
+
+        if passfile is None:
+            homedir = compat.get_pg_home_directory()
+            if homedir:
+                passfile = homedir / PGPASSFILE
+            else:
+                passfile = None
+        else:
+            passfile = pathlib.Path(passfile)
+
+        if passfile is not None:
+            password = _read_password_from_pgpass(
+                hosts=auth_hosts, ports=port,
+                database=database, user=user,
+                passfile=passfile)
+
+    addrs = []
+    for h, p in zip(host, port):
+        if h.startswith('/'):
+            # UNIX socket name
+            if '.s.PGSQL.' not in h:
+                h = os.path.join(h, '.s.PGSQL.{}'.format(p))
+            addrs.append(h)
+        else:
+            # TCP host/port
+            addrs.append((h, p))
+
+    if not addrs:
+        raise ValueError(
+            'could not determine the database address to connect to')
+
+    if ssl is None:
+        ssl = os.getenv('PGSSLMODE')
+
+    # ssl_is_advisory is only allowed to come from the sslmode parameter.
+    ssl_is_advisory = None
+    if isinstance(ssl, str):
+        SSLMODES = {
+            'disable': 0,
+            'allow': 1,
+            'prefer': 2,
+            'require': 3,
+            'verify-ca': 4,
+            'verify-full': 5,
+        }
+        try:
+            sslmode = SSLMODES[ssl]
+        except KeyError:
+            modes = ', '.join(SSLMODES.keys())
+            raise exceptions.InterfaceError(
+                '`sslmode` parameter must be one of: {}'.format(modes))
+
+        # sslmode 'allow' is currently handled as 'prefer' because we're
+        # missing the "retry with SSL" behavior for 'allow', but do have the
+        # "retry without SSL" behavior for 'prefer'.
+        # Not changing 'allow' to 'prefer' here would be effectively the same
+        # as changing 'allow' to 'disable'.
+        if sslmode == SSLMODES['allow']:
+            sslmode = SSLMODES['prefer']
+
+        # docs at https://www.postgresql.org/docs/10/static/libpq-connect.html
+        # Not implemented: sslcert & sslkey & sslrootcert & sslcrl params.
+        if sslmode <= SSLMODES['allow']:
+            ssl = False
+            ssl_is_advisory = sslmode >= SSLMODES['allow']
+        else:
+            ssl = ssl_module.create_default_context()
+            ssl.check_hostname = sslmode >= SSLMODES['verify-full']
+            ssl.verify_mode = ssl_module.CERT_REQUIRED
+            if sslmode <= SSLMODES['require']:
+                ssl.verify_mode = ssl_module.CERT_NONE
+            ssl_is_advisory = sslmode <= SSLMODES['prefer']
+
+    if ssl:
+        for addr in addrs:
+            if isinstance(addr, str):
+                # UNIX socket
+                raise exceptions.InterfaceError(
+                    '`ssl` parameter can only be enabled for TCP addresses, '
+                    'got a UNIX socket path: {!r}'.format(addr))
+
+    if server_settings is not None and (
+            not isinstance(server_settings, dict) or
+            not all(isinstance(k, str) for k in server_settings) or
+            not all(isinstance(v, str) for v in server_settings.values())):
+        raise ValueError(
+            'server_settings is expected to be None or '
+            'a Dict[str, str]')
+
+    params = _ConnectionParameters(
+        user=user, password=password, database=database, ssl=ssl,
+        ssl_is_advisory=ssl_is_advisory, connect_timeout=connect_timeout,
+        server_settings=server_settings)
+
+    return addrs, params
+
+
+def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
+                             database, timeout, command_timeout,
+                             statement_cache_size,
+                             max_cached_statement_lifetime,
+                             max_cacheable_statement_size,
+                             ssl, server_settings):
+
+    local_vars = locals()
+    for var_name in {'max_cacheable_statement_size',
+                     'max_cached_statement_lifetime',
+                     'statement_cache_size'}:
+        var_val = local_vars[var_name]
+        if var_val is None or isinstance(var_val, bool) or var_val < 0:
+            raise ValueError(
+                '{} is expected to be greater '
+                'or equal to 0, got {!r}'.format(var_name, var_val))
+
+    if command_timeout is not None:
+        try:
+            if isinstance(command_timeout, bool):
+                raise ValueError
+            command_timeout = float(command_timeout)
+            if command_timeout <= 0:
+                raise ValueError
+        except ValueError:
+            raise ValueError(
+                'invalid command_timeout value: '
+                'expected greater than 0 float (got {!r})'.format(
+                    command_timeout)) from None
+
+    addrs, params = _parse_connect_dsn_and_args(
+        dsn=dsn, host=host, port=port, user=user,
+        password=password, passfile=passfile, ssl=ssl,
+        database=database, connect_timeout=timeout,
+        server_settings=server_settings)
+
+    config = _ClientConfiguration(
+        command_timeout=command_timeout,
+        statement_cache_size=statement_cache_size,
+        max_cached_statement_lifetime=max_cached_statement_lifetime,
+        max_cacheable_statement_size=max_cacheable_statement_size,)
+
+    return addrs, params, config
+
+
+async def _connect_addr(*, addr, loop, timeout, params, config,
+                        connection_class):
+    assert loop is not None
+
+    if timeout <= 0:
+        raise asyncio.TimeoutError
+
+    connected = _create_future(loop)
+    proto_factory = lambda: protocol.Protocol(
+        addr, connected, params, loop)
+
+    if isinstance(addr, str):
+        # UNIX socket
+        assert not params.ssl
+        connector = loop.create_unix_connection(proto_factory, addr)
+    elif params.ssl:
+        connector = _create_ssl_connection(
+            proto_factory, *addr, loop=loop, ssl_context=params.ssl,
+            ssl_is_advisory=params.ssl_is_advisory)
+    else:
+        connector = loop.create_connection(proto_factory, *addr)
+
+    before = time.monotonic()
+    tr, pr = await asyncio.wait_for(
+        connector, timeout=timeout, loop=loop)
+    timeout -= time.monotonic() - before
+
+    try:
+        if timeout <= 0:
+            raise asyncio.TimeoutError
+        await asyncio.wait_for(connected, loop=loop, timeout=timeout)
+    except Exception:
+        tr.close()
+        raise
+
+    con = connection_class(pr, tr, loop, addr, config, params)
+    pr.set_connection(con)
+    return con
+
+
+async def _connect(*, loop, timeout, connection_class, **kwargs):
+    if loop is None:
+        loop = asyncio.get_event_loop()
+
+    addrs, params, config = _parse_connect_arguments(timeout=timeout, **kwargs)
+
+    last_error = None
+    addr = None
+    for addr in addrs:
+        before = time.monotonic()
+        try:
+            con = await _connect_addr(
+                addr=addr, loop=loop, timeout=timeout,
+                params=params, config=config,
+                connection_class=connection_class)
+        except (OSError, asyncio.TimeoutError, ConnectionError) as ex:
+            last_error = ex
+        else:
+            return con
+        finally:
+            timeout -= time.monotonic() - before
+
+    raise last_error
+
+
+async def _negotiate_ssl_connection(host, port, conn_factory, *, loop, ssl,
+                                    server_hostname, ssl_is_advisory=False):
+    # Note: ssl_is_advisory only affects behavior when the server does not
+    # accept SSLRequests. If the SSLRequest is accepted but either the SSL
+    # negotiation fails or the PostgreSQL user isn't permitted to use SSL,
+    # there's nothing that would attempt to reconnect with a non-SSL socket.
+    reader, writer = await asyncio.open_connection(host, port, loop=loop)
+
+    tr = writer.transport
+    try:
+        sock = _get_socket(tr)
+        _set_nodelay(sock)
+
+        writer.write(struct.pack('!ll', 8, 80877103))  # SSLRequest message.
+        await writer.drain()
+        resp = await reader.readexactly(1)
+
+        if resp == b'S':
+            conn_factory = functools.partial(
+                conn_factory, ssl=ssl, server_hostname=server_hostname)
+        elif (ssl_is_advisory and
+                ssl.verify_mode == ssl_module.CERT_NONE and
+                resp == b'N'):
+            # ssl_is_advisory will imply that ssl.verify_mode == CERT_NONE,
+            # since the only way to get ssl_is_advisory is from sslmode=prefer
+            # (or sslmode=allow). But be extra sure to disallow insecure
+            # connections when the ssl context asks for real security.
+            pass
+        else:
+            raise ConnectionError(
+                'PostgreSQL server at "{}:{}" rejected SSL upgrade'.format(
+                    host, port))
+
+        sock = sock.dup()  # Must come before tr.close()
+    finally:
+        tr.close()
+
+    try:
+        return await conn_factory(sock=sock)  # Must come after tr.close()
+    except Exception:
+        sock.close()
+        raise
+
+
+async def _create_ssl_connection(protocol_factory, host, port, *,
+                                 loop, ssl_context, ssl_is_advisory=False):
+    return await _negotiate_ssl_connection(
+        host, port,
+        functools.partial(loop.create_connection, protocol_factory),
+        loop=loop,
+        ssl=ssl_context,
+        server_hostname=host,
+        ssl_is_advisory=ssl_is_advisory)
+
+
+async def _open_connection(*, loop, addr, params: _ConnectionParameters):
+    if isinstance(addr, str):
+        r, w = await asyncio.open_unix_connection(addr, loop=loop)
+    else:
+        if params.ssl:
+            r, w = await _negotiate_ssl_connection(
+                *addr,
+                functools.partial(asyncio.open_connection, loop=loop),
+                loop=loop,
+                ssl=params.ssl,
+                server_hostname=addr[0],
+                ssl_is_advisory=params.ssl_is_advisory)
+        else:
+            r, w = await asyncio.open_connection(*addr, loop=loop)
+            _set_nodelay(_get_socket(w.transport))
+
+    return r, w
+
+
+def _get_socket(transport):
+    sock = transport.get_extra_info('socket')
+    if sock is None:
+        # Shouldn't happen with any asyncio-complaint event loop.
+        raise ConnectionError(
+            'could not get the socket for transport {!r}'.format(transport))
+    return sock
+
+
+def _set_nodelay(sock):
+    if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
+        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+
+
+def _create_future(loop):
+    try:
+        create_future = loop.create_future
+    except AttributeError:
+        return asyncio.Future(loop=loop)
+    else:
+        return create_future()
diff --git a/asyncpg/connection.py b/asyncpg/connection.py
new file mode 100644 (file)
index 0000000..d294a86
--- /dev/null
@@ -0,0 +1,1926 @@
+# 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
+
+
+import asyncio
+import asyncpg
+import collections
+import collections.abc
+import itertools
+import struct
+import sys
+import time
+import traceback
+import warnings
+
+from . import compat
+from . import connect_utils
+from . import cursor
+from . import exceptions
+from . import introspection
+from . import prepared_stmt
+from . import protocol
+from . import serverversion
+from . import transaction
+from . import utils
+
+
+class ConnectionMeta(type):
+
+    def __instancecheck__(cls, instance):
+        mro = type(instance).__mro__
+        return Connection in mro or _ConnectionProxy in mro
+
+
+class Connection(metaclass=ConnectionMeta):
+    """A representation of a database session.
+
+    Connections are created by calling :func:`~asyncpg.connection.connect`.
+    """
+
+    __slots__ = ('_protocol', '_transport', '_loop',
+                 '_top_xact', '_aborted',
+                 '_pool_release_ctr', '_stmt_cache', '_stmts_to_close',
+                 '_listeners', '_server_version', '_server_caps',
+                 '_intro_query', '_reset_query', '_proxy',
+                 '_stmt_exclusive_section', '_config', '_params', '_addr',
+                 '_log_listeners', '_cancellations', '_source_traceback',
+                 '__weakref__')
+
+    def __init__(self, protocol, transport, loop,
+                 addr: (str, int) or str,
+                 config: connect_utils._ClientConfiguration,
+                 params: connect_utils._ConnectionParameters):
+        self._protocol = protocol
+        self._transport = transport
+        self._loop = loop
+        self._top_xact = None
+        self._aborted = False
+        # Incremented every time the connection is released back to a pool.
+        # Used to catch invalid references to connection-related resources
+        # post-release (e.g. explicit prepared statements).
+        self._pool_release_ctr = 0
+
+        self._addr = addr
+        self._config = config
+        self._params = params
+
+        self._stmt_cache = _StatementCache(
+            loop=loop,
+            max_size=config.statement_cache_size,
+            on_remove=self._maybe_gc_stmt,
+            max_lifetime=config.max_cached_statement_lifetime)
+
+        self._stmts_to_close = set()
+
+        self._listeners = {}
+        self._log_listeners = set()
+        self._cancellations = set()
+
+        settings = self._protocol.get_settings()
+        ver_string = settings.server_version
+        self._server_version = \
+            serverversion.split_server_version_string(ver_string)
+
+        self._server_caps = _detect_server_capabilities(
+            self._server_version, settings)
+
+        self._intro_query = introspection.INTRO_LOOKUP_TYPES
+
+        self._reset_query = None
+        self._proxy = None
+
+        # Used to serialize operations that might involve anonymous
+        # statements.  Specifically, we want to make the following
+        # operation atomic:
+        #    ("prepare an anonymous statement", "use the statement")
+        #
+        # Used for `con.fetchval()`, `con.fetch()`, `con.fetchrow()`,
+        # `con.execute()`, and `con.executemany()`.
+        self._stmt_exclusive_section = _Atomic()
+
+        if loop.get_debug():
+            self._source_traceback = _extract_stack()
+        else:
+            self._source_traceback = None
+
+    def __del__(self):
+        if not self.is_closed() and self._protocol is not None:
+            if self._source_traceback:
+                msg = "unclosed connection {!r}; created at:\n {}".format(
+                    self, self._source_traceback)
+            else:
+                msg = (
+                    "unclosed connection {!r}; run in asyncio debug "
+                    "mode to show the traceback of connection "
+                    "origin".format(self)
+                )
+
+            warnings.warn(msg, ResourceWarning)
+            if not self._loop.is_closed():
+                self.terminate()
+
+    async def add_listener(self, channel, callback):
+        """Add a listener for Postgres notifications.
+
+        :param str channel: Channel to listen on.
+
+        :param callable callback:
+            A callable receiving the following arguments:
+            **connection**: a Connection the callback is registered with;
+            **pid**: PID of the Postgres server that sent the notification;
+            **channel**: name of the channel the notification was sent to;
+            **payload**: the payload.
+        """
+        self._check_open()
+        if channel not in self._listeners:
+            await self.fetch('LISTEN {}'.format(utils._quote_ident(channel)))
+            self._listeners[channel] = set()
+        self._listeners[channel].add(callback)
+
+    async def remove_listener(self, channel, callback):
+        """Remove a listening callback on the specified channel."""
+        if self.is_closed():
+            return
+        if channel not in self._listeners:
+            return
+        if callback not in self._listeners[channel]:
+            return
+        self._listeners[channel].remove(callback)
+        if not self._listeners[channel]:
+            del self._listeners[channel]
+            await self.fetch('UNLISTEN {}'.format(utils._quote_ident(channel)))
+
+    def add_log_listener(self, callback):
+        """Add a listener for Postgres log messages.
+
+        It will be called when asyncronous NoticeResponse is received
+        from the connection.  Possible message types are: WARNING, NOTICE,
+        DEBUG, INFO, or LOG.
+
+        :param callable callback:
+            A callable receiving the following arguments:
+            **connection**: a Connection the callback is registered with;
+            **message**: the `exceptions.PostgresLogMessage` message.
+
+        .. versionadded:: 0.12.0
+        """
+        if self.is_closed():
+            raise exceptions.InterfaceError('connection is closed')
+        self._log_listeners.add(callback)
+
+    def remove_log_listener(self, callback):
+        """Remove a listening callback for log messages.
+
+        .. versionadded:: 0.12.0
+        """
+        self._log_listeners.discard(callback)
+
+    def get_server_pid(self):
+        """Return the PID of the Postgres server the connection is bound to."""
+        return self._protocol.get_server_pid()
+
+    def get_server_version(self):
+        """Return the version of the connected PostgreSQL server.
+
+        The returned value is a named tuple similar to that in
+        ``sys.version_info``:
+
+        .. code-block:: pycon
+
+            >>> con.get_server_version()
+            ServerVersion(major=9, minor=6, micro=1,
+                          releaselevel='final', serial=0)
+
+        .. versionadded:: 0.8.0
+        """
+        return self._server_version
+
+    def get_settings(self):
+        """Return connection settings.
+
+        :return: :class:`~asyncpg.ConnectionSettings`.
+        """
+        return self._protocol.get_settings()
+
+    def transaction(self, *, isolation='read_committed', readonly=False,
+                    deferrable=False):
+        """Create a :class:`~transaction.Transaction` object.
+
+        Refer to `PostgreSQL documentation`_ on the meaning of transaction
+        parameters.
+
+        :param isolation: Transaction isolation mode, can be one of:
+                          `'serializable'`, `'repeatable_read'`,
+                          `'read_committed'`.
+
+        :param readonly: Specifies whether or not this transaction is
+                         read-only.
+
+        :param deferrable: Specifies whether or not this transaction is
+                           deferrable.
+
+        .. _`PostgreSQL documentation`:
+                https://www.postgresql.org/docs/
+                current/static/sql-set-transaction.html
+        """
+        self._check_open()
+        return transaction.Transaction(self, isolation, readonly, deferrable)
+
+    def is_in_transaction(self):
+        """Return True if Connection is currently inside a transaction.
+
+        :return bool: True if inside transaction, False otherwise.
+
+        .. versionadded:: 0.16.0
+        """
+        return self._protocol.is_in_transaction()
+
+    async def execute(self, query: str, *args, timeout: float=None) -> str:
+        """Execute an SQL command (or commands).
+
+        This method can execute many SQL commands at once, when no arguments
+        are provided.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> await con.execute('''
+            ...     CREATE TABLE mytab (a int);
+            ...     INSERT INTO mytab (a) VALUES (100), (200), (300);
+            ... ''')
+            INSERT 0 3
+
+            >>> await con.execute('''
+            ...     INSERT INTO mytab (a) VALUES ($1), ($2)
+            ... ''', 10, 20)
+            INSERT 0 2
+
+        :param args: Query arguments.
+        :param float timeout: Optional timeout value in seconds.
+        :return str: Status of the last SQL command.
+
+        .. versionchanged:: 0.5.4
+           Made it possible to pass query arguments.
+        """
+        self._check_open()
+
+        if not args:
+            return await self._protocol.query(query, timeout)
+
+        _, status, _ = await self._execute(query, args, 0, timeout, True)
+        return status.decode()
+
+    async def executemany(self, command: str, args, *, timeout: float=None):
+        """Execute an SQL *command* for each sequence of arguments in *args*.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> await con.executemany('''
+            ...     INSERT INTO mytab (a) VALUES ($1, $2, $3);
+            ... ''', [(1, 2, 3), (4, 5, 6)])
+
+        :param command: Command to execute.
+        :param args: An iterable containing sequences of arguments.
+        :param float timeout: Optional timeout value in seconds.
+        :return None: This method discards the results of the operations.
+
+        .. note::
+
+           When inserting a large number of rows,
+           use :meth:`Connection.copy_records_to_table()` instead,
+           it is much more efficient for this purpose.
+
+        .. versionadded:: 0.7.0
+
+        .. versionchanged:: 0.11.0
+           `timeout` became a keyword-only parameter.
+        """
+        self._check_open()
+        return await self._executemany(command, args, timeout)
+
+    async def _get_statement(self, query, timeout, *, named: bool=False,
+                             use_cache: bool=True):
+        if use_cache:
+            statement = self._stmt_cache.get(query)
+            if statement is not None:
+                return statement
+
+            # Only use the cache when:
+            #  * `statement_cache_size` is greater than 0;
+            #  * query size is less than `max_cacheable_statement_size`.
+            use_cache = self._stmt_cache.get_max_size() > 0
+            if (use_cache and
+                    self._config.max_cacheable_statement_size and
+                    len(query) > self._config.max_cacheable_statement_size):
+                use_cache = False
+
+        if use_cache or named:
+            stmt_name = self._get_unique_id('stmt')
+        else:
+            stmt_name = ''
+
+        statement = await self._protocol.prepare(stmt_name, query, timeout)
+        need_reprepare = False
+        types_with_missing_codecs = statement._init_types()
+        tries = 0
+        while types_with_missing_codecs:
+            settings = self._protocol.get_settings()
+
+            # Introspect newly seen types and populate the
+            # codec cache.
+            types, intro_stmt = await self._introspect_types(
+                types_with_missing_codecs, timeout)
+
+            settings.register_data_types(types)
+
+            # The introspection query has used an anonymous statement,
+            # which has blown away the anonymous statement we've prepared
+            # for the query, so we need to re-prepare it.
+            need_reprepare = not intro_stmt.name and not statement.name
+            types_with_missing_codecs = statement._init_types()
+            tries += 1
+            if tries > 5:
+                # In the vast majority of cases there will be only
+                # one iteration.  In rare cases, there might be a race
+                # with reload_schema_state(), which would cause a
+                # second try.  More than five is clearly a bug.
+                raise exceptions.InternalClientError(
+                    'could not resolve query result and/or argument types '
+                    'in {} attempts'.format(tries)
+                )
+
+        # Now that types have been resolved, populate the codec pipeline
+        # for the statement.
+        statement._init_codecs()
+
+        if need_reprepare:
+            await self._protocol.prepare(
+                stmt_name, query, timeout, state=statement)
+
+        if use_cache:
+            self._stmt_cache.put(query, statement)
+
+        # If we've just created a new statement object, check if there
+        # are any statements for GC.
+        if self._stmts_to_close:
+            await self._cleanup_stmts()
+
+        return statement
+
+    async def _introspect_types(self, typeoids, timeout):
+        return await self.__execute(
+            self._intro_query, (list(typeoids),), 0, timeout)
+
+    def cursor(self, query, *args, prefetch=None, timeout=None):
+        """Return a *cursor factory* for the specified query.
+
+        :param args: Query arguments.
+        :param int prefetch: The number of rows the *cursor iterator*
+                             will prefetch (defaults to ``50``.)
+        :param float timeout: Optional timeout in seconds.
+
+        :return: A :class:`~cursor.CursorFactory` object.
+        """
+        self._check_open()
+        return cursor.CursorFactory(self, query, None, args,
+                                    prefetch, timeout)
+
+    async def prepare(self, query, *, timeout=None):
+        """Create a *prepared statement* for the specified query.
+
+        :param str query: Text of the query to create a prepared statement for.
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: A :class:`~prepared_stmt.PreparedStatement` instance.
+        """
+        return await self._prepare(query, timeout=timeout, use_cache=False)
+
+    async def _prepare(self, query, *, timeout=None, use_cache: bool=False):
+        self._check_open()
+        stmt = await self._get_statement(query, timeout, named=True,
+                                         use_cache=use_cache)
+        return prepared_stmt.PreparedStatement(self, query, stmt)
+
+    async def fetch(self, query, *args, timeout=None) -> list:
+        """Run a query and return the results as a list of :class:`Record`.
+
+        :param str query: Query text.
+        :param args: Query arguments.
+        :param float timeout: Optional timeout value in seconds.
+
+        :return list: A list of :class:`Record` instances.
+        """
+        self._check_open()
+        return await self._execute(query, args, 0, timeout)
+
+    async def fetchval(self, query, *args, column=0, timeout=None):
+        """Run a query and return a value in the first row.
+
+        :param str query: Query text.
+        :param args: Query arguments.
+        :param int column: Numeric index within the record of the value to
+                           return (defaults to 0).
+        :param float timeout: Optional timeout value in seconds.
+                            If not specified, defaults to the value of
+                            ``command_timeout`` argument to the ``Connection``
+                            instance constructor.
+
+        :return: The value of the specified column of the first record, or
+                 None if no records were returned by the query.
+        """
+        self._check_open()
+        data = await self._execute(query, args, 1, timeout)
+        if not data:
+            return None
+        return data[0][column]
+
+    async def fetchrow(self, query, *args, timeout=None):
+        """Run a query and return the first row.
+
+        :param str query: Query text
+        :param args: Query arguments
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: The first row as a :class:`Record` instance, or None if
+                 no records were returned by the query.
+        """
+        self._check_open()
+        data = await self._execute(query, args, 1, timeout)
+        if not data:
+            return None
+        return data[0]
+
+    async def copy_from_table(self, table_name, *, output,
+                              columns=None, schema_name=None, timeout=None,
+                              format=None, oids=None, delimiter=None,
+                              null=None, header=None, quote=None,
+                              escape=None, force_quote=None, encoding=None):
+        """Copy table contents to a file or file-like object.
+
+        :param str table_name:
+            The name of the table to copy data from.
+
+        :param output:
+            A :term:`path-like object <python:path-like object>`,
+            or a :term:`file-like object <python:file-like object>`, or
+            a :term:`coroutine function <python:coroutine function>`
+            that takes a ``bytes`` instance as a sole argument.
+
+        :param list columns:
+            An optional list of column names to copy.
+
+        :param str schema_name:
+            An optional schema name to qualify the table.
+
+        :param float timeout:
+            Optional timeout value in seconds.
+
+        The remaining keyword arguments are ``COPY`` statement options,
+        see `COPY statement documentation`_ for details.
+
+        :return: The status string of the COPY command.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> import asyncpg
+            >>> import asyncio
+            >>> async def run():
+            ...     con = await asyncpg.connect(user='postgres')
+            ...     result = await con.copy_from_table(
+            ...         'mytable', columns=('foo', 'bar'),
+            ...         output='file.csv', format='csv')
+            ...     print(result)
+            ...
+            >>> asyncio.get_event_loop().run_until_complete(run())
+            'COPY 100'
+
+        .. _`COPY statement documentation`:
+            https://www.postgresql.org/docs/current/static/sql-copy.html
+
+        .. versionadded:: 0.11.0
+        """
+        tabname = utils._quote_ident(table_name)
+        if schema_name:
+            tabname = utils._quote_ident(schema_name) + '.' + tabname
+
+        if columns:
+            cols = '({})'.format(
+                ', '.join(utils._quote_ident(c) for c in columns))
+        else:
+            cols = ''
+
+        opts = self._format_copy_opts(
+            format=format, oids=oids, delimiter=delimiter,
+            null=null, header=header, quote=quote, escape=escape,
+            force_quote=force_quote, encoding=encoding
+        )
+
+        copy_stmt = 'COPY {tab}{cols} TO STDOUT {opts}'.format(
+            tab=tabname, cols=cols, opts=opts)
+
+        return await self._copy_out(copy_stmt, output, timeout)
+
+    async def copy_from_query(self, query, *args, output,
+                              timeout=None, format=None, oids=None,
+                              delimiter=None, null=None, header=None,
+                              quote=None, escape=None, force_quote=None,
+                              encoding=None):
+        """Copy the results of a query to a file or file-like object.
+
+        :param str query:
+            The query to copy the results of.
+
+        :param \*args:
+            Query arguments.
+
+        :param output:
+            A :term:`path-like object <python:path-like object>`,
+            or a :term:`file-like object <python:file-like object>`, or
+            a :term:`coroutine function <python:coroutine function>`
+            that takes a ``bytes`` instance as a sole argument.
+
+        :param float timeout:
+            Optional timeout value in seconds.
+
+        The remaining keyword arguments are ``COPY`` statement options,
+        see `COPY statement documentation`_ for details.
+
+        :return: The status string of the COPY command.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> import asyncpg
+            >>> import asyncio
+            >>> async def run():
+            ...     con = await asyncpg.connect(user='postgres')
+            ...     result = await con.copy_from_query(
+            ...         'SELECT foo, bar FROM mytable WHERE foo > $1', 10,
+            ...         output='file.csv', format='csv')
+            ...     print(result)
+            ...
+            >>> asyncio.get_event_loop().run_until_complete(run())
+            'COPY 10'
+
+        .. _`COPY statement documentation`:
+            https://www.postgresql.org/docs/current/static/sql-copy.html
+
+        .. versionadded:: 0.11.0
+        """
+        opts = self._format_copy_opts(
+            format=format, oids=oids, delimiter=delimiter,
+            null=null, header=header, quote=quote, escape=escape,
+            force_quote=force_quote, encoding=encoding
+        )
+
+        if args:
+            query = await utils._mogrify(self, query, args)
+
+        copy_stmt = 'COPY ({query}) TO STDOUT {opts}'.format(
+            query=query, opts=opts)
+
+        return await self._copy_out(copy_stmt, output, timeout)
+
+    async def copy_to_table(self, table_name, *, source,
+                            columns=None, schema_name=None, timeout=None,
+                            format=None, oids=None, freeze=None,
+                            delimiter=None, null=None, header=None,
+                            quote=None, escape=None, force_quote=None,
+                            force_not_null=None, force_null=None,
+                            encoding=None):
+        """Copy data to the specified table.
+
+        :param str table_name:
+            The name of the table to copy data to.
+
+        :param source:
+            A :term:`path-like object <python:path-like object>`,
+            or a :term:`file-like object <python:file-like object>`, or
+            an :term:`asynchronous iterable <python:asynchronous iterable>`
+            that returns ``bytes``, or an object supporting the
+            :ref:`buffer protocol <python:bufferobjects>`.
+
+        :param list columns:
+            An optional list of column names to copy.
+
+        :param str schema_name:
+            An optional schema name to qualify the table.
+
+        :param float timeout:
+            Optional timeout value in seconds.
+
+        The remaining keyword arguments are ``COPY`` statement options,
+        see `COPY statement documentation`_ for details.
+
+        :return: The status string of the COPY command.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> import asyncpg
+            >>> import asyncio
+            >>> async def run():
+            ...     con = await asyncpg.connect(user='postgres')
+            ...     result = await con.copy_to_table(
+            ...         'mytable', source='datafile.tbl')
+            ...     print(result)
+            ...
+            >>> asyncio.get_event_loop().run_until_complete(run())
+            'COPY 140000'
+
+        .. _`COPY statement documentation`:
+            https://www.postgresql.org/docs/current/static/sql-copy.html
+
+        .. versionadded:: 0.11.0
+        """
+        tabname = utils._quote_ident(table_name)
+        if schema_name:
+            tabname = utils._quote_ident(schema_name) + '.' + tabname
+
+        if columns:
+            cols = '({})'.format(
+                ', '.join(utils._quote_ident(c) for c in columns))
+        else:
+            cols = ''
+
+        opts = self._format_copy_opts(
+            format=format, oids=oids, freeze=freeze, delimiter=delimiter,
+            null=null, header=header, quote=quote, escape=escape,
+            force_not_null=force_not_null, force_null=force_null,
+            encoding=encoding
+        )
+
+        copy_stmt = 'COPY {tab}{cols} FROM STDIN {opts}'.format(
+            tab=tabname, cols=cols, opts=opts)
+
+        return await self._copy_in(copy_stmt, source, timeout)
+
+    async def copy_records_to_table(self, table_name, *, records,
+                                    columns=None, schema_name=None,
+                                    timeout=None):
+        """Copy a list of records to the specified table using binary COPY.
+
+        :param str table_name:
+            The name of the table to copy data to.
+
+        :param records:
+            An iterable returning row tuples to copy into the table.
+
+        :param list columns:
+            An optional list of column names to copy.
+
+        :param str schema_name:
+            An optional schema name to qualify the table.
+
+        :param float timeout:
+            Optional timeout value in seconds.
+
+        :return: The status string of the COPY command.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> import asyncpg
+            >>> import asyncio
+            >>> async def run():
+            ...     con = await asyncpg.connect(user='postgres')
+            ...     result = await con.copy_records_to_table(
+            ...         'mytable', records=[
+            ...             (1, 'foo', 'bar'),
+            ...             (2, 'ham', 'spam')])
+            ...     print(result)
+            ...
+            >>> asyncio.get_event_loop().run_until_complete(run())
+            'COPY 2'
+
+        .. versionadded:: 0.11.0
+        """
+        tabname = utils._quote_ident(table_name)
+        if schema_name:
+            tabname = utils._quote_ident(schema_name) + '.' + tabname
+
+        if columns:
+            col_list = ', '.join(utils._quote_ident(c) for c in columns)
+            cols = '({})'.format(col_list)
+        else:
+            col_list = '*'
+            cols = ''
+
+        intro_query = 'SELECT {cols} FROM {tab} LIMIT 1'.format(
+            tab=tabname, cols=col_list)
+
+        intro_ps = await self._prepare(intro_query, use_cache=True)
+
+        opts = '(FORMAT binary)'
+
+        copy_stmt = 'COPY {tab}{cols} FROM STDIN {opts}'.format(
+            tab=tabname, cols=cols, opts=opts)
+
+        return await self._copy_in_records(
+            copy_stmt, records, intro_ps._state, timeout)
+
+    def _format_copy_opts(self, *, format=None, oids=None, freeze=None,
+                          delimiter=None, null=None, header=None, quote=None,
+                          escape=None, force_quote=None, force_not_null=None,
+                          force_null=None, encoding=None):
+        kwargs = dict(locals())
+        kwargs.pop('self')
+        opts = []
+
+        if force_quote is not None and isinstance(force_quote, bool):
+            kwargs.pop('force_quote')
+            if force_quote:
+                opts.append('FORCE_QUOTE *')
+
+        for k, v in kwargs.items():
+            if v is not None:
+                if k in ('force_not_null', 'force_null', 'force_quote'):
+                    v = '(' + ', '.join(utils._quote_ident(c) for c in v) + ')'
+                elif k in ('oids', 'freeze', 'header'):
+                    v = str(v)
+                else:
+                    v = utils._quote_literal(v)
+
+                opts.append('{} {}'.format(k.upper(), v))
+
+        if opts:
+            return '(' + ', '.join(opts) + ')'
+        else:
+            return ''
+
+    async def _copy_out(self, copy_stmt, output, timeout):
+        try:
+            path = compat.fspath(output)
+        except TypeError:
+            # output is not a path-like object
+            path = None
+
+        writer = None
+        opened_by_us = False
+        run_in_executor = self._loop.run_in_executor
+
+        if path is not None:
+            # a path
+            f = await run_in_executor(None, open, path, 'wb')
+            opened_by_us = True
+        elif hasattr(output, 'write'):
+            # file-like
+            f = output
+        elif callable(output):
+            # assuming calling output returns an awaitable.
+            writer = output
+        else:
+            raise TypeError(
+                'output is expected to be a file-like object, '
+                'a path-like object or a coroutine function, '
+                'not {}'.format(type(output).__name__)
+            )
+
+        if writer is None:
+            async def _writer(data):
+                await run_in_executor(None, f.write, data)
+            writer = _writer
+
+        try:
+            return await self._protocol.copy_out(copy_stmt, writer, timeout)
+        finally:
+            if opened_by_us:
+                f.close()
+
+    async def _copy_in(self, copy_stmt, source, timeout):
+        try:
+            path = compat.fspath(source)
+        except TypeError:
+            # source is not a path-like object
+            path = None
+
+        f = None
+        reader = None
+        data = None
+        opened_by_us = False
+        run_in_executor = self._loop.run_in_executor
+
+        if path is not None:
+            # a path
+            f = await run_in_executor(None, open, path, 'wb')
+            opened_by_us = True
+        elif hasattr(source, 'read'):
+            # file-like
+            f = source
+        elif isinstance(source, collections.abc.AsyncIterable):
+            # assuming calling output returns an awaitable.
+            reader = source
+        else:
+            # assuming source is an instance supporting the buffer protocol.
+            data = source
+
+        if f is not None:
+            # Copying from a file-like object.
+            class _Reader:
+                @compat.aiter_compat
+                def __aiter__(self):
+                    return self
+
+                async def __anext__(self):
+                    data = await run_in_executor(None, f.read, 524288)
+                    if len(data) == 0:
+                        raise StopAsyncIteration
+                    else:
+                        return data
+
+            reader = _Reader()
+
+        try:
+            return await self._protocol.copy_in(
+                copy_stmt, reader, data, None, None, timeout)
+        finally:
+            if opened_by_us:
+                await run_in_executor(None, f.close)
+
+    async def _copy_in_records(self, copy_stmt, records, intro_stmt, timeout):
+        return await self._protocol.copy_in(
+            copy_stmt, None, None, records, intro_stmt, timeout)
+
+    async def set_type_codec(self, typename, *,
+                             schema='public', encoder, decoder,
+                             format='text'):
+        """Set an encoder/decoder pair for the specified data type.
+
+        :param typename:
+            Name of the data type the codec is for.
+
+        :param schema:
+            Schema name of the data type the codec is for
+            (defaults to ``'public'``)
+
+        :param format:
+            The type of the argument received by the *decoder* callback,
+            and the type of the *encoder* callback return value.
+
+            If *format* is ``'text'`` (the default), the exchange datum is a
+            ``str`` instance containing valid text representation of the
+            data type.
+
+            If *format* is ``'binary'``, the exchange datum is a ``bytes``
+            instance containing valid _binary_ representation of the
+            data type.
+
+            If *format* is ``'tuple'``, the exchange datum is a type-specific
+            ``tuple`` of values.  The table below lists supported data
+            types and their format for this mode.
+
+            +-----------------+---------------------------------------------+
+            |  Type           |                Tuple layout                 |
+            +=================+=============================================+
+            | ``interval``    | (``months``, ``days``, ``microseconds``)    |
+            +-----------------+---------------------------------------------+
+            | ``date``        | (``date ordinal relative to Jan 1 2000``,)  |
+            |                 | ``-2^31`` for negative infinity timestamp   |
+            |                 | ``2^31-1`` for positive infinity timestamp. |
+            +-----------------+---------------------------------------------+
+            | ``timestamp``   | (``microseconds relative to Jan 1 2000``,)  |
+            |                 | ``-2^63`` for negative infinity timestamp   |
+            |                 | ``2^63-1`` for positive infinity timestamp. |
+            +-----------------+---------------------------------------------+
+            | ``timestamp     | (``microseconds relative to Jan 1 2000      |
+            | with time zone``| UTC``,)                                     |
+            |                 | ``-2^63`` for negative infinity timestamp   |
+            |                 | ``2^63-1`` for positive infinity timestamp. |
+            +-----------------+---------------------------------------------+
+            | ``time``        | (``microseconds``,)                         |
+            +-----------------+---------------------------------------------+
+            | ``time with     | (``microseconds``,                          |
+            | time zone``     | ``time zone offset in seconds``)            |
+            +-----------------+---------------------------------------------+
+
+        :param encoder:
+            Callable accepting a Python object as a single argument and
+            returning a value encoded according to *format*.
+
+        :param decoder:
+            Callable accepting a single argument encoded according to *format*
+            and returning a decoded Python object.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> import asyncpg
+            >>> import asyncio
+            >>> import datetime
+            >>> from dateutil.relativedelta import relativedelta
+            >>> async def run():
+            ...     con = await asyncpg.connect(user='postgres')
+            ...     def encoder(delta):
+            ...         ndelta = delta.normalized()
+            ...         return (ndelta.years * 12 + ndelta.months,
+            ...                 ndelta.days,
+            ...                 ((ndelta.hours * 3600 +
+            ...                    ndelta.minutes * 60 +
+            ...                    ndelta.seconds) * 1000000 +
+            ...                  ndelta.microseconds))
+            ...     def decoder(tup):
+            ...         return relativedelta(months=tup[0], days=tup[1],
+            ...                              microseconds=tup[2])
+            ...     await con.set_type_codec(
+            ...         'interval', schema='pg_catalog', encoder=encoder,
+            ...         decoder=decoder, format='tuple')
+            ...     result = await con.fetchval(
+            ...         "SELECT '2 years 3 mons 1 day'::interval")
+            ...     print(result)
+            ...     print(datetime.datetime(2002, 1, 1) + result)
+            ...
+            >>> asyncio.get_event_loop().run_until_complete(run())
+            relativedelta(years=+2, months=+3, days=+1)
+            2004-04-02 00:00:00
+
+        .. versionadded:: 0.12.0
+            Added the ``format`` keyword argument and support for 'tuple'
+            format.
+
+        .. versionchanged:: 0.12.0
+            The ``binary`` keyword argument is deprecated in favor of
+            ``format``.
+
+        .. versionchanged:: 0.13.0
+            The ``binary`` keyword argument was removed in favor of
+            ``format``.
+        """
+        self._check_open()
+
+        typeinfo = await self.fetchrow(
+            introspection.TYPE_BY_NAME, typename, schema)
+        if not typeinfo:
+            raise ValueError('unknown type: {}.{}'.format(schema, typename))
+
+        if not introspection.is_scalar_type(typeinfo):
+            raise ValueError(
+                'cannot use custom codec on non-scalar type {}.{}'.format(
+                    schema, typename))
+
+        oid = typeinfo['oid']
+        self._protocol.get_settings().add_python_codec(
+            oid, typename, schema, 'scalar',
+            encoder, decoder, format)
+
+        # Statement cache is no longer valid due to codec changes.
+        self._drop_local_statement_cache()
+
+    async def reset_type_codec(self, typename, *, schema='public'):
+        """Reset *typename* codec to the default implementation.
+
+        :param typename:
+            Name of the data type the codec is for.
+
+        :param schema:
+            Schema name of the data type the codec is for
+            (defaults to ``'public'``)
+
+        .. versionadded:: 0.12.0
+        """
+
+        typeinfo = await self.fetchrow(
+            introspection.TYPE_BY_NAME, typename, schema)
+        if not typeinfo:
+            raise ValueError('unknown type: {}.{}'.format(schema, typename))
+
+        oid = typeinfo['oid']
+
+        self._protocol.get_settings().remove_python_codec(
+            oid, typename, schema)
+
+        # Statement cache is no longer valid due to codec changes.
+        self._drop_local_statement_cache()
+
+    async def set_builtin_type_codec(self, typename, *,
+                                     schema='public', codec_name,
+                                     format=None):
+        """Set a builtin codec for the specified scalar data type.
+
+        This method has two uses.  The first is to register a builtin
+        codec for an extension type without a stable OID, such as 'hstore'.
+        The second use is to declare that an extension type or a
+        user-defined type is wire-compatible with a certain builtin
+        data type and should be exchanged as such.
+
+        :param typename:
+            Name of the data type the codec is for.
+
+        :param schema:
+            Schema name of the data type the codec is for
+            (defaults to ``'public'``).
+
+        :param codec_name:
+            The name of the builtin codec to use for the type.
+            This should be either the name of a known core type
+            (such as ``"int"``), or the name of a supported extension
+            type.  Currently, the only supported extension type is
+            ``"pg_contrib.hstore"``.
+
+        :param format:
+            If *format* is ``None`` (the default), all formats supported
+            by the target codec are declared to be supported for *typename*.
+            If *format* is ``'text'`` or ``'binary'``, then only the
+            specified format is declared to be supported for *typename*.
+
+        .. versionchanged:: 0.18.0
+            The *codec_name* argument can be the name of any known
+            core data type.  Added the *format* keyword argument.
+        """
+        self._check_open()
+
+        typeinfo = await self.fetchrow(
+            introspection.TYPE_BY_NAME, typename, schema)
+        if not typeinfo:
+            raise exceptions.InterfaceError(
+                'unknown type: {}.{}'.format(schema, typename))
+
+        if not introspection.is_scalar_type(typeinfo):
+            raise exceptions.InterfaceError(
+                'cannot alias non-scalar type {}.{}'.format(
+                    schema, typename))
+
+        oid = typeinfo['oid']
+
+        self._protocol.get_settings().set_builtin_type_codec(
+            oid, typename, schema, 'scalar', codec_name, format)
+
+        # Statement cache is no longer valid due to codec changes.
+        self._drop_local_statement_cache()
+
+    def is_closed(self):
+        """Return ``True`` if the connection is closed, ``False`` otherwise.
+
+        :return bool: ``True`` if the connection is closed, ``False``
+                      otherwise.
+        """
+        return self._aborted or not self._protocol.is_connected()
+
+    async def close(self, *, timeout=None):
+        """Close the connection gracefully.
+
+        :param float timeout:
+            Optional timeout value in seconds.
+
+        .. versionchanged:: 0.14.0
+           Added the *timeout* parameter.
+        """
+        try:
+            if not self.is_closed():
+                await self._protocol.close(timeout)
+        except Exception:
+            # If we fail to close gracefully, abort the connection.
+            self._abort()
+            raise
+        finally:
+            self._cleanup()
+
+    def terminate(self):
+        """Terminate the connection without waiting for pending data."""
+        if not self.is_closed():
+            self._abort()
+        self._cleanup()
+
+    async def reset(self, *, timeout=None):
+        self._check_open()
+        self._listeners.clear()
+        self._log_listeners.clear()
+        reset_query = self._get_reset_query()
+
+        if self._protocol.is_in_transaction() or self._top_xact is not None:
+            if self._top_xact is None or not self._top_xact._managed:
+                # Managed transactions are guaranteed to __aexit__
+                # correctly.
+                self._loop.call_exception_handler({
+                    'message': 'Resetting connection with an '
+                               'active transaction {!r}'.format(self)
+                })
+
+            self._top_xact = None
+            reset_query = 'ROLLBACK;\n' + reset_query
+
+        if reset_query:
+            await self.execute(reset_query, timeout=timeout)
+
+    def _abort(self):
+        # Put the connection into the aborted state.
+        self._aborted = True
+        self._protocol.abort()
+        self._protocol = None
+
+    def _cleanup(self):
+        # Free the resources associated with this connection.
+        # This must be called when a connection is terminated.
+
+        if self._proxy is not None:
+            # Connection is a member of a pool, so let the pool
+            # know that this connection is dead.
+            self._proxy._holder._release_on_close()
+
+        self._mark_stmts_as_closed()
+        self._listeners.clear()
+        self._log_listeners.clear()
+        self._clean_tasks()
+
+    def _clean_tasks(self):
+        # Wrap-up any remaining tasks associated with this connection.
+        if self._cancellations:
+            for fut in self._cancellations:
+                if not fut.done():
+                    fut.cancel()
+            self._cancellations.clear()
+
+    def _check_open(self):
+        if self.is_closed():
+            raise exceptions.InterfaceError('connection is closed')
+
+    def _get_unique_id(self, prefix):
+        global _uid
+        _uid += 1
+        return '__asyncpg_{}_{:x}__'.format(prefix, _uid)
+
+    def _mark_stmts_as_closed(self):
+        for stmt in self._stmt_cache.iter_statements():
+            stmt.mark_closed()
+
+        for stmt in self._stmts_to_close:
+            stmt.mark_closed()
+
+        self._stmt_cache.clear()
+        self._stmts_to_close.clear()
+
+    def _maybe_gc_stmt(self, stmt):
+        if stmt.refs == 0 and not self._stmt_cache.has(stmt.query):
+            # If low-level `stmt` isn't referenced from any high-level
+            # `PreparedStatement` object and is not in the `_stmt_cache`:
+            #
+            #  * mark it as closed, which will make it non-usable
+            #    for any `PreparedStatement` or for methods like
+            #    `Connection.fetch()`.
+            #
+            # * schedule it to be formally closed on the server.
+            stmt.mark_closed()
+            self._stmts_to_close.add(stmt)
+
+    async def _cleanup_stmts(self):
+        # Called whenever we create a new prepared statement in
+        # `Connection._get_statement()` and `_stmts_to_close` is
+        # not empty.
+        to_close = self._stmts_to_close
+        self._stmts_to_close = set()
+        for stmt in to_close:
+            # It is imperative that statements are cleaned properly,
+            # so we ignore the timeout.
+            await self._protocol.close_statement(stmt, protocol.NO_TIMEOUT)
+
+    async def _cancel(self, waiter):
+        r = w = None
+
+        try:
+            # Open new connection to the server
+            r, w = await connect_utils._open_connection(
+                loop=self._loop, addr=self._addr, params=self._params)
+
+            # Pack CancelRequest message
+            msg = struct.pack('!llll', 16, 80877102,
+                              self._protocol.backend_pid,
+                              self._protocol.backend_secret)
+
+            w.write(msg)
+            await r.read()  # Wait until EOF
+        except ConnectionResetError as ex:
+            # On some systems Postgres will reset the connection
+            # after processing the cancellation command.
+            if r is None and not waiter.done():
+                waiter.set_exception(ex)
+        except asyncio.CancelledError:
+            # There are two scenarios in which the cancellation
+            # itself will be cancelled: 1) the connection is being closed,
+            # 2) the event loop is being shut down.
+            # In either case we do not care about the propagation of
+            # the CancelledError, and don't want the loop to warn about
+            # an unretrieved exception.
+            pass
+        except Exception as ex:
+            if not waiter.done():
+                waiter.set_exception(ex)
+        finally:
+            self._cancellations.discard(
+                compat.current_asyncio_task(self._loop))
+            if not waiter.done():
+                waiter.set_result(None)
+            if w is not None:
+                w.close()
+
+    def _cancel_current_command(self, waiter):
+        self._cancellations.add(self._loop.create_task(self._cancel(waiter)))
+
+    def _process_log_message(self, fields, last_query):
+        if not self._log_listeners:
+            return
+
+        message = exceptions.PostgresLogMessage.new(fields, query=last_query)
+
+        con_ref = self._unwrap()
+        for cb in self._log_listeners:
+            self._loop.call_soon(
+                self._call_log_listener, cb, con_ref, message)
+
+    def _call_log_listener(self, cb, con_ref, message):
+        try:
+            cb(con_ref, message)
+        except Exception as ex:
+            self._loop.call_exception_handler({
+                'message': 'Unhandled exception in asyncpg log message '
+                           'listener callback {!r}'.format(cb),
+                'exception': ex
+            })
+
+    def _process_notification(self, pid, channel, payload):
+        if channel not in self._listeners:
+            return
+
+        con_ref = self._unwrap()
+        for cb in self._listeners[channel]:
+            self._loop.call_soon(
+                self._call_listener, cb, con_ref, pid, channel, payload)
+
+    def _call_listener(self, cb, con_ref, pid, channel, payload):
+        try:
+            cb(con_ref, pid, channel, payload)
+        except Exception as ex:
+            self._loop.call_exception_handler({
+                'message': 'Unhandled exception in asyncpg notification '
+                           'listener callback {!r}'.format(cb),
+                'exception': ex
+            })
+
+    def _unwrap(self):
+        if self._proxy is None:
+            con_ref = self
+        else:
+            # `_proxy` is not None when the connection is a member
+            # of a connection pool.  Which means that the user is working
+            # with a `PoolConnectionProxy` instance, and expects to see it
+            # (and not the actual Connection) in their event callbacks.
+            con_ref = self._proxy
+        return con_ref
+
+    def _get_reset_query(self):
+        if self._reset_query is not None:
+            return self._reset_query
+
+        caps = self._server_caps
+
+        _reset_query = []
+        if caps.advisory_locks:
+            _reset_query.append('SELECT pg_advisory_unlock_all();')
+        if caps.sql_close_all:
+            _reset_query.append('CLOSE ALL;')
+        if caps.notifications and caps.plpgsql:
+            _reset_query.append('''
+                DO $$
+                BEGIN
+                    PERFORM * FROM pg_listening_channels() LIMIT 1;
+                    IF FOUND THEN
+                        UNLISTEN *;
+                    END IF;
+                END;
+                $$;
+            ''')
+        if caps.sql_reset:
+            _reset_query.append('RESET ALL;')
+
+        _reset_query = '\n'.join(_reset_query)
+        self._reset_query = _reset_query
+
+        return _reset_query
+
+    def _set_proxy(self, proxy):
+        if self._proxy is not None and proxy is not None:
+            # Should not happen unless there is a bug in `Pool`.
+            raise exceptions.InterfaceError(
+                'internal asyncpg error: connection is already proxied')
+
+        self._proxy = proxy
+
+    def _check_listeners(self, listeners, listener_type):
+        if listeners:
+            count = len(listeners)
+
+            w = exceptions.InterfaceWarning(
+                '{conn!r} is being released to the pool but has {c} active '
+                '{type} listener{s}'.format(
+                    conn=self, c=count, type=listener_type,
+                    s='s' if count > 1 else ''))
+
+            warnings.warn(w)
+
+    def _on_release(self, stacklevel=1):
+        # Invalidate external references to the connection.
+        self._pool_release_ctr += 1
+        # Called when the connection is about to be released to the pool.
+        # Let's check that the user has not left any listeners on it.
+        self._check_listeners(
+            list(itertools.chain.from_iterable(self._listeners.values())),
+            'notification')
+        self._check_listeners(
+            self._log_listeners, 'log')
+
+    def _drop_local_statement_cache(self):
+        self._stmt_cache.clear()
+
+    def _drop_global_statement_cache(self):
+        if self._proxy is not None:
+            # This connection is a member of a pool, so we delegate
+            # the cache drop to the pool.
+            pool = self._proxy._holder._pool
+            pool._drop_statement_cache()
+        else:
+            self._drop_local_statement_cache()
+
+    def _drop_local_type_cache(self):
+        self._protocol.get_settings().clear_type_cache()
+
+    def _drop_global_type_cache(self):
+        if self._proxy is not None:
+            # This connection is a member of a pool, so we delegate
+            # the cache drop to the pool.
+            pool = self._proxy._holder._pool
+            pool._drop_type_cache()
+        else:
+            self._drop_local_type_cache()
+
+    async def reload_schema_state(self):
+        """Indicate that the database schema information must be reloaded.
+
+        For performance reasons, asyncpg caches certain aspects of the
+        database schema, such as the layout of composite types.  Consequently,
+        when the database schema changes, and asyncpg is not able to
+        gracefully recover from an error caused by outdated schema
+        assumptions, an :exc:`~asyncpg.exceptions.OutdatedSchemaCacheError`
+        is raised.  To prevent the exception, this method may be used to inform
+        asyncpg that the database schema has changed.
+
+        Example:
+
+        .. code-block:: pycon
+
+            >>> import asyncpg
+            >>> import asyncio
+            >>> async def change_type(con):
+            ...     result = await con.fetch('SELECT id, info FROM tbl')
+            ...     # Change composite's attribute type "int"=>"text"
+            ...     await con.execute('ALTER TYPE custom DROP ATTRIBUTE y')
+            ...     await con.execute('ALTER TYPE custom ADD ATTRIBUTE y text')
+            ...     await con.reload_schema_state()
+            ...     for id_, info in result:
+            ...         new = (info['x'], str(info['y']))
+            ...         await con.execute(
+            ...             'UPDATE tbl SET info=$2 WHERE id=$1', id_, new)
+            ...
+            >>> async def run():
+            ...     # Initial schema:
+            ...     # CREATE TYPE custom AS (x int, y int);
+            ...     # CREATE TABLE tbl(id int, info custom);
+            ...     con = await asyncpg.connect(user='postgres')
+            ...     async with con.transaction():
+            ...         # Prevent concurrent changes in the table
+            ...         await con.execute('LOCK TABLE tbl')
+            ...         await change_type(con)
+            ...
+            >>> asyncio.get_event_loop().run_until_complete(run())
+
+        .. versionadded:: 0.14.0
+        """
+        self._drop_global_type_cache()
+        self._drop_global_statement_cache()
+
+    async def _execute(self, query, args, limit, timeout, return_status=False):
+        with self._stmt_exclusive_section:
+            result, _ = await self.__execute(
+                query, args, limit, timeout, return_status=return_status)
+        return result
+
+    async def __execute(self, query, args, limit, timeout,
+                        return_status=False):
+        executor = lambda stmt, timeout: self._protocol.bind_execute(
+            stmt, args, '', limit, return_status, timeout)
+        timeout = self._protocol._get_timeout(timeout)
+        return await self._do_execute(query, executor, timeout)
+
+    async def _executemany(self, query, args, timeout):
+        executor = lambda stmt, timeout: self._protocol.bind_execute_many(
+            stmt, args, '', timeout)
+        timeout = self._protocol._get_timeout(timeout)
+        with self._stmt_exclusive_section:
+            result, _ = await self._do_execute(query, executor, timeout)
+        return result
+
+    async def _do_execute(self, query, executor, timeout, retry=True):
+        if timeout is None:
+            stmt = await self._get_statement(query, None)
+        else:
+            before = time.monotonic()
+            stmt = await self._get_statement(query, timeout)
+            after = time.monotonic()
+            timeout -= after - before
+            before = after
+
+        try:
+            if timeout is None:
+                result = await executor(stmt, None)
+            else:
+                try:
+                    result = await executor(stmt, timeout)
+                finally:
+                    after = time.monotonic()
+                    timeout -= after - before
+
+        except exceptions.OutdatedSchemaCacheError:
+            # This exception is raised when we detect a difference between
+            # cached type's info and incoming tuple from the DB (when a type is
+            # changed by the ALTER TYPE).
+            # It is not possible to recover (the statement is already done at
+            # the server's side), the only way is to drop our caches and
+            # reraise the exception to the caller.
+            await self.reload_schema_state()
+            raise
+        except exceptions.InvalidCachedStatementError:
+            # PostgreSQL will raise an exception when it detects
+            # that the result type of the query has changed from
+            # when the statement was prepared.  This may happen,
+            # for example, after an ALTER TABLE or SET search_path.
+            #
+            # When this happens, and there is no transaction running,
+            # we can simply re-prepare the statement and try once
+            # again.  We deliberately retry only once as this is
+            # supposed to be a rare occurrence.
+            #
+            # If the transaction _is_ running, this error will put it
+            # into an error state, and we have no choice but to
+            # re-raise the exception.
+            #
+            # In either case we clear the statement cache for this
+            # connection and all other connections of the pool this
+            # connection belongs to (if any).
+            #
+            # See https://github.com/MagicStack/asyncpg/issues/72
+            # and https://github.com/MagicStack/asyncpg/issues/76
+            # for discussion.
+            #
+            self._drop_global_statement_cache()
+            if self._protocol.is_in_transaction() or not retry:
+                raise
+            else:
+                return await self._do_execute(
+                    query, executor, timeout, retry=False)
+
+        return result, stmt
+
+
+async def connect(dsn=None, *,
+                  host=None, port=None,
+                  user=None, password=None, passfile=None,
+                  database=None,
+                  loop=None,
+                  timeout=60,
+                  statement_cache_size=100,
+                  max_cached_statement_lifetime=300,
+                  max_cacheable_statement_size=1024 * 15,
+                  command_timeout=None,
+                  ssl=None,
+                  connection_class=Connection,
+                  server_settings=None):
+    r"""A coroutine to establish a connection to a PostgreSQL server.
+
+    The connection parameters may be specified either as a connection
+    URI in *dsn*, or as specific keyword arguments, or both.
+    If both *dsn* and keyword arguments are specified, the latter
+    override the corresponding values parsed from the connection URI.
+    The default values for the majority of arguments can be specified
+    using `environment variables <postgres envvars>`_.
+
+    Returns a new :class:`~asyncpg.connection.Connection` object.
+
+    :param dsn:
+        Connection arguments specified using as a single string in the
+        `libpq connection URI format`_:
+        ``postgres://user:password@host:port/database?option=value``.
+        The following options are recognized by asyncpg: host, port,
+        user, database (or dbname), password, passfile, sslmode.
+        Unlike libpq, asyncpg will treat unrecognized options
+        as `server settings`_ to be used for the connection.
+
+    :param host:
+        Database host address as one of the following:
+
+        - an IP address or a domain name;
+        - an absolute path to the directory containing the database
+          server Unix-domain socket (not supported on Windows);
+        - a sequence of any of the above, in which case the addresses
+          will be tried in order, and the first successful connection
+          will be returned.
+
+        If not specified, asyncpg will try the following, in order:
+
+        - host address(es) parsed from the *dsn* argument,
+        - the value of the ``PGHOST`` environment variable,
+        - on Unix, common directories used for PostgreSQL Unix-domain
+          sockets: ``"/run/postgresql"``, ``"/var/run/postgresl"``,
+          ``"/var/pgsql_socket"``, ``"/private/tmp"``, and ``"/tmp"``,
+        - ``"localhost"``.
+
+    :param port:
+        Port number to connect to at the server host
+        (or Unix-domain socket file extension).  If multiple host
+        addresses were specified, this parameter may specify a
+        sequence of port numbers of the same length as the host sequence,
+        or it may specify a single port number to be used for all host
+        addresses.
+
+        If not specified, the value parsed from the *dsn* argument is used,
+        or the value of the ``PGPORT`` environment variable, or ``5432`` if
+        neither is specified.
+
+    :param user:
+        The name of the database role used for authentication.
+
+        If not specified, the value parsed from the *dsn* argument is used,
+        or the value of the ``PGUSER`` environment variable, or the
+        operating system name of the user running the application.
+
+    :param database:
+        The name of the database to connect to.
+
+        If not specified, the value parsed from the *dsn* argument is used,
+        or the value of the ``PGDATABASE`` environment variable, or the
+        operating system name of the user running the application.
+
+    :param password:
+        Password to be used for authentication, if the server requires
+        one.  If not specified, the value parsed from the *dsn* argument
+        is used, or the value of the ``PGPASSWORD`` environment variable.
+        Note that the use of the environment variable is discouraged as
+        other users and applications may be able to read it without needing
+        specific privileges.  It is recommended to use *passfile* instead.
+
+    :param passfile:
+        The name of the file used to store passwords
+        (defaults to ``~/.pgpass``, or ``%APPDATA%\postgresql\pgpass.conf``
+        on Windows).
+
+    :param loop:
+        An asyncio event loop instance.  If ``None``, the default
+        event loop will be used.
+
+    :param float timeout:
+        Connection timeout in seconds.
+
+    :param int statement_cache_size:
+        The size of prepared statement LRU cache.  Pass ``0`` to
+        disable the cache.
+
+    :param int max_cached_statement_lifetime:
+        The maximum time in seconds a prepared statement will stay
+        in the cache.  Pass ``0`` to allow statements be cached
+        indefinitely.
+
+    :param int max_cacheable_statement_size:
+        The maximum size of a statement that can be cached (15KiB by
+        default).  Pass ``0`` to allow all statements to be cached
+        regardless of their size.
+
+    :param float command_timeout:
+        The default timeout for operations on this connection
+        (the default is ``None``: no timeout).
+
+    :param ssl:
+        Pass ``True`` or an `ssl.SSLContext <SSLContext_>`_ instance to
+        require an SSL connection.  If ``True``, a default SSL context
+        returned by `ssl.create_default_context() <create_default_context_>`_
+        will be used.
+
+    :param dict server_settings:
+        An optional dict of server runtime parameters.  Refer to
+        PostgreSQL documentation for
+        a `list of supported options <server settings>`_.
+
+    :param Connection connection_class:
+        Class of the returned connection object.  Must be a subclass of
+        :class:`~asyncpg.connection.Connection`.
+
+    :return: A :class:`~asyncpg.connection.Connection` instance.
+
+    Example:
+
+    .. code-block:: pycon
+
+        >>> import asyncpg
+        >>> import asyncio
+        >>> async def run():
+        ...     con = await asyncpg.connect(user='postgres')
+        ...     types = await con.fetch('SELECT * FROM pg_type')
+        ...     print(types)
+        ...
+        >>> asyncio.get_event_loop().run_until_complete(run())
+        [<Record typname='bool' typnamespace=11 ...
+
+    .. versionadded:: 0.10.0
+       Added ``max_cached_statement_use_count`` parameter.
+
+    .. versionchanged:: 0.11.0
+       Removed ability to pass arbitrary keyword arguments to set
+       server settings.  Added a dedicated parameter ``server_settings``
+       for that.
+
+    .. versionadded:: 0.11.0
+       Added ``connection_class`` parameter.
+
+    .. versionadded:: 0.16.0
+       Added ``passfile`` parameter
+       (and support for password files in general).
+
+    .. versionadded:: 0.18.0
+       Added ability to specify multiple hosts in the *dsn*
+       and *host* arguments.
+
+    .. _SSLContext: https://docs.python.org/3/library/ssl.html#ssl.SSLContext
+    .. _create_default_context:
+        https://docs.python.org/3/library/ssl.html#ssl.create_default_context
+    .. _server settings:
+        https://www.postgresql.org/docs/current/static/runtime-config.html
+    .. _postgres envvars:
+        https://www.postgresql.org/docs/current/static/libpq-envars.html
+    .. _libpq connection URI format:
+        https://www.postgresql.org/docs/current/static/\
+        libpq-connect.html#LIBPQ-CONNSTRING
+    """
+    if not issubclass(connection_class, Connection):
+        raise TypeError(
+            'connection_class is expected to be a subclass of '
+            'asyncpg.Connection, got {!r}'.format(connection_class))
+
+    if loop is None:
+        loop = asyncio.get_event_loop()
+
+    return await connect_utils._connect(
+        loop=loop, timeout=timeout, connection_class=connection_class,
+        dsn=dsn, host=host, port=port, user=user,
+        password=password, passfile=passfile,
+        ssl=ssl, database=database,
+        server_settings=server_settings,
+        command_timeout=command_timeout,
+        statement_cache_size=statement_cache_size,
+        max_cached_statement_lifetime=max_cached_statement_lifetime,
+        max_cacheable_statement_size=max_cacheable_statement_size)
+
+
+class _StatementCacheEntry:
+
+    __slots__ = ('_query', '_statement', '_cache', '_cleanup_cb')
+
+    def __init__(self, cache, query, statement):
+        self._cache = cache
+        self._query = query
+        self._statement = statement
+        self._cleanup_cb = None
+
+
+class _StatementCache:
+
+    __slots__ = ('_loop', '_entries', '_max_size', '_on_remove',
+                 '_max_lifetime')
+
+    def __init__(self, *, loop, max_size, on_remove, max_lifetime):
+        self._loop = loop
+        self._max_size = max_size
+        self._on_remove = on_remove
+        self._max_lifetime = max_lifetime
+
+        # We use an OrderedDict for LRU implementation.  Operations:
+        #
+        # * We use a simple `__setitem__` to push a new entry:
+        #       `entries[key] = new_entry`
+        #   That will push `new_entry` to the *end* of the entries dict.
+        #
+        # * When we have a cache hit, we call
+        #       `entries.move_to_end(key, last=True)`
+        #   to move the entry to the *end* of the entries dict.
+        #
+        # * When we need to remove entries to maintain `max_size`, we call
+        #       `entries.popitem(last=False)`
+        #   to remove an entry from the *beginning* of the entries dict.
+        #
+        # So new entries and hits are always promoted to the end of the
+        # entries dict, whereas the unused one will group in the
+        # beginning of it.
+        self._entries = collections.OrderedDict()
+
+    def __len__(self):
+        return len(self._entries)
+
+    def get_max_size(self):
+        return self._max_size
+
+    def set_max_size(self, new_size):
+        assert new_size >= 0
+        self._max_size = new_size
+        self._maybe_cleanup()
+
+    def get_max_lifetime(self):
+        return self._max_lifetime
+
+    def set_max_lifetime(self, new_lifetime):
+        assert new_lifetime >= 0
+        self._max_lifetime = new_lifetime
+        for entry in self._entries.values():
+            # For every entry cancel the existing callback
+            # and setup a new one if necessary.
+            self._set_entry_timeout(entry)
+
+    def get(self, query, *, promote=True):
+        if not self._max_size:
+            # The cache is disabled.
+            return
+
+        entry = self._entries.get(query)  # type: _StatementCacheEntry
+        if entry is None:
+            return
+
+        if entry._statement.closed:
+            # Happens in unittests when we call `stmt._state.mark_closed()`
+            # manually or when a prepared statement closes itself on type
+            # cache error.
+            self._entries.pop(query)
+            self._clear_entry_callback(entry)
+            return
+
+        if promote:
+            # `promote` is `False` when `get()` is called by `has()`.
+            self._entries.move_to_end(query, last=True)
+
+        return entry._statement
+
+    def has(self, query):
+        return self.get(query, promote=False) is not None
+
+    def put(self, query, statement):
+        if not self._max_size:
+            # The cache is disabled.
+            return
+
+        self._entries[query] = self._new_entry(query, statement)
+
+        # Check if the cache is bigger than max_size and trim it
+        # if necessary.
+        self._maybe_cleanup()
+
+    def iter_statements(self):
+        return (e._statement for e in self._entries.values())
+
+    def clear(self):
+        # First, make sure that we cancel all scheduled callbacks.
+        for entry in self._entries.values():
+            self._clear_entry_callback(entry)
+
+        # Clear the entries dict.
+        self._entries.clear()
+
+    def _set_entry_timeout(self, entry):
+        # Clear the existing timeout.
+        self._clear_entry_callback(entry)
+
+        # Set the new timeout if it's not 0.
+        if self._max_lifetime:
+            entry._cleanup_cb = self._loop.call_later(
+                self._max_lifetime, self._on_entry_expired, entry)
+
+    def _new_entry(self, query, statement):
+        entry = _StatementCacheEntry(self, query, statement)
+        self._set_entry_timeout(entry)
+        return entry
+
+    def _on_entry_expired(self, entry):
+        # `call_later` callback, called when an entry stayed longer
+        # than `self._max_lifetime`.
+        if self._entries.get(entry._query) is entry:
+            self._entries.pop(entry._query)
+            self._on_remove(entry._statement)
+
+    def _clear_entry_callback(self, entry):
+        if entry._cleanup_cb is not None:
+            entry._cleanup_cb.cancel()
+
+    def _maybe_cleanup(self):
+        # Delete cache entries until the size of the cache is `max_size`.
+        while len(self._entries) > self._max_size:
+            old_query, old_entry = self._entries.popitem(last=False)
+            self._clear_entry_callback(old_entry)
+
+            # Let the connection know that the statement was removed
+            # from the cache.
+            self._on_remove(old_entry._statement)
+
+
+class _Atomic:
+    __slots__ = ('_acquired',)
+
+    def __init__(self):
+        self._acquired = 0
+
+    def __enter__(self):
+        if self._acquired:
+            raise exceptions.InterfaceError(
+                'cannot perform operation: another operation is in progress')
+        self._acquired = 1
+
+    def __exit__(self, t, e, tb):
+        self._acquired = 0
+
+
+class _ConnectionProxy:
+    # Base class to enable `isinstance(Connection)` check.
+    __slots__ = ()
+
+
+ServerCapabilities = collections.namedtuple(
+    'ServerCapabilities',
+    ['advisory_locks', 'notifications', 'plpgsql', 'sql_reset',
+     'sql_close_all'])
+ServerCapabilities.__doc__ = 'PostgreSQL server capabilities.'
+
+
+def _detect_server_capabilities(server_version, connection_settings):
+    if hasattr(connection_settings, 'padb_revision'):
+        # Amazon Redshift detected.
+        advisory_locks = False
+        notifications = False
+        plpgsql = False
+        sql_reset = True
+        sql_close_all = False
+    elif hasattr(connection_settings, 'crdb_version'):
+        # CockroachDB detected.
+        advisory_locks = False
+        notifications = False
+        plpgsql = False
+        sql_reset = False
+        sql_close_all = False
+    elif hasattr(connection_settings, 'crate_version'):
+        # CrateDB detected.
+        advisory_locks = False
+        notifications = False
+        plpgsql = False
+        sql_reset = False
+        sql_close_all = False
+    else:
+        # Standard PostgreSQL server assumed.
+        advisory_locks = True
+        notifications = True
+        plpgsql = True
+        sql_reset = True
+        sql_close_all = True
+
+    return ServerCapabilities(
+        advisory_locks=advisory_locks,
+        notifications=notifications,
+        plpgsql=plpgsql,
+        sql_reset=sql_reset,
+        sql_close_all=sql_close_all
+    )
+
+
+def _extract_stack(limit=10):
+    """Replacement for traceback.extract_stack() that only does the
+    necessary work for asyncio debug mode.
+    """
+    frame = sys._getframe().f_back
+    try:
+        stack = traceback.StackSummary.extract(
+            traceback.walk_stack(frame), lookup_lines=False)
+    finally:
+        del frame
+
+    apg_path = asyncpg.__path__[0]
+    i = 0
+    while i < len(stack) and stack[i][0].startswith(apg_path):
+        i += 1
+    stack = stack[i:i + limit]
+
+    stack.reverse()
+    return ''.join(traceback.format_list(stack))
+
+
+_uid = 0
diff --git a/asyncpg/connresource.py b/asyncpg/connresource.py
new file mode 100644 (file)
index 0000000..3b0c1d3
--- /dev/null
@@ -0,0 +1,44 @@
+
+# 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
+
+
+import functools
+
+from . import exceptions
+
+
+def guarded(meth):
+    """A decorator to add a sanity check to ConnectionResource methods."""
+
+    @functools.wraps(meth)
+    def _check(self, *args, **kwargs):
+        self._check_conn_validity(meth.__name__)
+        return meth(self, *args, **kwargs)
+
+    return _check
+
+
+class ConnectionResource:
+    __slots__ = ('_connection', '_con_release_ctr')
+
+    def __init__(self, connection):
+        self._connection = connection
+        self._con_release_ctr = connection._pool_release_ctr
+
+    def _check_conn_validity(self, meth_name):
+        con_release_ctr = self._connection._pool_release_ctr
+        if con_release_ctr != self._con_release_ctr:
+            raise exceptions.InterfaceError(
+                'cannot call {}.{}(): '
+                'the underlying connection has been released back '
+                'to the pool'.format(self.__class__.__name__, meth_name))
+
+        if self._connection.is_closed():
+            raise exceptions.InterfaceError(
+                'cannot call {}.{}(): '
+                'the underlying connection is closed'.format(
+                    self.__class__.__name__, meth_name))
diff --git a/asyncpg/cursor.py b/asyncpg/cursor.py
new file mode 100644 (file)
index 0000000..030def0
--- /dev/null
@@ -0,0 +1,260 @@
+# 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
+
+
+import collections
+
+from . import compat
+from . import connresource
+from . import exceptions
+
+
+class CursorFactory(connresource.ConnectionResource):
+    """A cursor interface for the results of a query.
+
+    A cursor interface can be used to initiate efficient traversal of the
+    results of a large query.
+    """
+
+    __slots__ = ('_state', '_args', '_prefetch', '_query', '_timeout')
+
+    def __init__(self, connection, query, state, args, prefetch, timeout):
+        super().__init__(connection)
+        self._args = args
+        self._prefetch = prefetch
+        self._query = query
+        self._timeout = timeout
+        self._state = state
+        if state is not None:
+            state.attach()
+
+    @compat.aiter_compat
+    @connresource.guarded
+    def __aiter__(self):
+        prefetch = 50 if self._prefetch is None else self._prefetch
+        return CursorIterator(self._connection,
+                              self._query, self._state,
+                              self._args, prefetch,
+                              self._timeout)
+
+    @connresource.guarded
+    def __await__(self):
+        if self._prefetch is not None:
+            raise exceptions.InterfaceError(
+                'prefetch argument can only be specified for iterable cursor')
+        cursor = Cursor(self._connection, self._query,
+                        self._state, self._args)
+        return cursor._init(self._timeout).__await__()
+
+    def __del__(self):
+        if self._state is not None:
+            self._state.detach()
+            self._connection._maybe_gc_stmt(self._state)
+
+
+class BaseCursor(connresource.ConnectionResource):
+
+    __slots__ = ('_state', '_args', '_portal_name', '_exhausted', '_query')
+
+    def __init__(self, connection, query, state, args):
+        super().__init__(connection)
+        self._args = args
+        self._state = state
+        if state is not None:
+            state.attach()
+        self._portal_name = None
+        self._exhausted = False
+        self._query = query
+
+    def _check_ready(self):
+        if self._state is None:
+            raise exceptions.InterfaceError(
+                'cursor: no associated prepared statement')
+
+        if self._state.closed:
+            raise exceptions.InterfaceError(
+                'cursor: the prepared statement is closed')
+
+        if not self._connection._top_xact:
+            raise exceptions.NoActiveSQLTransactionError(
+                'cursor cannot be created outside of a transaction')
+
+    async def _bind_exec(self, n, timeout):
+        self._check_ready()
+
+        if self._portal_name:
+            raise exceptions.InterfaceError(
+                'cursor already has an open portal')
+
+        con = self._connection
+        protocol = con._protocol
+
+        self._portal_name = con._get_unique_id('portal')
+        buffer, _, self._exhausted = await protocol.bind_execute(
+            self._state, self._args, self._portal_name, n, True, timeout)
+        return buffer
+
+    async def _bind(self, timeout):
+        self._check_ready()
+
+        if self._portal_name:
+            raise exceptions.InterfaceError(
+                'cursor already has an open portal')
+
+        con = self._connection
+        protocol = con._protocol
+
+        self._portal_name = con._get_unique_id('portal')
+        buffer = await protocol.bind(self._state, self._args,
+                                     self._portal_name,
+                                     timeout)
+        return buffer
+
+    async def _exec(self, n, timeout):
+        self._check_ready()
+
+        if not self._portal_name:
+            raise exceptions.InterfaceError(
+                'cursor does not have an open portal')
+
+        protocol = self._connection._protocol
+        buffer, _, self._exhausted = await protocol.execute(
+            self._state, self._portal_name, n, True, timeout)
+        return buffer
+
+    def __repr__(self):
+        attrs = []
+        if self._exhausted:
+            attrs.append('exhausted')
+        attrs.append('')  # to separate from id
+
+        if self.__class__.__module__.startswith('asyncpg.'):
+            mod = 'asyncpg'
+        else:
+            mod = self.__class__.__module__
+
+        return '<{}.{} "{!s:.30}" {}{:#x}>'.format(
+            mod, self.__class__.__name__,
+            self._state.query,
+            ' '.join(attrs), id(self))
+
+    def __del__(self):
+        if self._state is not None:
+            self._state.detach()
+            self._connection._maybe_gc_stmt(self._state)
+
+
+class CursorIterator(BaseCursor):
+
+    __slots__ = ('_buffer', '_prefetch', '_timeout')
+
+    def __init__(self, connection, query, state, args, prefetch, timeout):
+        super().__init__(connection, query, state, args)
+
+        if prefetch <= 0:
+            raise exceptions.InterfaceError(
+                'prefetch argument must be greater than zero')
+
+        self._buffer = collections.deque()
+        self._prefetch = prefetch
+        self._timeout = timeout
+
+    @compat.aiter_compat
+    @connresource.guarded
+    def __aiter__(self):
+        return self
+
+    @connresource.guarded
+    async def __anext__(self):
+        if self._state is None:
+            self._state = await self._connection._get_statement(
+                self._query, self._timeout, named=True)
+            self._state.attach()
+
+        if not self._portal_name:
+            buffer = await self._bind_exec(self._prefetch, self._timeout)
+            self._buffer.extend(buffer)
+
+        if not self._buffer and not self._exhausted:
+            buffer = await self._exec(self._prefetch, self._timeout)
+            self._buffer.extend(buffer)
+
+        if self._buffer:
+            return self._buffer.popleft()
+
+        raise StopAsyncIteration
+
+
+class Cursor(BaseCursor):
+    """An open *portal* into the results of a query."""
+
+    __slots__ = ()
+
+    async def _init(self, timeout):
+        if self._state is None:
+            self._state = await self._connection._get_statement(
+                self._query, timeout, named=True)
+            self._state.attach()
+        self._check_ready()
+        await self._bind(timeout)
+        return self
+
+    @connresource.guarded
+    async def fetch(self, n, *, timeout=None):
+        r"""Return the next *n* rows as a list of :class:`Record` objects.
+
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: A list of :class:`Record` instances.
+        """
+        self._check_ready()
+        if n <= 0:
+            raise exceptions.InterfaceError('n must be greater than zero')
+        if self._exhausted:
+            return []
+        recs = await self._exec(n, timeout)
+        if len(recs) < n:
+            self._exhausted = True
+        return recs
+
+    @connresource.guarded
+    async def fetchrow(self, *, timeout=None):
+        r"""Return the next row.
+
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: A :class:`Record` instance.
+        """
+        self._check_ready()
+        if self._exhausted:
+            return None
+        recs = await self._exec(1, timeout)
+        if len(recs) < 1:
+            self._exhausted = True
+            return None
+        return recs[0]
+
+    @connresource.guarded
+    async def forward(self, n, *, timeout=None) -> int:
+        r"""Skip over the next *n* rows.
+
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: A number of rows actually skipped over (<= *n*).
+        """
+        self._check_ready()
+        if n <= 0:
+            raise exceptions.InterfaceError('n must be greater than zero')
+
+        protocol = self._connection._protocol
+        status = await protocol.query('MOVE FORWARD {:d} {}'.format(
+            n, self._portal_name), timeout)
+
+        advanced = int(status.split()[1])
+        if advanced < n:
+            self._exhausted = True
+
+        return advanced
diff --git a/asyncpg/exceptions/__init__.py b/asyncpg/exceptions/__init__.py
new file mode 100644 (file)
index 0000000..9eb2d42
--- /dev/null
@@ -0,0 +1,1105 @@
+# GENERATED FROM postgresql/src/backend/utils/errcodes.txt
+# DO NOT MODIFY, use tools/generate_exceptions.py to update
+
+from ._base import *  # NOQA
+from . import _base
+
+
+class PostgresWarning(_base.PostgresLogMessage, Warning):
+    sqlstate = '01000'
+
+
+class DynamicResultSetsReturned(PostgresWarning):
+    sqlstate = '0100C'
+
+
+class ImplicitZeroBitPadding(PostgresWarning):
+    sqlstate = '01008'
+
+
+class NullValueEliminatedInSetFunction(PostgresWarning):
+    sqlstate = '01003'
+
+
+class PrivilegeNotGranted(PostgresWarning):
+    sqlstate = '01007'
+
+
+class PrivilegeNotRevoked(PostgresWarning):
+    sqlstate = '01006'
+
+
+class StringDataRightTruncation(PostgresWarning):
+    sqlstate = '01004'
+
+
+class DeprecatedFeature(PostgresWarning):
+    sqlstate = '01P01'
+
+
+class NoData(PostgresWarning):
+    sqlstate = '02000'
+
+
+class NoAdditionalDynamicResultSetsReturned(NoData):
+    sqlstate = '02001'
+
+
+class SQLStatementNotYetCompleteError(_base.PostgresError):
+    sqlstate = '03000'
+
+
+class PostgresConnectionError(_base.PostgresError):
+    sqlstate = '08000'
+
+
+class ConnectionDoesNotExistError(PostgresConnectionError):
+    sqlstate = '08003'
+
+
+class ConnectionFailureError(PostgresConnectionError):
+    sqlstate = '08006'
+
+
+class ClientCannotConnectError(PostgresConnectionError):
+    sqlstate = '08001'
+
+
+class ConnectionRejectionError(PostgresConnectionError):
+    sqlstate = '08004'
+
+
+class TransactionResolutionUnknownError(PostgresConnectionError):
+    sqlstate = '08007'
+
+
+class ProtocolViolationError(PostgresConnectionError):
+    sqlstate = '08P01'
+
+
+class TriggeredActionError(_base.PostgresError):
+    sqlstate = '09000'
+
+
+class FeatureNotSupportedError(_base.PostgresError):
+    sqlstate = '0A000'
+
+
+class InvalidCachedStatementError(FeatureNotSupportedError):
+    pass
+
+
+class InvalidTransactionInitiationError(_base.PostgresError):
+    sqlstate = '0B000'
+
+
+class LocatorError(_base.PostgresError):
+    sqlstate = '0F000'
+
+
+class InvalidLocatorSpecificationError(LocatorError):
+    sqlstate = '0F001'
+
+
+class InvalidGrantorError(_base.PostgresError):
+    sqlstate = '0L000'
+
+
+class InvalidGrantOperationError(InvalidGrantorError):
+    sqlstate = '0LP01'
+
+
+class InvalidRoleSpecificationError(_base.PostgresError):
+    sqlstate = '0P000'
+
+
+class DiagnosticsError(_base.PostgresError):
+    sqlstate = '0Z000'
+
+
+class StackedDiagnosticsAccessedWithoutActiveHandlerError(DiagnosticsError):
+    sqlstate = '0Z002'
+
+
+class CaseNotFoundError(_base.PostgresError):
+    sqlstate = '20000'
+
+
+class CardinalityViolationError(_base.PostgresError):
+    sqlstate = '21000'
+
+
+class DataError(_base.PostgresError):
+    sqlstate = '22000'
+
+
+class ArraySubscriptError(DataError):
+    sqlstate = '2202E'
+
+
+class CharacterNotInRepertoireError(DataError):
+    sqlstate = '22021'
+
+
+class DatetimeFieldOverflowError(DataError):
+    sqlstate = '22008'
+
+
+class DivisionByZeroError(DataError):
+    sqlstate = '22012'
+
+
+class ErrorInAssignmentError(DataError):
+    sqlstate = '22005'
+
+
+class EscapeCharacterConflictError(DataError):
+    sqlstate = '2200B'
+
+
+class IndicatorOverflowError(DataError):
+    sqlstate = '22022'
+
+
+class IntervalFieldOverflowError(DataError):
+    sqlstate = '22015'
+
+
+class InvalidArgumentForLogarithmError(DataError):
+    sqlstate = '2201E'
+
+
+class InvalidArgumentForNtileFunctionError(DataError):
+    sqlstate = '22014'
+
+
+class InvalidArgumentForNthValueFunctionError(DataError):
+    sqlstate = '22016'
+
+
+class InvalidArgumentForPowerFunctionError(DataError):
+    sqlstate = '2201F'
+
+
+class InvalidArgumentForWidthBucketFunctionError(DataError):
+    sqlstate = '2201G'
+
+
+class InvalidCharacterValueForCastError(DataError):
+    sqlstate = '22018'
+
+
+class InvalidDatetimeFormatError(DataError):
+    sqlstate = '22007'
+
+
+class InvalidEscapeCharacterError(DataError):
+    sqlstate = '22019'
+
+
+class InvalidEscapeOctetError(DataError):
+    sqlstate = '2200D'
+
+
+class InvalidEscapeSequenceError(DataError):
+    sqlstate = '22025'
+
+
+class NonstandardUseOfEscapeCharacterError(DataError):
+    sqlstate = '22P06'
+
+
+class InvalidIndicatorParameterValueError(DataError):
+    sqlstate = '22010'
+
+
+class InvalidParameterValueError(DataError):
+    sqlstate = '22023'
+
+
+class InvalidRegularExpressionError(DataError):
+    sqlstate = '2201B'
+
+
+class InvalidRowCountInLimitClauseError(DataError):
+    sqlstate = '2201W'
+
+
+class InvalidRowCountInResultOffsetClauseError(DataError):
+    sqlstate = '2201X'
+
+
+class InvalidTablesampleArgumentError(DataError):
+    sqlstate = '2202H'
+
+
+class InvalidTablesampleRepeatError(DataError):
+    sqlstate = '2202G'
+
+
+class InvalidTimeZoneDisplacementValueError(DataError):
+    sqlstate = '22009'
+
+
+class InvalidUseOfEscapeCharacterError(DataError):
+    sqlstate = '2200C'
+
+
+class MostSpecificTypeMismatchError(DataError):
+    sqlstate = '2200G'
+
+
+class NullValueNotAllowedError(DataError):
+    sqlstate = '22004'
+
+
+class NullValueNoIndicatorParameterError(DataError):
+    sqlstate = '22002'
+
+
+class NumericValueOutOfRangeError(DataError):
+    sqlstate = '22003'
+
+
+class SequenceGeneratorLimitExceededError(DataError):
+    sqlstate = '2200H'
+
+
+class StringDataLengthMismatchError(DataError):
+    sqlstate = '22026'
+
+
+class StringDataRightTruncationError(DataError):
+    sqlstate = '22001'
+
+
+class SubstringError(DataError):
+    sqlstate = '22011'
+
+
+class TrimError(DataError):
+    sqlstate = '22027'
+
+
+class UnterminatedCStringError(DataError):
+    sqlstate = '22024'
+
+
+class ZeroLengthCharacterStringError(DataError):
+    sqlstate = '2200F'
+
+
+class PostgresFloatingPointError(DataError):
+    sqlstate = '22P01'
+
+
+class InvalidTextRepresentationError(DataError):
+    sqlstate = '22P02'
+
+
+class InvalidBinaryRepresentationError(DataError):
+    sqlstate = '22P03'
+
+
+class BadCopyFileFormatError(DataError):
+    sqlstate = '22P04'
+
+
+class UntranslatableCharacterError(DataError):
+    sqlstate = '22P05'
+
+
+class NotAnXmlDocumentError(DataError):
+    sqlstate = '2200L'
+
+
+class InvalidXmlDocumentError(DataError):
+    sqlstate = '2200M'
+
+
+class InvalidXmlContentError(DataError):
+    sqlstate = '2200N'
+
+
+class InvalidXmlCommentError(DataError):
+    sqlstate = '2200S'
+
+
+class InvalidXmlProcessingInstructionError(DataError):
+    sqlstate = '2200T'
+
+
+class IntegrityConstraintViolationError(_base.PostgresError):
+    sqlstate = '23000'
+
+
+class RestrictViolationError(IntegrityConstraintViolationError):
+    sqlstate = '23001'
+
+
+class NotNullViolationError(IntegrityConstraintViolationError):
+    sqlstate = '23502'
+
+
+class ForeignKeyViolationError(IntegrityConstraintViolationError):
+    sqlstate = '23503'
+
+
+class UniqueViolationError(IntegrityConstraintViolationError):
+    sqlstate = '23505'
+
+
+class CheckViolationError(IntegrityConstraintViolationError):
+    sqlstate = '23514'
+
+
+class ExclusionViolationError(IntegrityConstraintViolationError):
+    sqlstate = '23P01'
+
+
+class InvalidCursorStateError(_base.PostgresError):
+    sqlstate = '24000'
+
+
+class InvalidTransactionStateError(_base.PostgresError):
+    sqlstate = '25000'
+
+
+class ActiveSQLTransactionError(InvalidTransactionStateError):
+    sqlstate = '25001'
+
+
+class BranchTransactionAlreadyActiveError(InvalidTransactionStateError):
+    sqlstate = '25002'
+
+
+class HeldCursorRequiresSameIsolationLevelError(InvalidTransactionStateError):
+    sqlstate = '25008'
+
+
+class InappropriateAccessModeForBranchTransactionError(
+        InvalidTransactionStateError):
+    sqlstate = '25003'
+
+
+class InappropriateIsolationLevelForBranchTransactionError(
+        InvalidTransactionStateError):
+    sqlstate = '25004'
+
+
+class NoActiveSQLTransactionForBranchTransactionError(
+        InvalidTransactionStateError):
+    sqlstate = '25005'
+
+
+class ReadOnlySQLTransactionError(InvalidTransactionStateError):
+    sqlstate = '25006'
+
+
+class SchemaAndDataStatementMixingNotSupportedError(
+        InvalidTransactionStateError):
+    sqlstate = '25007'
+
+
+class NoActiveSQLTransactionError(InvalidTransactionStateError):
+    sqlstate = '25P01'
+
+
+class InFailedSQLTransactionError(InvalidTransactionStateError):
+    sqlstate = '25P02'
+
+
+class IdleInTransactionSessionTimeoutError(InvalidTransactionStateError):
+    sqlstate = '25P03'
+
+
+class InvalidSQLStatementNameError(_base.PostgresError):
+    sqlstate = '26000'
+
+
+class TriggeredDataChangeViolationError(_base.PostgresError):
+    sqlstate = '27000'
+
+
+class InvalidAuthorizationSpecificationError(_base.PostgresError):
+    sqlstate = '28000'
+
+
+class InvalidPasswordError(InvalidAuthorizationSpecificationError):
+    sqlstate = '28P01'
+
+
+class DependentPrivilegeDescriptorsStillExistError(_base.PostgresError):
+    sqlstate = '2B000'
+
+
+class DependentObjectsStillExistError(
+        DependentPrivilegeDescriptorsStillExistError):
+    sqlstate = '2BP01'
+
+
+class InvalidTransactionTerminationError(_base.PostgresError):
+    sqlstate = '2D000'
+
+
+class SQLRoutineError(_base.PostgresError):
+    sqlstate = '2F000'
+
+
+class FunctionExecutedNoReturnStatementError(SQLRoutineError):
+    sqlstate = '2F005'
+
+
+class ModifyingSQLDataNotPermittedError(SQLRoutineError):
+    sqlstate = '2F002'
+
+
+class ProhibitedSQLStatementAttemptedError(SQLRoutineError):
+    sqlstate = '2F003'
+
+
+class ReadingSQLDataNotPermittedError(SQLRoutineError):
+    sqlstate = '2F004'
+
+
+class InvalidCursorNameError(_base.PostgresError):
+    sqlstate = '34000'
+
+
+class ExternalRoutineError(_base.PostgresError):
+    sqlstate = '38000'
+
+
+class ContainingSQLNotPermittedError(ExternalRoutineError):
+    sqlstate = '38001'
+
+
+class ModifyingExternalRoutineSQLDataNotPermittedError(ExternalRoutineError):
+    sqlstate = '38002'
+
+
+class ProhibitedExternalRoutineSQLStatementAttemptedError(
+        ExternalRoutineError):
+    sqlstate = '38003'
+
+
+class ReadingExternalRoutineSQLDataNotPermittedError(ExternalRoutineError):
+    sqlstate = '38004'
+
+
+class ExternalRoutineInvocationError(_base.PostgresError):
+    sqlstate = '39000'
+
+
+class InvalidSqlstateReturnedError(ExternalRoutineInvocationError):
+    sqlstate = '39001'
+
+
+class NullValueInExternalRoutineNotAllowedError(
+        ExternalRoutineInvocationError):
+    sqlstate = '39004'
+
+
+class TriggerProtocolViolatedError(ExternalRoutineInvocationError):
+    sqlstate = '39P01'
+
+
+class SrfProtocolViolatedError(ExternalRoutineInvocationError):
+    sqlstate = '39P02'
+
+
+class EventTriggerProtocolViolatedError(ExternalRoutineInvocationError):
+    sqlstate = '39P03'
+
+
+class SavepointError(_base.PostgresError):
+    sqlstate = '3B000'
+
+
+class InvalidSavepointSpecificationError(SavepointError):
+    sqlstate = '3B001'
+
+
+class InvalidCatalogNameError(_base.PostgresError):
+    sqlstate = '3D000'
+
+
+class InvalidSchemaNameError(_base.PostgresError):
+    sqlstate = '3F000'
+
+
+class TransactionRollbackError(_base.PostgresError):
+    sqlstate = '40000'
+
+
+class TransactionIntegrityConstraintViolationError(TransactionRollbackError):
+    sqlstate = '40002'
+
+
+class SerializationError(TransactionRollbackError):
+    sqlstate = '40001'
+
+
+class StatementCompletionUnknownError(TransactionRollbackError):
+    sqlstate = '40003'
+
+
+class DeadlockDetectedError(TransactionRollbackError):
+    sqlstate = '40P01'
+
+
+class SyntaxOrAccessError(_base.PostgresError):
+    sqlstate = '42000'
+
+
+class PostgresSyntaxError(SyntaxOrAccessError):
+    sqlstate = '42601'
+
+
+class InsufficientPrivilegeError(SyntaxOrAccessError):
+    sqlstate = '42501'
+
+
+class CannotCoerceError(SyntaxOrAccessError):
+    sqlstate = '42846'
+
+
+class GroupingError(SyntaxOrAccessError):
+    sqlstate = '42803'
+
+
+class WindowingError(SyntaxOrAccessError):
+    sqlstate = '42P20'
+
+
+class InvalidRecursionError(SyntaxOrAccessError):
+    sqlstate = '42P19'
+
+
+class InvalidForeignKeyError(SyntaxOrAccessError):
+    sqlstate = '42830'
+
+
+class InvalidNameError(SyntaxOrAccessError):
+    sqlstate = '42602'
+
+
+class NameTooLongError(SyntaxOrAccessError):
+    sqlstate = '42622'
+
+
+class ReservedNameError(SyntaxOrAccessError):
+    sqlstate = '42939'
+
+
+class DatatypeMismatchError(SyntaxOrAccessError):
+    sqlstate = '42804'
+
+
+class IndeterminateDatatypeError(SyntaxOrAccessError):
+    sqlstate = '42P18'
+
+
+class CollationMismatchError(SyntaxOrAccessError):
+    sqlstate = '42P21'
+
+
+class IndeterminateCollationError(SyntaxOrAccessError):
+    sqlstate = '42P22'
+
+
+class WrongObjectTypeError(SyntaxOrAccessError):
+    sqlstate = '42809'
+
+
+class GeneratedAlwaysError(SyntaxOrAccessError):
+    sqlstate = '428C9'
+
+
+class UndefinedColumnError(SyntaxOrAccessError):
+    sqlstate = '42703'
+
+
+class UndefinedFunctionError(SyntaxOrAccessError):
+    sqlstate = '42883'
+
+
+class UndefinedTableError(SyntaxOrAccessError):
+    sqlstate = '42P01'
+
+
+class UndefinedParameterError(SyntaxOrAccessError):
+    sqlstate = '42P02'
+
+
+class UndefinedObjectError(SyntaxOrAccessError):
+    sqlstate = '42704'
+
+
+class DuplicateColumnError(SyntaxOrAccessError):
+    sqlstate = '42701'
+
+
+class DuplicateCursorError(SyntaxOrAccessError):
+    sqlstate = '42P03'
+
+
+class DuplicateDatabaseError(SyntaxOrAccessError):
+    sqlstate = '42P04'
+
+
+class DuplicateFunctionError(SyntaxOrAccessError):
+    sqlstate = '42723'
+
+
+class DuplicatePreparedStatementError(SyntaxOrAccessError):
+    sqlstate = '42P05'
+
+
+class DuplicateSchemaError(SyntaxOrAccessError):
+    sqlstate = '42P06'
+
+
+class DuplicateTableError(SyntaxOrAccessError):
+    sqlstate = '42P07'
+
+
+class DuplicateAliasError(SyntaxOrAccessError):
+    sqlstate = '42712'
+
+
+class DuplicateObjectError(SyntaxOrAccessError):
+    sqlstate = '42710'
+
+
+class AmbiguousColumnError(SyntaxOrAccessError):
+    sqlstate = '42702'
+
+
+class AmbiguousFunctionError(SyntaxOrAccessError):
+    sqlstate = '42725'
+
+
+class AmbiguousParameterError(SyntaxOrAccessError):
+    sqlstate = '42P08'
+
+
+class AmbiguousAliasError(SyntaxOrAccessError):
+    sqlstate = '42P09'
+
+
+class InvalidColumnReferenceError(SyntaxOrAccessError):
+    sqlstate = '42P10'
+
+
+class InvalidColumnDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42611'
+
+
+class InvalidCursorDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P11'
+
+
+class InvalidDatabaseDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P12'
+
+
+class InvalidFunctionDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P13'
+
+
+class InvalidPreparedStatementDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P14'
+
+
+class InvalidSchemaDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P15'
+
+
+class InvalidTableDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P16'
+
+
+class InvalidObjectDefinitionError(SyntaxOrAccessError):
+    sqlstate = '42P17'
+
+
+class WithCheckOptionViolationError(_base.PostgresError):
+    sqlstate = '44000'
+
+
+class InsufficientResourcesError(_base.PostgresError):
+    sqlstate = '53000'
+
+
+class DiskFullError(InsufficientResourcesError):
+    sqlstate = '53100'
+
+
+class OutOfMemoryError(InsufficientResourcesError):
+    sqlstate = '53200'
+
+
+class TooManyConnectionsError(InsufficientResourcesError):
+    sqlstate = '53300'
+
+
+class ConfigurationLimitExceededError(InsufficientResourcesError):
+    sqlstate = '53400'
+
+
+class ProgramLimitExceededError(_base.PostgresError):
+    sqlstate = '54000'
+
+
+class StatementTooComplexError(ProgramLimitExceededError):
+    sqlstate = '54001'
+
+
+class TooManyColumnsError(ProgramLimitExceededError):
+    sqlstate = '54011'
+
+
+class TooManyArgumentsError(ProgramLimitExceededError):
+    sqlstate = '54023'
+
+
+class ObjectNotInPrerequisiteStateError(_base.PostgresError):
+    sqlstate = '55000'
+
+
+class ObjectInUseError(ObjectNotInPrerequisiteStateError):
+    sqlstate = '55006'
+
+
+class CantChangeRuntimeParamError(ObjectNotInPrerequisiteStateError):
+    sqlstate = '55P02'
+
+
+class LockNotAvailableError(ObjectNotInPrerequisiteStateError):
+    sqlstate = '55P03'
+
+
+class OperatorInterventionError(_base.PostgresError):
+    sqlstate = '57000'
+
+
+class QueryCanceledError(OperatorInterventionError):
+    sqlstate = '57014'
+
+
+class AdminShutdownError(OperatorInterventionError):
+    sqlstate = '57P01'
+
+
+class CrashShutdownError(OperatorInterventionError):
+    sqlstate = '57P02'
+
+
+class CannotConnectNowError(OperatorInterventionError):
+    sqlstate = '57P03'
+
+
+class DatabaseDroppedError(OperatorInterventionError):
+    sqlstate = '57P04'
+
+
+class PostgresSystemError(_base.PostgresError):
+    sqlstate = '58000'
+
+
+class PostgresIOError(PostgresSystemError):
+    sqlstate = '58030'
+
+
+class UndefinedFileError(PostgresSystemError):
+    sqlstate = '58P01'
+
+
+class DuplicateFileError(PostgresSystemError):
+    sqlstate = '58P02'
+
+
+class SnapshotTooOldError(_base.PostgresError):
+    sqlstate = '72000'
+
+
+class ConfigFileError(_base.PostgresError):
+    sqlstate = 'F0000'
+
+
+class LockFileExistsError(ConfigFileError):
+    sqlstate = 'F0001'
+
+
+class FDWError(_base.PostgresError):
+    sqlstate = 'HV000'
+
+
+class FDWColumnNameNotFoundError(FDWError):
+    sqlstate = 'HV005'
+
+
+class FDWDynamicParameterValueNeededError(FDWError):
+    sqlstate = 'HV002'
+
+
+class FDWFunctionSequenceError(FDWError):
+    sqlstate = 'HV010'
+
+
+class FDWInconsistentDescriptorInformationError(FDWError):
+    sqlstate = 'HV021'
+
+
+class FDWInvalidAttributeValueError(FDWError):
+    sqlstate = 'HV024'
+
+
+class FDWInvalidColumnNameError(FDWError):
+    sqlstate = 'HV007'
+
+
+class FDWInvalidColumnNumberError(FDWError):
+    sqlstate = 'HV008'
+
+
+class FDWInvalidDataTypeError(FDWError):
+    sqlstate = 'HV004'
+
+
+class FDWInvalidDataTypeDescriptorsError(FDWError):
+    sqlstate = 'HV006'
+
+
+class FDWInvalidDescriptorFieldIdentifierError(FDWError):
+    sqlstate = 'HV091'
+
+
+class FDWInvalidHandleError(FDWError):
+    sqlstate = 'HV00B'
+
+
+class FDWInvalidOptionIndexError(FDWError):
+    sqlstate = 'HV00C'
+
+
+class FDWInvalidOptionNameError(FDWError):
+    sqlstate = 'HV00D'
+
+
+class FDWInvalidStringLengthOrBufferLengthError(FDWError):
+    sqlstate = 'HV090'
+
+
+class FDWInvalidStringFormatError(FDWError):
+    sqlstate = 'HV00A'
+
+
+class FDWInvalidUseOfNullPointerError(FDWError):
+    sqlstate = 'HV009'
+
+
+class FDWTooManyHandlesError(FDWError):
+    sqlstate = 'HV014'
+
+
+class FDWOutOfMemoryError(FDWError):
+    sqlstate = 'HV001'
+
+
+class FDWNoSchemasError(FDWError):
+    sqlstate = 'HV00P'
+
+
+class FDWOptionNameNotFoundError(FDWError):
+    sqlstate = 'HV00J'
+
+
+class FDWReplyHandleError(FDWError):
+    sqlstate = 'HV00K'
+
+
+class FDWSchemaNotFoundError(FDWError):
+    sqlstate = 'HV00Q'
+
+
+class FDWTableNotFoundError(FDWError):
+    sqlstate = 'HV00R'
+
+
+class FDWUnableToCreateExecutionError(FDWError):
+    sqlstate = 'HV00L'
+
+
+class FDWUnableToCreateReplyError(FDWError):
+    sqlstate = 'HV00M'
+
+
+class FDWUnableToEstablishConnectionError(FDWError):
+    sqlstate = 'HV00N'
+
+
+class PLPGSQLError(_base.PostgresError):
+    sqlstate = 'P0000'
+
+
+class RaiseError(PLPGSQLError):
+    sqlstate = 'P0001'
+
+
+class NoDataFoundError(PLPGSQLError):
+    sqlstate = 'P0002'
+
+
+class TooManyRowsError(PLPGSQLError):
+    sqlstate = 'P0003'
+
+
+class AssertError(PLPGSQLError):
+    sqlstate = 'P0004'
+
+
+class InternalServerError(_base.PostgresError):
+    sqlstate = 'XX000'
+
+
+class DataCorruptedError(InternalServerError):
+    sqlstate = 'XX001'
+
+
+class IndexCorruptedError(InternalServerError):
+    sqlstate = 'XX002'
+
+
+__all__ = _base.__all__ + (
+    'ActiveSQLTransactionError', 'AdminShutdownError',
+    'AmbiguousAliasError', 'AmbiguousColumnError',
+    'AmbiguousFunctionError', 'AmbiguousParameterError',
+    'ArraySubscriptError', 'AssertError', 'BadCopyFileFormatError',
+    'BranchTransactionAlreadyActiveError', 'CannotCoerceError',
+    'CannotConnectNowError', 'CantChangeRuntimeParamError',
+    'CardinalityViolationError', 'CaseNotFoundError',
+    'CharacterNotInRepertoireError', 'CheckViolationError',
+    'ClientCannotConnectError', 'CollationMismatchError',
+    'ConfigFileError', 'ConfigurationLimitExceededError',
+    'ConnectionDoesNotExistError', 'ConnectionFailureError',
+    'ConnectionRejectionError', 'ContainingSQLNotPermittedError',
+    'CrashShutdownError', 'DataCorruptedError', 'DataError',
+    'DatabaseDroppedError', 'DatatypeMismatchError',
+    'DatetimeFieldOverflowError', 'DeadlockDetectedError',
+    'DependentObjectsStillExistError',
+    'DependentPrivilegeDescriptorsStillExistError', 'DeprecatedFeature',
+    'DiagnosticsError', 'DiskFullError', 'DivisionByZeroError',
+    'DuplicateAliasError', 'DuplicateColumnError', 'DuplicateCursorError',
+    'DuplicateDatabaseError', 'DuplicateFileError',
+    'DuplicateFunctionError', 'DuplicateObjectError',
+    'DuplicatePreparedStatementError', 'DuplicateSchemaError',
+    'DuplicateTableError', 'DynamicResultSetsReturned',
+    'ErrorInAssignmentError', 'EscapeCharacterConflictError',
+    'EventTriggerProtocolViolatedError', 'ExclusionViolationError',
+    'ExternalRoutineError', 'ExternalRoutineInvocationError',
+    'FDWColumnNameNotFoundError', 'FDWDynamicParameterValueNeededError',
+    'FDWError', 'FDWFunctionSequenceError',
+    'FDWInconsistentDescriptorInformationError',
+    'FDWInvalidAttributeValueError', 'FDWInvalidColumnNameError',
+    'FDWInvalidColumnNumberError', 'FDWInvalidDataTypeDescriptorsError',
+    'FDWInvalidDataTypeError', 'FDWInvalidDescriptorFieldIdentifierError',
+    'FDWInvalidHandleError', 'FDWInvalidOptionIndexError',
+    'FDWInvalidOptionNameError', 'FDWInvalidStringFormatError',
+    'FDWInvalidStringLengthOrBufferLengthError',
+    'FDWInvalidUseOfNullPointerError', 'FDWNoSchemasError',
+    'FDWOptionNameNotFoundError', 'FDWOutOfMemoryError',
+    'FDWReplyHandleError', 'FDWSchemaNotFoundError',
+    'FDWTableNotFoundError', 'FDWTooManyHandlesError',
+    'FDWUnableToCreateExecutionError', 'FDWUnableToCreateReplyError',
+    'FDWUnableToEstablishConnectionError', 'FeatureNotSupportedError',
+    'ForeignKeyViolationError', 'FunctionExecutedNoReturnStatementError',
+    'GeneratedAlwaysError', 'GroupingError',
+    'HeldCursorRequiresSameIsolationLevelError',
+    'IdleInTransactionSessionTimeoutError', 'ImplicitZeroBitPadding',
+    'InFailedSQLTransactionError',
+    'InappropriateAccessModeForBranchTransactionError',
+    'InappropriateIsolationLevelForBranchTransactionError',
+    'IndeterminateCollationError', 'IndeterminateDatatypeError',
+    'IndexCorruptedError', 'IndicatorOverflowError',
+    'InsufficientPrivilegeError', 'InsufficientResourcesError',
+    'IntegrityConstraintViolationError', 'InternalServerError',
+    'IntervalFieldOverflowError', 'InvalidArgumentForLogarithmError',
+    'InvalidArgumentForNthValueFunctionError',
+    'InvalidArgumentForNtileFunctionError',
+    'InvalidArgumentForPowerFunctionError',
+    'InvalidArgumentForWidthBucketFunctionError',
+    'InvalidAuthorizationSpecificationError',
+    'InvalidBinaryRepresentationError', 'InvalidCachedStatementError',
+    'InvalidCatalogNameError', 'InvalidCharacterValueForCastError',
+    'InvalidColumnDefinitionError', 'InvalidColumnReferenceError',
+    'InvalidCursorDefinitionError', 'InvalidCursorNameError',
+    'InvalidCursorStateError', 'InvalidDatabaseDefinitionError',
+    'InvalidDatetimeFormatError', 'InvalidEscapeCharacterError',
+    'InvalidEscapeOctetError', 'InvalidEscapeSequenceError',
+    'InvalidForeignKeyError', 'InvalidFunctionDefinitionError',
+    'InvalidGrantOperationError', 'InvalidGrantorError',
+    'InvalidIndicatorParameterValueError',
+    'InvalidLocatorSpecificationError', 'InvalidNameError',
+    'InvalidObjectDefinitionError', 'InvalidParameterValueError',
+    'InvalidPasswordError', 'InvalidPreparedStatementDefinitionError',
+    'InvalidRecursionError', 'InvalidRegularExpressionError',
+    'InvalidRoleSpecificationError', 'InvalidRowCountInLimitClauseError',
+    'InvalidRowCountInResultOffsetClauseError',
+    'InvalidSQLStatementNameError', 'InvalidSavepointSpecificationError',
+    'InvalidSchemaDefinitionError', 'InvalidSchemaNameError',
+    'InvalidSqlstateReturnedError', 'InvalidTableDefinitionError',
+    'InvalidTablesampleArgumentError', 'InvalidTablesampleRepeatError',
+    'InvalidTextRepresentationError',
+    'InvalidTimeZoneDisplacementValueError',
+    'InvalidTransactionInitiationError', 'InvalidTransactionStateError',
+    'InvalidTransactionTerminationError',
+    'InvalidUseOfEscapeCharacterError', 'InvalidXmlCommentError',
+    'InvalidXmlContentError', 'InvalidXmlDocumentError',
+    'InvalidXmlProcessingInstructionError', 'LocatorError',
+    'LockFileExistsError', 'LockNotAvailableError',
+    'ModifyingExternalRoutineSQLDataNotPermittedError',
+    'ModifyingSQLDataNotPermittedError', 'MostSpecificTypeMismatchError',
+    'NameTooLongError', 'NoActiveSQLTransactionError',
+    'NoActiveSQLTransactionForBranchTransactionError',
+    'NoAdditionalDynamicResultSetsReturned', 'NoData', 'NoDataFoundError',
+    'NonstandardUseOfEscapeCharacterError', 'NotAnXmlDocumentError',
+    'NotNullViolationError', 'NullValueEliminatedInSetFunction',
+    'NullValueInExternalRoutineNotAllowedError',
+    'NullValueNoIndicatorParameterError', 'NullValueNotAllowedError',
+    'NumericValueOutOfRangeError', 'ObjectInUseError',
+    'ObjectNotInPrerequisiteStateError', 'OperatorInterventionError',
+    'OutOfMemoryError', 'PLPGSQLError', 'PostgresConnectionError',
+    'PostgresFloatingPointError', 'PostgresIOError',
+    'PostgresSyntaxError', 'PostgresSystemError', 'PostgresWarning',
+    'PrivilegeNotGranted', 'PrivilegeNotRevoked',
+    'ProgramLimitExceededError',
+    'ProhibitedExternalRoutineSQLStatementAttemptedError',
+    'ProhibitedSQLStatementAttemptedError', 'ProtocolViolationError',
+    'QueryCanceledError', 'RaiseError', 'ReadOnlySQLTransactionError',
+    'ReadingExternalRoutineSQLDataNotPermittedError',
+    'ReadingSQLDataNotPermittedError', 'ReservedNameError',
+    'RestrictViolationError', 'SQLRoutineError',
+    'SQLStatementNotYetCompleteError', 'SavepointError',
+    'SchemaAndDataStatementMixingNotSupportedError',
+    'SequenceGeneratorLimitExceededError', 'SerializationError',
+    'SnapshotTooOldError', 'SrfProtocolViolatedError',
+    'StackedDiagnosticsAccessedWithoutActiveHandlerError',
+    'StatementCompletionUnknownError', 'StatementTooComplexError',
+    'StringDataLengthMismatchError', 'StringDataRightTruncation',
+    'StringDataRightTruncationError', 'SubstringError',
+    'SyntaxOrAccessError', 'TooManyArgumentsError', 'TooManyColumnsError',
+    'TooManyConnectionsError', 'TooManyRowsError',
+    'TransactionIntegrityConstraintViolationError',
+    'TransactionResolutionUnknownError', 'TransactionRollbackError',
+    'TriggerProtocolViolatedError', 'TriggeredActionError',
+    'TriggeredDataChangeViolationError', 'TrimError',
+    'UndefinedColumnError', 'UndefinedFileError',
+    'UndefinedFunctionError', 'UndefinedObjectError',
+    'UndefinedParameterError', 'UndefinedTableError',
+    'UniqueViolationError', 'UnterminatedCStringError',
+    'UntranslatableCharacterError', 'WindowingError',
+    'WithCheckOptionViolationError', 'WrongObjectTypeError',
+    'ZeroLengthCharacterStringError'
+)
diff --git a/asyncpg/exceptions/_base.py b/asyncpg/exceptions/_base.py
new file mode 100644 (file)
index 0000000..3e6ef81
--- /dev/null
@@ -0,0 +1,270 @@
+# 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
+
+
+import asyncpg
+import sys
+import textwrap
+
+
+__all__ = ('PostgresError', 'FatalPostgresError', 'UnknownPostgresError',
+           'InterfaceError', 'InterfaceWarning', 'PostgresLogMessage',
+           'InternalClientError', 'OutdatedSchemaCacheError', 'ProtocolError')
+
+
+def _is_asyncpg_class(cls):
+    modname = cls.__module__
+    return modname == 'asyncpg' or modname.startswith('asyncpg.')
+
+
+class PostgresMessageMeta(type):
+
+    _message_map = {}
+    _field_map = {
+        'S': 'severity',
+        'V': 'severity_en',
+        'C': 'sqlstate',
+        'M': 'message',
+        'D': 'detail',
+        'H': 'hint',
+        'P': 'position',
+        'p': 'internal_position',
+        'q': 'internal_query',
+        'W': 'context',
+        's': 'schema_name',
+        't': 'table_name',
+        'c': 'column_name',
+        'd': 'data_type_name',
+        'n': 'constraint_name',
+        'F': 'server_source_filename',
+        'L': 'server_source_line',
+        'R': 'server_source_function'
+    }
+
+    def __new__(mcls, name, bases, dct):
+        cls = super().__new__(mcls, name, bases, dct)
+        if cls.__module__ == mcls.__module__ and name == 'PostgresMessage':
+            for f in mcls._field_map.values():
+                setattr(cls, f, None)
+
+        if _is_asyncpg_class(cls):
+            mod = sys.modules[cls.__module__]
+            if hasattr(mod, name):
+                raise RuntimeError('exception class redefinition: {}'.format(
+                    name))
+
+        code = dct.get('sqlstate')
+        if code is not None:
+            existing = mcls._message_map.get(code)
+            if existing is not None:
+                raise TypeError('{} has duplicate SQLSTATE code, which is'
+                                'already defined by {}'.format(
+                                    name, existing.__name__))
+            mcls._message_map[code] = cls
+
+        return cls
+
+    @classmethod
+    def get_message_class_for_sqlstate(mcls, code):
+        return mcls._message_map.get(code, UnknownPostgresError)
+
+
+class PostgresMessage(metaclass=PostgresMessageMeta):
+
+    @classmethod
+    def _get_error_class(cls, fields):
+        sqlstate = fields.get('C')
+        return type(cls).get_message_class_for_sqlstate(sqlstate)
+
+    @classmethod
+    def _get_error_dict(cls, fields, query):
+        dct = {
+            'query': query
+        }
+
+        field_map = type(cls)._field_map
+        for k, v in fields.items():
+            field = field_map.get(k)
+            if field:
+                dct[field] = v
+
+        return dct
+
+    @classmethod
+    def _make_constructor(cls, fields, query=None):
+        dct = cls._get_error_dict(fields, query)
+
+        exccls = cls._get_error_class(fields)
+        message = dct.get('message', '')
+
+        # PostgreSQL will raise an exception when it detects
+        # that the result type of the query has changed from
+        # when the statement was prepared.
+        #
+        # The original error is somewhat cryptic and unspecific,
+        # so we raise a custom subclass that is easier to handle
+        # and identify.
+        #
+        # Note that we specifically do not rely on the error
+        # message, as it is localizable.
+        is_icse = (
+            exccls.__name__ == 'FeatureNotSupportedError' and
+            _is_asyncpg_class(exccls) and
+            dct.get('server_source_function') == 'RevalidateCachedQuery'
+        )
+
+        if is_icse:
+            exceptions = sys.modules[exccls.__module__]
+            exccls = exceptions.InvalidCachedStatementError
+            message = ('cached statement plan is invalid due to a database '
+                       'schema or configuration change')
+
+        is_prepared_stmt_error = (
+            exccls.__name__ in ('DuplicatePreparedStatementError',
+                                'InvalidSQLStatementNameError') and
+            _is_asyncpg_class(exccls)
+        )
+
+        if is_prepared_stmt_error:
+            hint = dct.get('hint', '')
+            hint += textwrap.dedent("""\
+
+                NOTE: pgbouncer with pool_mode set to "transaction" or
+                "statement" does not support prepared statements properly.
+                You have two options:
+
+                * if you are using pgbouncer for connection pooling to a
+                  single server, switch to the connection pool functionality
+                  provided by asyncpg, it is a much better option for this
+                  purpose;
+
+                * if you have no option of avoiding the use of pgbouncer,
+                  then you must switch pgbouncer's pool_mode to "session".
+            """)
+
+            dct['hint'] = hint
+
+        return exccls, message, dct
+
+    def as_dict(self):
+        dct = {}
+        for f in type(self)._field_map.values():
+            val = getattr(self, f)
+            if val is not None:
+                dct[f] = val
+        return dct
+
+
+class PostgresError(PostgresMessage, Exception):
+    """Base class for all Postgres errors."""
+
+    def __str__(self):
+        msg = self.args[0]
+        if self.detail:
+            msg += '\nDETAIL:  {}'.format(self.detail)
+        if self.hint:
+            msg += '\nHINT:  {}'.format(self.hint)
+
+        return msg
+
+    @classmethod
+    def new(cls, fields, query=None):
+        exccls, message, dct = cls._make_constructor(fields, query)
+        ex = exccls(message)
+        ex.__dict__.update(dct)
+        return ex
+
+
+class FatalPostgresError(PostgresError):
+    """A fatal error that should result in server disconnection."""
+
+
+class UnknownPostgresError(FatalPostgresError):
+    """An error with an unknown SQLSTATE code."""
+
+
+class InterfaceMessage:
+    def __init__(self, *, detail=None, hint=None):
+        self.detail = detail
+        self.hint = hint
+
+    def __str__(self):
+        msg = self.args[0]
+        if self.detail:
+            msg += '\nDETAIL:  {}'.format(self.detail)
+        if self.hint:
+            msg += '\nHINT:  {}'.format(self.hint)
+
+        return msg
+
+
+class InterfaceError(InterfaceMessage, Exception):
+    """An error caused by improper use of asyncpg API."""
+
+    def __init__(self, msg, *, detail=None, hint=None):
+        InterfaceMessage.__init__(self, detail=detail, hint=hint)
+        Exception.__init__(self, msg)
+
+
+class DataError(InterfaceError, ValueError):
+    """An error caused by invalid query input."""
+
+
+class InterfaceWarning(InterfaceMessage, UserWarning):
+    """A warning caused by an improper use of asyncpg API."""
+
+    def __init__(self, msg, *, detail=None, hint=None):
+        InterfaceMessage.__init__(self, detail=detail, hint=hint)
+        UserWarning.__init__(self, msg)
+
+
+class InternalClientError(Exception):
+    """All unexpected errors not classified otherwise."""
+
+
+class ProtocolError(InternalClientError):
+    """Unexpected condition in the handling of PostgreSQL protocol input."""
+
+
+class OutdatedSchemaCacheError(InternalClientError):
+    """A value decoding error caused by a schema change before row fetching."""
+
+    def __init__(self, msg, *, schema=None, data_type=None, position=None):
+        super().__init__(msg)
+        self.schema_name = schema
+        self.data_type_name = data_type
+        self.position = position
+
+
+class PostgresLogMessage(PostgresMessage):
+    """A base class for non-error server messages."""
+
+    def __str__(self):
+        return '{}: {}'.format(type(self).__name__, self.message)
+
+    def __setattr__(self, name, val):
+        raise TypeError('instances of {} are immutable'.format(
+            type(self).__name__))
+
+    @classmethod
+    def new(cls, fields, query=None):
+        exccls, message_text, dct = cls._make_constructor(fields, query)
+
+        if exccls is UnknownPostgresError:
+            exccls = PostgresLogMessage
+
+        if exccls is PostgresLogMessage:
+            severity = dct.get('severity_en') or dct.get('severity')
+            if severity and severity.upper() == 'WARNING':
+                exccls = asyncpg.PostgresWarning
+
+        if issubclass(exccls, (BaseException, Warning)):
+            msg = exccls(message_text)
+        else:
+            msg = exccls()
+
+        msg.__dict__.update(dct)
+        return msg
diff --git a/asyncpg/introspection.py b/asyncpg/introspection.py
new file mode 100644 (file)
index 0000000..201f434
--- /dev/null
@@ -0,0 +1,158 @@
+# 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
+
+
+_TYPEINFO = '''\
+    (
+        SELECT
+            t.oid                           AS oid,
+            ns.nspname                      AS ns,
+            t.typname                       AS name,
+            t.typtype                       AS kind,
+            (CASE WHEN t.typtype = 'd' THEN
+                (WITH RECURSIVE typebases(oid, depth) AS (
+                    SELECT
+                        t2.typbasetype      AS oid,
+                        0                   AS depth
+                    FROM
+                        pg_type t2
+                    WHERE
+                        t2.oid = t.oid
+
+                    UNION ALL
+
+                    SELECT
+                        t2.typbasetype      AS oid,
+                        tb.depth + 1        AS depth
+                    FROM
+                        pg_type t2,
+                        typebases tb
+                    WHERE
+                       tb.oid = t2.oid
+                       AND t2.typbasetype != 0
+               ) SELECT oid FROM typebases ORDER BY depth DESC LIMIT 1)
+
+               ELSE NULL
+            END)                            AS basetype,
+            t.typreceive::oid != 0 AND t.typsend::oid != 0
+                                            AS has_bin_io,
+            t.typelem                       AS elemtype,
+            elem_t.typdelim                 AS elemdelim,
+            range_t.rngsubtype              AS range_subtype,
+            (CASE WHEN t.typtype = 'r' THEN
+                (SELECT
+                    range_elem_t.typreceive::oid != 0 AND
+                        range_elem_t.typsend::oid != 0
+                FROM
+                    pg_catalog.pg_type AS range_elem_t
+                WHERE
+                    range_elem_t.oid = range_t.rngsubtype)
+            ELSE
+                elem_t.typreceive::oid != 0 AND
+                    elem_t.typsend::oid != 0
+            END)                            AS elem_has_bin_io,
+            (CASE WHEN t.typtype = 'c' THEN
+                (SELECT
+                    array_agg(ia.atttypid ORDER BY ia.attnum)
+                FROM
+                    pg_attribute ia
+                    INNER JOIN pg_class c
+                        ON (ia.attrelid = c.oid)
+                WHERE
+                    ia.attnum > 0 AND NOT ia.attisdropped
+                    AND c.reltype = t.oid)
+
+                ELSE NULL
+            END)                            AS attrtypoids,
+            (CASE WHEN t.typtype = 'c' THEN
+                (SELECT
+                    array_agg(ia.attname::text ORDER BY ia.attnum)
+                FROM
+                    pg_attribute ia
+                    INNER JOIN pg_class c
+                        ON (ia.attrelid = c.oid)
+                WHERE
+                    ia.attnum > 0 AND NOT ia.attisdropped
+                    AND c.reltype = t.oid)
+
+                ELSE NULL
+            END)                            AS attrnames
+        FROM
+            pg_catalog.pg_type AS t
+            INNER JOIN pg_catalog.pg_namespace ns ON (
+                ns.oid = t.typnamespace)
+            LEFT JOIN pg_type elem_t ON (
+                t.typlen = -1 AND
+                t.typelem != 0 AND
+                t.typelem = elem_t.oid
+            )
+            LEFT JOIN pg_range range_t ON (
+                t.oid = range_t.rngtypid
+            )
+    )
+'''
+
+
+INTRO_LOOKUP_TYPES = '''\
+WITH RECURSIVE typeinfo_tree(
+    oid, ns, name, kind, basetype, has_bin_io, elemtype, elemdelim,
+    range_subtype, elem_has_bin_io, attrtypoids, attrnames, depth)
+AS (
+    SELECT
+        ti.oid, ti.ns, ti.name, ti.kind, ti.basetype, ti.has_bin_io,
+        ti.elemtype, ti.elemdelim, ti.range_subtype, ti.elem_has_bin_io,
+        ti.attrtypoids, ti.attrnames, 0
+    FROM
+        {typeinfo} AS ti
+    WHERE
+        ti.oid = any($1::oid[])
+
+    UNION ALL
+
+    SELECT
+        ti.oid, ti.ns, ti.name, ti.kind, ti.basetype, ti.has_bin_io,
+        ti.elemtype, ti.elemdelim, ti.range_subtype, ti.elem_has_bin_io,
+        ti.attrtypoids, ti.attrnames, tt.depth + 1
+    FROM
+        {typeinfo} ti,
+        typeinfo_tree tt
+    WHERE
+        (tt.elemtype IS NOT NULL AND ti.oid = tt.elemtype)
+        OR (tt.attrtypoids IS NOT NULL AND ti.oid = any(tt.attrtypoids))
+        OR (tt.range_subtype IS NOT NULL AND ti.oid = tt.range_subtype)
+)
+
+SELECT DISTINCT
+    *
+FROM
+    typeinfo_tree
+ORDER BY
+    depth DESC
+'''.format(typeinfo=_TYPEINFO)
+
+
+TYPE_BY_NAME = '''\
+SELECT
+    t.oid,
+    t.typelem     AS elemtype,
+    t.typtype     AS kind
+FROM
+    pg_catalog.pg_type AS t
+    INNER JOIN pg_catalog.pg_namespace ns ON (ns.oid = t.typnamespace)
+WHERE
+    t.typname = $1 AND ns.nspname = $2
+'''
+
+
+# 'b' for a base type, 'd' for a domain, 'e' for enum.
+SCALAR_TYPE_KINDS = (b'b', b'd', b'e')
+
+
+def is_scalar_type(typeinfo) -> bool:
+    return (
+        typeinfo['kind'] in SCALAR_TYPE_KINDS and
+        not typeinfo['elemtype']
+    )
diff --git a/asyncpg/pgproto/__init__.pxd b/asyncpg/pgproto/__init__.pxd
new file mode 100644 (file)
index 0000000..1df403c
--- /dev/null
@@ -0,0 +1,5 @@
+# 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
diff --git a/asyncpg/pgproto/__init__.py b/asyncpg/pgproto/__init__.py
new file mode 100644 (file)
index 0000000..1df403c
--- /dev/null
@@ -0,0 +1,5 @@
+# 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
diff --git a/asyncpg/pgproto/buffer.pxd b/asyncpg/pgproto/buffer.pxd
new file mode 100644 (file)
index 0000000..0040dfc
--- /dev/null
@@ -0,0 +1,129 @@
+# 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 class WriteBuffer:
+    cdef:
+        # Preallocated small buffer
+        bint _smallbuf_inuse
+        char _smallbuf[_BUFFER_INITIAL_SIZE]
+
+        char *_buf
+
+        # Allocated size
+        ssize_t _size
+
+        # Length of data in the buffer
+        ssize_t _length
+
+        # Number of memoryviews attached to the buffer
+        int _view_count
+
+        # True is start_message was used
+        bint _message_mode
+
+    cdef inline len(self):
+        return self._length
+
+    cdef inline _check_readonly(self)
+    cdef inline _ensure_alloced(self, ssize_t extra_length)
+    cdef _reallocate(self, ssize_t new_size)
+    cdef inline start_message(self, char type)
+    cdef inline end_message(self)
+    cdef write_buffer(self, WriteBuffer buf)
+    cdef write_byte(self, char b)
+    cdef write_bytes(self, bytes data)
+    cdef write_bytestring(self, bytes string)
+    cdef write_str(self, str string, str encoding)
+    cdef write_utf8(self, str string)
+    cdef write_cstr(self, const char *data, ssize_t len)
+    cdef write_int16(self, int16_t i)
+    cdef write_int32(self, int32_t i)
+    cdef write_int64(self, int64_t i)
+    cdef write_float(self, float f)
+    cdef write_double(self, double d)
+
+    @staticmethod
+    cdef WriteBuffer new_message(char type)
+
+    @staticmethod
+    cdef WriteBuffer new()
+
+
+ctypedef const char * (*try_consume_message_method)(object, ssize_t*)
+ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ctypedef int32_t (*take_message_method)(object) except -1
+ctypedef char (*get_message_type_method)(object)
+
+
+cdef class ReadBuffer:
+    cdef:
+        # A deque of buffers (bytes objects)
+        object _bufs
+        object _bufs_append
+        object _bufs_popleft
+
+        # A pointer to the first buffer in `_bufs`
+        bytes _buf0
+
+        # A pointer to the previous first buffer
+        # (used to prolong the life of _buf0 when using
+        # methods like _try_read_bytes)
+        bytes _buf0_prev
+
+        # Number of buffers in `_bufs`
+        int32_t _bufs_len
+
+        # A read position in the first buffer in `_bufs`
+        ssize_t _pos0
+
+        # Length of the first buffer in `_bufs`
+        ssize_t _len0
+
+        # A total number of buffered bytes in ReadBuffer
+        ssize_t _length
+
+        char _current_message_type
+        int32_t _current_message_len
+        ssize_t _current_message_len_unread
+        bint _current_message_ready
+
+    cdef inline len(self):
+        return self._length
+
+    cdef inline char get_message_type(self):
+        return self._current_message_type
+
+    cdef inline int32_t get_message_length(self):
+        return self._current_message_len
+
+    cdef inline read_utf8(self):
+        return self.read_cstr().decode('utf-8')
+
+    cdef feed_data(self, data)
+    cdef inline _ensure_first_buf(self)
+    cdef _switch_to_next_buf(self)
+    cdef inline char read_byte(self) except? -1
+    cdef inline const char* _try_read_bytes(self, ssize_t nbytes)
+    cdef inline _read_into(self, char *buf, ssize_t nbytes)
+    cdef inline _read_and_discard(self, ssize_t nbytes)
+    cdef bytes read_bytes(self, ssize_t nbytes)
+    cdef inline int32_t read_int32(self) except? -1
+    cdef inline int16_t read_int16(self) except? -1
+    cdef inline read_cstr(self)
+    cdef int32_t take_message(self) except -1
+    cdef inline int32_t take_message_type(self, char mtype) except -1
+    cdef int32_t put_message(self) except -1
+    cdef inline const char* try_consume_message(self, ssize_t* len)
+    cdef bytes consume_message(self)
+    cdef discard_message(self)
+    cdef redirect_messages(self, WriteBuffer buf, char mtype)
+    cdef bytearray consume_messages(self, char mtype)
+    cdef finish_message(self)
+    cdef inline _finish_message(self)
+
+    @staticmethod
+    cdef ReadBuffer new_message_parser(object data)
diff --git a/asyncpg/pgproto/buffer.pyx b/asyncpg/pgproto/buffer.pyx
new file mode 100644 (file)
index 0000000..4d4f04c
--- /dev/null
@@ -0,0 +1,705 @@
+# 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
+
+
+from libc.string cimport memcpy
+
+import collections
+
+from . import exceptions
+
+
+@cython.no_gc_clear
+@cython.final
+@cython.freelist(_BUFFER_FREELIST_SIZE)
+cdef class WriteBuffer:
+
+    def __cinit__(self):
+        self._smallbuf_inuse = True
+        self._buf = self._smallbuf
+        self._size = _BUFFER_INITIAL_SIZE
+        self._length = 0
+        self._message_mode = 0
+
+    def __dealloc__(self):
+        if self._buf is not NULL and not self._smallbuf_inuse:
+            cpython.PyMem_Free(self._buf)
+            self._buf = NULL
+            self._size = 0
+
+        if self._view_count:
+            raise exceptions.BufferError(
+                'Deallocating buffer with attached memoryviews')
+
+    def __getbuffer__(self, Py_buffer *buffer, int flags):
+        self._view_count += 1
+
+        cpython.PyBuffer_FillInfo(
+            buffer, self, self._buf, self._length,
+            1,  # read-only
+            flags)
+
+    def __releasebuffer__(self, Py_buffer *buffer):
+        self._view_count -= 1
+
+    cdef inline _check_readonly(self):
+        if self._view_count:
+            raise exceptions.BufferError('the buffer is in read-only mode')
+
+    cdef inline _ensure_alloced(self, ssize_t extra_length):
+        cdef ssize_t new_size = extra_length + self._length
+
+        if new_size > self._size:
+            self._reallocate(new_size)
+
+    cdef _reallocate(self, ssize_t new_size):
+        cdef char *new_buf
+
+        if new_size < _BUFFER_MAX_GROW:
+            new_size = _BUFFER_MAX_GROW
+        else:
+            # Add a little extra
+            new_size += _BUFFER_INITIAL_SIZE
+
+        if self._smallbuf_inuse:
+            new_buf = <char*>cpython.PyMem_Malloc(
+                sizeof(char) * <size_t>new_size)
+            if new_buf is NULL:
+                self._buf = NULL
+                self._size = 0
+                self._length = 0
+                raise MemoryError
+            memcpy(new_buf, self._buf, <size_t>self._size)
+            self._size = new_size
+            self._buf = new_buf
+            self._smallbuf_inuse = False
+        else:
+            new_buf = <char*>cpython.PyMem_Realloc(
+                <void*>self._buf, <size_t>new_size)
+            if new_buf is NULL:
+                cpython.PyMem_Free(self._buf)
+                self._buf = NULL
+                self._size = 0
+                self._length = 0
+                raise MemoryError
+            self._buf = new_buf
+            self._size = new_size
+
+    cdef inline start_message(self, char type):
+        if self._length != 0:
+            raise exceptions.BufferError(
+                'cannot start_message for a non-empty buffer')
+        self._ensure_alloced(5)
+        self._message_mode = 1
+        self._buf[0] = type
+        self._length = 5
+
+    cdef inline end_message(self):
+        # "length-1" to exclude the message type byte
+        cdef ssize_t mlen = self._length - 1
+
+        self._check_readonly()
+        if not self._message_mode:
+            raise exceptions.BufferError(
+                'end_message can only be called with start_message')
+        if self._length < 5:
+            raise exceptions.BufferError('end_message: buffer is too small')
+        if mlen > _MAXINT32:
+            raise exceptions.BufferError('end_message: message is too large')
+
+        hton.pack_int32(&self._buf[1], <int32_t>mlen)
+        return self
+
+    cdef write_buffer(self, WriteBuffer buf):
+        self._check_readonly()
+
+        if not buf._length:
+            return
+
+        self._ensure_alloced(buf._length)
+        memcpy(self._buf + self._length,
+               <void*>buf._buf,
+               <size_t>buf._length)
+        self._length += buf._length
+
+    cdef write_byte(self, char b):
+        self._check_readonly()
+
+        self._ensure_alloced(1)
+        self._buf[self._length] = b
+        self._length += 1
+
+    cdef write_bytes(self, bytes data):
+        cdef char* buf
+        cdef ssize_t len
+
+        cpython.PyBytes_AsStringAndSize(data, &buf, &len)
+        self.write_cstr(buf, len)
+
+    cdef write_bytestring(self, bytes string):
+        cdef char* buf
+        cdef ssize_t len
+
+        cpython.PyBytes_AsStringAndSize(string, &buf, &len)
+        # PyBytes_AsStringAndSize returns a null-terminated buffer,
+        # but the null byte is not counted in len. hence the + 1
+        self.write_cstr(buf, len + 1)
+
+    cdef write_str(self, str string, str encoding):
+        self.write_bytestring(string.encode(encoding))
+
+    cdef write_utf8(self, str string):
+        self.write_bytestring(string.encode('utf-8'))
+
+    cdef write_cstr(self, const char *data, ssize_t len):
+        self._check_readonly()
+        self._ensure_alloced(len)
+
+        memcpy(self._buf + self._length, <void*>data, <size_t>len)
+        self._length += len
+
+    cdef write_int16(self, int16_t i):
+        self._check_readonly()
+        self._ensure_alloced(2)
+
+        hton.pack_int16(&self._buf[self._length], i)
+        self._length += 2
+
+    cdef write_int32(self, int32_t i):
+        self._check_readonly()
+        self._ensure_alloced(4)
+
+        hton.pack_int32(&self._buf[self._length], i)
+        self._length += 4
+
+    cdef write_int64(self, int64_t i):
+        self._check_readonly()
+        self._ensure_alloced(8)
+
+        hton.pack_int64(&self._buf[self._length], i)
+        self._length += 8
+
+    cdef write_float(self, float f):
+        self._check_readonly()
+        self._ensure_alloced(4)
+
+        hton.pack_float(&self._buf[self._length], f)
+        self._length += 4
+
+    cdef write_double(self, double d):
+        self._check_readonly()
+        self._ensure_alloced(8)
+
+        hton.pack_double(&self._buf[self._length], d)
+        self._length += 8
+
+    @staticmethod
+    cdef WriteBuffer new_message(char type):
+        cdef WriteBuffer buf
+        buf = WriteBuffer.__new__(WriteBuffer)
+        buf.start_message(type)
+        return buf
+
+    @staticmethod
+    cdef WriteBuffer new():
+        cdef WriteBuffer buf
+        buf = WriteBuffer.__new__(WriteBuffer)
+        return buf
+
+
+@cython.no_gc_clear
+@cython.final
+@cython.freelist(_BUFFER_FREELIST_SIZE)
+cdef class ReadBuffer:
+
+    def __cinit__(self):
+        self._bufs = collections.deque()
+        self._bufs_append = self._bufs.append
+        self._bufs_popleft = self._bufs.popleft
+        self._bufs_len = 0
+        self._buf0 = None
+        self._buf0_prev = None
+        self._pos0 = 0
+        self._len0 = 0
+        self._length = 0
+
+        self._current_message_type = 0
+        self._current_message_len = 0
+        self._current_message_len_unread = 0
+        self._current_message_ready = 0
+
+    cdef feed_data(self, data):
+        cdef:
+            ssize_t dlen
+            bytes data_bytes
+
+        if not cpython.PyBytes_CheckExact(data):
+            raise exceptions.BufferError('feed_data: bytes object expected')
+        data_bytes = <bytes>data
+
+        dlen = cpython.Py_SIZE(data_bytes)
+        if dlen == 0:
+            # EOF?
+            return
+
+        self._bufs_append(data_bytes)
+        self._length += dlen
+
+        if self._bufs_len == 0:
+            # First buffer
+            self._len0 = dlen
+            self._buf0 = data_bytes
+
+        self._bufs_len += 1
+
+    cdef inline _ensure_first_buf(self):
+        if self._len0 == 0:
+            raise exceptions.BufferError('empty first buffer')
+
+        if self._pos0 == self._len0:
+            self._switch_to_next_buf()
+
+    cdef _switch_to_next_buf(self):
+        # The first buffer is fully read, discard it
+        self._bufs_popleft()
+        self._bufs_len -= 1
+
+        # Shouldn't fail, since we've checked that `_length >= 1`
+        # in _ensure_first_buf()
+        self._buf0_prev = self._buf0
+        self._buf0 = <bytes>self._bufs[0]
+
+        self._pos0 = 0
+        self._len0 = len(self._buf0)
+
+        if PG_DEBUG:
+            if self._len0 < 1:
+                raise exceptions.BufferError(
+                    'debug: second buffer of ReadBuffer is empty')
+
+    cdef inline const char* _try_read_bytes(self, ssize_t nbytes):
+        # Try to read *nbytes* from the first buffer.
+        #
+        # Returns pointer to data if there is at least *nbytes*
+        # in the buffer, NULL otherwise.
+        #
+        # Important: caller must call _ensure_first_buf() prior
+        # to calling try_read_bytes, and must not overread
+
+        cdef:
+            const char *result
+
+        if PG_DEBUG:
+            if nbytes > self._length:
+                return NULL
+
+        if self._current_message_ready:
+            if self._current_message_len_unread < nbytes:
+                return NULL
+
+        if self._pos0 + nbytes <= self._len0:
+            result = cpython.PyBytes_AS_STRING(self._buf0)
+            result += self._pos0
+            self._pos0 += nbytes
+            self._length -= nbytes
+            if self._current_message_ready:
+                self._current_message_len_unread -= nbytes
+            return result
+        else:
+            return NULL
+
+    cdef inline _read_into(self, char *buf, ssize_t nbytes):
+        cdef:
+            ssize_t nread
+            char *buf0
+
+        while True:
+            buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+
+            if self._pos0 + nbytes > self._len0:
+                nread = self._len0 - self._pos0
+                memcpy(buf, buf0 + self._pos0, <size_t>nread)
+                self._pos0 = self._len0
+                self._length -= nread
+                nbytes -= nread
+                buf += nread
+                self._ensure_first_buf()
+
+            else:
+                memcpy(buf, buf0 + self._pos0, <size_t>nbytes)
+                self._pos0 += nbytes
+                self._length -= nbytes
+                break
+
+    cdef inline _read_and_discard(self, ssize_t nbytes):
+        cdef:
+            ssize_t nread
+
+        self._ensure_first_buf()
+        while True:
+            if self._pos0 + nbytes > self._len0:
+                nread = self._len0 - self._pos0
+                self._pos0 = self._len0
+                self._length -= nread
+                nbytes -= nread
+                self._ensure_first_buf()
+
+            else:
+                self._pos0 += nbytes
+                self._length -= nbytes
+                break
+
+    cdef bytes read_bytes(self, ssize_t nbytes):
+        cdef:
+            bytes result
+            ssize_t nread
+            const char *cbuf
+            char *buf
+
+        self._ensure_first_buf()
+        cbuf = self._try_read_bytes(nbytes)
+        if cbuf != NULL:
+            return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
+
+        if nbytes > self._length:
+            raise exceptions.BufferError(
+                'not enough data to read {} bytes'.format(nbytes))
+
+        if self._current_message_ready:
+            self._current_message_len_unread -= nbytes
+            if self._current_message_len_unread < 0:
+                raise exceptions.BufferError('buffer overread')
+
+        result = cpython.PyBytes_FromStringAndSize(NULL, nbytes)
+        buf = cpython.PyBytes_AS_STRING(result)
+        self._read_into(buf, nbytes)
+        return result
+
+    cdef inline char read_byte(self) except? -1:
+        cdef const char *first_byte
+
+        if PG_DEBUG:
+            if not self._buf0:
+                raise exceptions.BufferError(
+                    'debug: first buffer of ReadBuffer is empty')
+
+        self._ensure_first_buf()
+        first_byte = self._try_read_bytes(1)
+        if first_byte is NULL:
+            raise exceptions.BufferError('not enough data to read one byte')
+
+        return first_byte[0]
+
+    cdef inline int32_t read_int32(self) except? -1:
+        cdef:
+            bytes mem
+            const char *cbuf
+
+        self._ensure_first_buf()
+        cbuf = self._try_read_bytes(4)
+        if cbuf != NULL:
+            return hton.unpack_int32(cbuf)
+        else:
+            mem = self.read_bytes(4)
+            return hton.unpack_int32(cpython.PyBytes_AS_STRING(mem))
+
+    cdef inline int16_t read_int16(self) except? -1:
+        cdef:
+            bytes mem
+            const char *cbuf
+
+        self._ensure_first_buf()
+        cbuf = self._try_read_bytes(2)
+        if cbuf != NULL:
+            return hton.unpack_int16(cbuf)
+        else:
+            mem = self.read_bytes(2)
+            return hton.unpack_int16(cpython.PyBytes_AS_STRING(mem))
+
+    cdef inline read_cstr(self):
+        if not self._current_message_ready:
+            raise exceptions.BufferError(
+                'read_cstr only works when the message guaranteed '
+                'to be in the buffer')
+
+        cdef:
+            ssize_t pos
+            ssize_t nread
+            bytes result
+            const char *buf
+            const char *buf_start
+
+        self._ensure_first_buf()
+
+        buf_start = cpython.PyBytes_AS_STRING(self._buf0)
+        buf = buf_start + self._pos0
+        while buf - buf_start < self._len0:
+            if buf[0] == 0:
+                pos = buf - buf_start
+                nread = pos - self._pos0
+                buf = self._try_read_bytes(nread + 1)
+                if buf != NULL:
+                    return cpython.PyBytes_FromStringAndSize(buf, nread)
+                else:
+                    break
+            else:
+                buf += 1
+
+        result = b''
+        while True:
+            pos = self._buf0.find(b'\x00', self._pos0)
+            if pos >= 0:
+                result += self._buf0[self._pos0 : pos]
+                nread = pos - self._pos0 + 1
+                self._pos0 = pos + 1
+                self._length -= nread
+
+                self._current_message_len_unread -= nread
+                if self._current_message_len_unread < 0:
+                    raise exceptions.BufferError('read_cstr: buffer overread')
+
+                return result
+
+            else:
+                result += self._buf0[self._pos0:]
+                nread = self._len0 - self._pos0
+                self._pos0 = self._len0
+                self._length -= nread
+
+                self._current_message_len_unread -= nread
+                if self._current_message_len_unread < 0:
+                    raise exceptions.BufferError('read_cstr: buffer overread')
+
+                self._ensure_first_buf()
+
+    cdef int32_t take_message(self) except -1:
+        cdef:
+            const char *cbuf
+
+        if self._current_message_ready:
+            return 1
+
+        if self._current_message_type == 0:
+            if self._length < 1:
+                return 0
+            self._ensure_first_buf()
+            cbuf = self._try_read_bytes(1)
+            if cbuf == NULL:
+                raise exceptions.BufferError(
+                    'failed to read one byte on a non-empty buffer')
+            self._current_message_type = cbuf[0]
+
+        if self._current_message_len == 0:
+            if self._length < 4:
+                return 0
+
+            self._ensure_first_buf()
+            cbuf = self._try_read_bytes(4)
+            if cbuf != NULL:
+                self._current_message_len = hton.unpack_int32(cbuf)
+            else:
+                self._current_message_len = self.read_int32()
+
+            self._current_message_len_unread = self._current_message_len - 4
+
+        if self._length < self._current_message_len_unread:
+            return 0
+
+        self._current_message_ready = 1
+        return 1
+
+    cdef inline int32_t take_message_type(self, char mtype) except -1:
+        cdef const char *buf0
+
+        if self._current_message_ready:
+            return self._current_message_type == mtype
+        elif self._length >= 1:
+            self._ensure_first_buf()
+            buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+
+            return buf0[self._pos0] == mtype and self.take_message()
+        else:
+            return 0
+
+    cdef int32_t put_message(self) except -1:
+        if not self._current_message_ready:
+            raise exceptions.BufferError(
+                'cannot put message: no message taken')
+        self._current_message_ready = False
+        return 0
+
+    cdef inline const char* try_consume_message(self, ssize_t* len):
+        cdef:
+            ssize_t buf_len
+            const char *buf
+
+        if not self._current_message_ready:
+            return NULL
+
+        self._ensure_first_buf()
+        buf_len = self._current_message_len_unread
+        buf = self._try_read_bytes(buf_len)
+        if buf != NULL:
+            len[0] = buf_len
+            self._finish_message()
+        return buf
+
+    cdef discard_message(self):
+        if not self._current_message_ready:
+            raise exceptions.BufferError('no message to discard')
+        if self._current_message_len_unread > 0:
+            self._read_and_discard(self._current_message_len_unread)
+            self._current_message_len_unread = 0
+        self._finish_message()
+
+    cdef bytes consume_message(self):
+        if not self._current_message_ready:
+            raise exceptions.BufferError('no message to consume')
+        if self._current_message_len_unread > 0:
+            mem = self.read_bytes(self._current_message_len_unread)
+        else:
+            mem = b''
+        self._finish_message()
+        return mem
+
+    cdef redirect_messages(self, WriteBuffer buf, char mtype):
+        if not self._current_message_ready:
+            raise exceptions.BufferError(
+                'consume_full_messages called on a buffer without a '
+                'complete first message')
+        if mtype != self._current_message_type:
+            raise exceptions.BufferError(
+                'consume_full_messages called with a wrong mtype')
+        if self._current_message_len_unread != self._current_message_len - 4:
+            raise exceptions.BufferError(
+                'consume_full_messages called on a partially read message')
+
+        cdef:
+            const char* cbuf
+            ssize_t cbuf_len
+            int32_t msg_len
+            ssize_t new_pos0
+            ssize_t pos_delta
+            int32_t done
+
+        while True:
+            buf.write_byte(mtype)
+            buf.write_int32(self._current_message_len)
+
+            cbuf = self.try_consume_message(&cbuf_len)
+            if cbuf != NULL:
+                buf.write_cstr(cbuf, cbuf_len)
+            else:
+                buf.write_bytes(self.consume_message())
+
+            # Fast path: exhaust buf0 as efficiently as possible.
+            self._ensure_first_buf()
+            if self._pos0 + 5 <= self._len0:
+                cbuf = cpython.PyBytes_AS_STRING(self._buf0)
+                new_pos0 = self._pos0
+                cbuf_len = self._len0
+
+                done = 0
+                # Scan the first buffer and find the position of the
+                # end of the last "mtype" message.
+                while new_pos0 + 5 <= cbuf_len:
+                    if (cbuf + new_pos0)[0] != mtype:
+                        done = 1
+                        break
+                    msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1
+                    if new_pos0 + msg_len > cbuf_len:
+                        break
+                    new_pos0 += msg_len
+
+                if new_pos0 != self._pos0:
+                    if PG_DEBUG:
+                        assert self._pos0 < new_pos0 <= self._len0
+
+                    pos_delta = new_pos0 - self._pos0
+                    buf.write_cstr(
+                        cbuf + self._pos0,
+                        pos_delta)
+
+                    self._pos0 = new_pos0
+                    self._length -= pos_delta
+
+                    if PG_DEBUG:
+                        assert self._length >= 0
+
+                if done:
+                    # The next message is of a different type.
+                    return
+
+            # Back to slow path.
+            if not self.take_message_type(mtype):
+                return
+
+    cdef bytearray consume_messages(self, char mtype):
+        """Consume consecutive messages of the same type."""
+        cdef:
+            char *buf
+            ssize_t nbytes
+            ssize_t total_bytes = 0
+            bytearray result
+
+        if not self.take_message_type(mtype):
+            return None
+
+        # consume_messages is a volume-oriented method, so
+        # we assume that the remainder of the buffer will contain
+        # messages of the requested type.
+        result = cpythonx.PyByteArray_FromStringAndSize(NULL, self._length)
+        buf = cpythonx.PyByteArray_AsString(result)
+
+        while self.take_message_type(mtype):
+            self._ensure_first_buf()
+            nbytes = self._current_message_len_unread
+            self._read_into(buf, nbytes)
+            buf += nbytes
+            total_bytes += nbytes
+            self._finish_message()
+
+        # Clamp the result to an actual size read.
+        cpythonx.PyByteArray_Resize(result, total_bytes)
+
+        return result
+
+    cdef finish_message(self):
+        if self._current_message_type == 0 or not self._current_message_ready:
+            # The message has already been finished (e.g by consume_message()),
+            # or has been put back by put_message().
+            return
+
+        if self._current_message_len_unread:
+            if PG_DEBUG:
+                mtype = chr(self._current_message_type)
+
+            discarded = self.consume_message()
+
+            if PG_DEBUG:
+                print('!!! discarding message {!r} unread data: {!r}'.format(
+                    mtype,
+                    discarded))
+
+        self._finish_message()
+
+    cdef inline _finish_message(self):
+        self._current_message_type = 0
+        self._current_message_len = 0
+        self._current_message_ready = 0
+        self._current_message_len_unread = 0
+
+    @staticmethod
+    cdef ReadBuffer new_message_parser(object data):
+        cdef ReadBuffer buf
+
+        buf = ReadBuffer.__new__(ReadBuffer)
+        buf.feed_data(data)
+
+        buf._current_message_ready = 1
+        buf._current_message_len_unread = buf._len0
+
+        return buf
diff --git a/asyncpg/pgproto/codecs/__init__.pxd b/asyncpg/pgproto/codecs/__init__.pxd
new file mode 100644 (file)
index 0000000..8dd49b8
--- /dev/null
@@ -0,0 +1,143 @@
+# 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 class CodecContext:
+
+    cpdef get_text_codec(self)
+    cdef is_encoding_utf8(self)
+
+
+ctypedef object (*encode_func)(CodecContext settings,
+                               WriteBuffer buf,
+                               object obj)
+
+ctypedef object (*decode_func)(CodecContext settings,
+                               FRBuffer *buf)
+
+
+# Datetime
+cdef date_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef date_decode(CodecContext settings, FRBuffer * buf)
+cdef date_encode_tuple(CodecContext settings, WriteBuffer buf, obj)
+cdef date_decode_tuple(CodecContext settings, FRBuffer * buf)
+cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef timestamp_decode(CodecContext settings, FRBuffer * buf)
+cdef timestamp_encode_tuple(CodecContext settings, WriteBuffer buf, obj)
+cdef timestamp_decode_tuple(CodecContext settings, FRBuffer * buf)
+cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef timestamptz_decode(CodecContext settings, FRBuffer * buf)
+cdef time_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef time_decode(CodecContext settings, FRBuffer * buf)
+cdef time_encode_tuple(CodecContext settings, WriteBuffer buf, obj)
+cdef time_decode_tuple(CodecContext settings, FRBuffer * buf)
+cdef timetz_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef timetz_decode(CodecContext settings, FRBuffer * buf)
+cdef timetz_encode_tuple(CodecContext settings, WriteBuffer buf, obj)
+cdef timetz_decode_tuple(CodecContext settings, FRBuffer * buf)
+cdef interval_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef interval_decode(CodecContext settings, FRBuffer * buf)
+cdef interval_encode_tuple(CodecContext settings, WriteBuffer buf, tuple obj)
+cdef interval_decode_tuple(CodecContext settings, FRBuffer * buf)
+
+
+# Bits
+cdef bits_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef bits_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Bools
+cdef bool_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef bool_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Geometry
+cdef box_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef box_decode(CodecContext settings, FRBuffer * buf)
+cdef line_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef line_decode(CodecContext settings, FRBuffer * buf)
+cdef lseg_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef lseg_decode(CodecContext settings, FRBuffer * buf)
+cdef point_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef point_decode(CodecContext settings, FRBuffer * buf)
+cdef path_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef path_decode(CodecContext settings, FRBuffer * buf)
+cdef poly_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef poly_decode(CodecContext settings, FRBuffer * buf)
+cdef circle_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef circle_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Hstore
+cdef hstore_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef hstore_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Ints
+cdef int2_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef int2_decode(CodecContext settings, FRBuffer * buf)
+cdef int4_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef int4_decode(CodecContext settings, FRBuffer * buf)
+cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef uint4_decode(CodecContext settings, FRBuffer * buf)
+cdef int8_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef int8_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Floats
+cdef float4_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef float4_decode(CodecContext settings, FRBuffer * buf)
+cdef float8_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef float8_decode(CodecContext settings, FRBuffer * buf)
+
+
+# JSON
+cdef jsonb_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef jsonb_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Text
+cdef as_pg_string_and_size(
+        CodecContext settings, obj, char **cstr, ssize_t *size)
+cdef text_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef text_decode(CodecContext settings, FRBuffer * buf)
+
+# Bytea
+cdef bytea_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef bytea_decode(CodecContext settings, FRBuffer * buf)
+
+
+# UUID
+cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj)
+cdef uuid_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Numeric
+cdef numeric_encode_text(CodecContext settings, WriteBuffer buf, obj)
+cdef numeric_decode_text(CodecContext settings, FRBuffer * buf)
+cdef numeric_encode_binary(CodecContext settings, WriteBuffer buf, obj)
+cdef numeric_decode_binary(CodecContext settings, FRBuffer * buf)
+
+
+# Void
+cdef void_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef void_decode(CodecContext settings, FRBuffer * buf)
+
+
+# tid
+cdef tid_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef tid_decode(CodecContext settings, FRBuffer * buf)
+
+
+# Network
+cdef net_decode(CodecContext settings, FRBuffer * buf)
+cdef cidr_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef inet_encode(CodecContext settings, WriteBuffer buf, obj)
+
+
+# txid
+cdef txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj)
+cdef txid_snapshot_decode(CodecContext settings, FRBuffer * buf)
diff --git a/asyncpg/pgproto/codecs/bits.pyx b/asyncpg/pgproto/codecs/bits.pyx
new file mode 100644 (file)
index 0000000..14f7bb0
--- /dev/null
@@ -0,0 +1,47 @@
+# 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 bits_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    cdef:
+        Py_buffer pybuf
+        bint pybuf_used = False
+        char *buf
+        ssize_t len
+        ssize_t bitlen
+
+    if cpython.PyBytes_CheckExact(obj):
+        buf = cpython.PyBytes_AS_STRING(obj)
+        len = cpython.Py_SIZE(obj)
+        bitlen = len * 8
+    elif isinstance(obj, pgproto_types.BitString):
+        cpython.PyBytes_AsStringAndSize(obj.bytes, &buf, &len)
+        bitlen = obj.__len__()
+    else:
+        cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+        pybuf_used = True
+        buf = <char*>pybuf.buf
+        len = pybuf.len
+        bitlen = len * 8
+
+    try:
+        if bitlen > _MAXINT32:
+            raise ValueError('bit value too long')
+        wbuf.write_int32(4 + <int32_t>len)
+        wbuf.write_int32(<int32_t>bitlen)
+        wbuf.write_cstr(buf, len)
+    finally:
+        if pybuf_used:
+            cpython.PyBuffer_Release(&pybuf)
+
+
+cdef bits_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int32_t bitlen = hton.unpack_int32(frb_read(buf, 4))
+        ssize_t buf_len = buf.len
+
+    bytes_ = cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)
+    return pgproto_types.BitString.frombytes(bytes_, bitlen)
diff --git a/asyncpg/pgproto/codecs/bytea.pyx b/asyncpg/pgproto/codecs/bytea.pyx
new file mode 100644 (file)
index 0000000..1581825
--- /dev/null
@@ -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)
diff --git a/asyncpg/pgproto/codecs/context.pyx b/asyncpg/pgproto/codecs/context.pyx
new file mode 100644 (file)
index 0000000..7df5b23
--- /dev/null
@@ -0,0 +1,14 @@
+# 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 class CodecContext:
+
+    cpdef get_text_codec(self):
+        raise NotImplementedError
+
+    cdef is_encoding_utf8(self):
+        raise NotImplementedError
diff --git a/asyncpg/pgproto/codecs/datetime.pyx b/asyncpg/pgproto/codecs/datetime.pyx
new file mode 100644 (file)
index 0000000..9dd1c95
--- /dev/null
@@ -0,0 +1,428 @@
+# 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
+
+
+cimport cpython.datetime
+import datetime
+
+cpython.datetime.import_datetime()
+
+utc = datetime.timezone.utc
+date_from_ordinal = datetime.date.fromordinal
+timedelta = datetime.timedelta
+
+pg_epoch_datetime = datetime.datetime(2000, 1, 1)
+cdef int32_t pg_epoch_datetime_ts = \
+    <int32_t>cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))
+
+pg_epoch_datetime_utc = datetime.datetime(2000, 1, 1, tzinfo=utc)
+cdef int32_t pg_epoch_datetime_utc_ts = \
+    <int32_t>cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())
+
+pg_epoch_date = datetime.date(2000, 1, 1)
+cdef int32_t pg_date_offset_ord = \
+    <int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())
+
+# Binary representations of infinity for datetimes.
+cdef int64_t pg_time64_infinity = 0x7fffffffffffffff
+cdef int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
+cdef int32_t pg_date_infinity = 0x7fffffff
+cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000
+
+infinity_datetime = datetime.datetime(
+    datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
+
+cdef int32_t infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(
+    infinity_datetime.toordinal())
+
+cdef int64_t infinity_datetime_ts = 252455615999999999
+
+negative_infinity_datetime = datetime.datetime(
+    datetime.MINYEAR, 1, 1, 0, 0, 0, 0)
+
+cdef int32_t negative_infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(
+    negative_infinity_datetime.toordinal())
+
+cdef int64_t negative_infinity_datetime_ts = -63082281600000000
+
+infinity_date = datetime.date(datetime.MAXYEAR, 12, 31)
+
+cdef int32_t infinity_date_ord = <int32_t>cpython.PyLong_AsLong(
+    infinity_date.toordinal())
+
+negative_infinity_date = datetime.date(datetime.MINYEAR, 1, 1)
+
+cdef int32_t negative_infinity_date_ord = <int32_t>cpython.PyLong_AsLong(
+    negative_infinity_date.toordinal())
+
+
+cdef inline _local_timezone():
+    d = datetime.datetime.now(datetime.timezone.utc).astimezone()
+    return datetime.timezone(d.utcoffset())
+
+
+cdef inline _encode_time(WriteBuffer buf, int64_t seconds,
+                         int32_t microseconds):
+    # XXX: add support for double timestamps
+    # int64 timestamps,
+    cdef int64_t ts = seconds * 1000000 + microseconds
+
+    if ts == infinity_datetime_ts:
+        buf.write_int64(pg_time64_infinity)
+    elif ts == negative_infinity_datetime_ts:
+        buf.write_int64(pg_time64_negative_infinity)
+    else:
+        buf.write_int64(ts)
+
+
+cdef inline int32_t _decode_time(FRBuffer *buf, int64_t *seconds,
+                                 int32_t *microseconds):
+    cdef int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+
+    if ts == pg_time64_infinity:
+        return 1
+    elif ts == pg_time64_negative_infinity:
+        return -1
+    else:
+        seconds[0] = ts // 1000000
+        microseconds[0] = <int32_t>(ts % 1000000)
+        return 0
+
+
+cdef date_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int32_t ordinal = <int32_t>cpython.PyLong_AsLong(obj.toordinal())
+        int32_t pg_ordinal
+
+    if ordinal == infinity_date_ord:
+        pg_ordinal = pg_date_infinity
+    elif ordinal == negative_infinity_date_ord:
+        pg_ordinal = pg_date_negative_infinity
+    else:
+        pg_ordinal = ordinal - pg_date_offset_ord
+
+    buf.write_int32(4)
+    buf.write_int32(pg_ordinal)
+
+
+cdef date_encode_tuple(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int32_t pg_ordinal
+
+    if len(obj) != 1:
+        raise ValueError(
+            'date tuple encoder: expecting 1 element '
+            'in tuple, got {}'.format(len(obj)))
+
+    pg_ordinal = obj[0]
+    buf.write_int32(4)
+    buf.write_int32(pg_ordinal)
+
+
+cdef date_decode(CodecContext settings, FRBuffer *buf):
+    cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+
+    if pg_ordinal == pg_date_infinity:
+        return infinity_date
+    elif pg_ordinal == pg_date_negative_infinity:
+        return negative_infinity_date
+    else:
+        return date_from_ordinal(pg_ordinal + pg_date_offset_ord)
+
+
+cdef date_decode_tuple(CodecContext settings, FRBuffer *buf):
+    cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+
+    return (pg_ordinal,)
+
+
+cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):
+    if not cpython.datetime.PyDateTime_Check(obj):
+        if cpython.datetime.PyDate_Check(obj):
+            obj = datetime.datetime(obj.year, obj.month, obj.day)
+        else:
+            raise TypeError(
+                'expected a datetime.date or datetime.datetime instance, '
+                'got {!r}'.format(type(obj).__name__)
+            )
+
+    delta = obj - pg_epoch_datetime
+    cdef:
+        int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+                                cpython.PyLong_AsLong(delta.seconds)
+        int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+                                    delta.microseconds)
+
+    buf.write_int32(8)
+    _encode_time(buf, seconds, microseconds)
+
+
+cdef timestamp_encode_tuple(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int64_t microseconds
+
+    if len(obj) != 1:
+        raise ValueError(
+            'timestamp tuple encoder: expecting 1 element '
+            'in tuple, got {}'.format(len(obj)))
+
+    microseconds = obj[0]
+
+    buf.write_int32(8)
+    buf.write_int64(microseconds)
+
+
+cdef timestamp_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int64_t seconds = 0
+        int32_t microseconds = 0
+        int32_t inf = _decode_time(buf, &seconds, &microseconds)
+
+    if inf > 0:
+        # positive infinity
+        return infinity_datetime
+    elif inf < 0:
+        # negative infinity
+        return negative_infinity_datetime
+    else:
+        return pg_epoch_datetime.__add__(
+            timedelta(0, seconds, microseconds))
+
+
+cdef timestamp_decode_tuple(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+
+    return (ts,)
+
+
+cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):
+    if not cpython.datetime.PyDateTime_Check(obj):
+        if cpython.datetime.PyDate_Check(obj):
+            obj = datetime.datetime(obj.year, obj.month, obj.day,
+                                    tzinfo=_local_timezone())
+        else:
+            raise TypeError(
+                'expected a datetime.date or datetime.datetime instance, '
+                'got {!r}'.format(type(obj).__name__)
+            )
+
+    buf.write_int32(8)
+
+    if obj == infinity_datetime:
+        buf.write_int64(pg_time64_infinity)
+        return
+    elif obj == negative_infinity_datetime:
+        buf.write_int64(pg_time64_negative_infinity)
+        return
+
+    try:
+        utc_dt = obj.astimezone(utc)
+    except ValueError:
+        # Python 3.5 doesn't like it when we call astimezone()
+        # on naive datetime objects, so make it aware.
+        utc_dt = obj.replace(tzinfo=_local_timezone()).astimezone(utc)
+
+    delta = utc_dt - pg_epoch_datetime_utc
+    cdef:
+        int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+                                cpython.PyLong_AsLong(delta.seconds)
+        int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+                                    delta.microseconds)
+
+    _encode_time(buf, seconds, microseconds)
+
+
+cdef timestamptz_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int64_t seconds = 0
+        int32_t microseconds = 0
+        int32_t inf = _decode_time(buf, &seconds, &microseconds)
+
+    if inf > 0:
+        # positive infinity
+        return infinity_datetime
+    elif inf < 0:
+        # negative infinity
+        return negative_infinity_datetime
+    else:
+        return pg_epoch_datetime_utc.__add__(
+            timedelta(0, seconds, microseconds))
+
+
+cdef time_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+                            cpython.PyLong_AsLong(obj.minute) * 60 + \
+                            cpython.PyLong_AsLong(obj.second)
+        int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+
+    buf.write_int32(8)
+    _encode_time(buf, seconds, microseconds)
+
+
+cdef time_encode_tuple(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int64_t microseconds
+
+    if len(obj) != 1:
+        raise ValueError(
+            'time tuple encoder: expecting 1 element '
+            'in tuple, got {}'.format(len(obj)))
+
+    microseconds = obj[0]
+
+    buf.write_int32(8)
+    buf.write_int64(microseconds)
+
+
+cdef time_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int64_t seconds = 0
+        int32_t microseconds = 0
+
+    _decode_time(buf, &seconds, &microseconds)
+
+    cdef:
+        int64_t minutes = <int64_t>(seconds / 60)
+        int64_t sec = seconds % 60
+        int64_t hours = <int64_t>(minutes / 60)
+        int64_t min = minutes % 60
+
+    return datetime.time(hours, min, sec, microseconds)
+
+
+cdef time_decode_tuple(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+
+    return (ts,)
+
+
+cdef timetz_encode(CodecContext settings, WriteBuffer buf, obj):
+    offset = obj.tzinfo.utcoffset(None)
+
+    cdef:
+        int32_t offset_sec = \
+            <int32_t>cpython.PyLong_AsLong(offset.days) * 24 * 60 * 60 + \
+            <int32_t>cpython.PyLong_AsLong(offset.seconds)
+
+        int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+                            cpython.PyLong_AsLong(obj.minute) * 60 + \
+                            cpython.PyLong_AsLong(obj.second)
+
+        int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+
+    buf.write_int32(12)
+    _encode_time(buf, seconds, microseconds)
+    # In Python utcoffset() is the difference between the local time
+    # and the UTC, whereas in PostgreSQL it's the opposite,
+    # so we need to flip the sign.
+    buf.write_int32(-offset_sec)
+
+
+cdef timetz_encode_tuple(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int64_t microseconds
+        int32_t offset_sec
+
+    if len(obj) != 2:
+        raise ValueError(
+            'time tuple encoder: expecting 2 elements2 '
+            'in tuple, got {}'.format(len(obj)))
+
+    microseconds = obj[0]
+    offset_sec = obj[1]
+
+    buf.write_int32(12)
+    buf.write_int64(microseconds)
+    buf.write_int32(offset_sec)
+
+
+cdef timetz_decode(CodecContext settings, FRBuffer *buf):
+    time = time_decode(settings, buf)
+    cdef int32_t offset = <int32_t>(hton.unpack_int32(frb_read(buf, 4)) / 60)
+    # See the comment in the `timetz_encode` method.
+    return time.replace(tzinfo=datetime.timezone(timedelta(minutes=-offset)))
+
+
+cdef timetz_decode_tuple(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int64_t microseconds = hton.unpack_int64(frb_read(buf, 8))
+        int32_t offset_sec = hton.unpack_int32(frb_read(buf, 4))
+
+    return (microseconds, offset_sec)
+
+
+cdef interval_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        int32_t days = <int32_t>cpython.PyLong_AsLong(obj.days)
+        int64_t seconds = cpython.PyLong_AsLongLong(obj.seconds)
+        int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microseconds)
+
+    buf.write_int32(16)
+    _encode_time(buf, seconds, microseconds)
+    buf.write_int32(days)
+    buf.write_int32(0) # Months
+
+
+cdef interval_encode_tuple(CodecContext settings, WriteBuffer buf,
+                           tuple obj):
+    cdef:
+        int32_t months
+        int32_t days
+        int64_t microseconds
+
+    if len(obj) != 3:
+        raise ValueError(
+            'interval tuple encoder: expecting 3 elements '
+            'in tuple, got {}'.format(len(obj)))
+
+    months = obj[0]
+    days = obj[1]
+    microseconds = obj[2]
+
+    buf.write_int32(16)
+    buf.write_int64(microseconds)
+    buf.write_int32(days)
+    buf.write_int32(months)
+
+
+cdef interval_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int32_t days
+        int32_t months
+        int32_t years
+        int64_t seconds = 0
+        int32_t microseconds = 0
+
+    _decode_time(buf, &seconds, &microseconds)
+
+    days = hton.unpack_int32(frb_read(buf, 4))
+    months = hton.unpack_int32(frb_read(buf, 4))
+
+    if months < 0:
+        years = -<int32_t>(-months // 12)
+        months = -<int32_t>(-months % 12)
+    else:
+        years = <int32_t>(months // 12)
+        months = <int32_t>(months % 12)
+
+    return datetime.timedelta(days=days + months * 30 + years * 365,
+                              seconds=seconds, microseconds=microseconds)
+
+
+cdef interval_decode_tuple(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int32_t days
+        int32_t months
+        int64_t microseconds
+
+    microseconds = hton.unpack_int64(frb_read(buf, 8))
+    days = hton.unpack_int32(frb_read(buf, 4))
+    months = hton.unpack_int32(frb_read(buf, 4))
+
+    return (months, days, microseconds)
diff --git a/asyncpg/pgproto/codecs/float.pyx b/asyncpg/pgproto/codecs/float.pyx
new file mode 100644 (file)
index 0000000..94eda03
--- /dev/null
@@ -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
+
+
+from libc cimport math
+
+
+cdef float4_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef double dval = cpython.PyFloat_AsDouble(obj)
+    cdef float fval = <float>dval
+    if math.isinf(fval) and not math.isinf(dval):
+        raise ValueError('value out of float32 range')
+
+    buf.write_int32(4)
+    buf.write_float(fval)
+
+
+cdef float4_decode(CodecContext settings, FRBuffer *buf):
+    cdef float f = hton.unpack_float(frb_read(buf, 4))
+    return cpython.PyFloat_FromDouble(f)
+
+
+cdef float8_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef double dval = cpython.PyFloat_AsDouble(obj)
+    buf.write_int32(8)
+    buf.write_double(dval)
+
+
+cdef float8_decode(CodecContext settings, FRBuffer *buf):
+    cdef double f = hton.unpack_double(frb_read(buf, 8))
+    return cpython.PyFloat_FromDouble(f)
diff --git a/asyncpg/pgproto/codecs/geometry.pyx b/asyncpg/pgproto/codecs/geometry.pyx
new file mode 100644 (file)
index 0000000..44aac64
--- /dev/null
@@ -0,0 +1,164 @@
+# 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 inline _encode_points(WriteBuffer wbuf, object points):
+    cdef object point
+
+    for point in points:
+        wbuf.write_double(point[0])
+        wbuf.write_double(point[1])
+
+
+cdef inline _decode_points(FRBuffer *buf):
+    cdef:
+        int32_t npts = hton.unpack_int32(frb_read(buf, 4))
+        pts = cpython.PyTuple_New(npts)
+        int32_t i
+        object point
+        double x
+        double y
+
+    for i in range(npts):
+        x = hton.unpack_double(frb_read(buf, 8))
+        y = hton.unpack_double(frb_read(buf, 8))
+        point = pgproto_types.Point(x, y)
+        cpython.Py_INCREF(point)
+        cpython.PyTuple_SET_ITEM(pts, i, point)
+
+    return pts
+
+
+cdef box_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    wbuf.write_int32(32)
+    _encode_points(wbuf, (obj[0], obj[1]))
+
+
+cdef box_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        double high_x = hton.unpack_double(frb_read(buf, 8))
+        double high_y = hton.unpack_double(frb_read(buf, 8))
+        double low_x = hton.unpack_double(frb_read(buf, 8))
+        double low_y = hton.unpack_double(frb_read(buf, 8))
+
+    return pgproto_types.Box(
+        pgproto_types.Point(high_x, high_y),
+        pgproto_types.Point(low_x, low_y))
+
+
+cdef line_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    wbuf.write_int32(24)
+    wbuf.write_double(obj[0])
+    wbuf.write_double(obj[1])
+    wbuf.write_double(obj[2])
+
+
+cdef line_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        double A = hton.unpack_double(frb_read(buf, 8))
+        double B = hton.unpack_double(frb_read(buf, 8))
+        double C = hton.unpack_double(frb_read(buf, 8))
+
+    return pgproto_types.Line(A, B, C)
+
+
+cdef lseg_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    wbuf.write_int32(32)
+    _encode_points(wbuf, (obj[0], obj[1]))
+
+
+cdef lseg_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        double p1_x = hton.unpack_double(frb_read(buf, 8))
+        double p1_y = hton.unpack_double(frb_read(buf, 8))
+        double p2_x = hton.unpack_double(frb_read(buf, 8))
+        double p2_y = hton.unpack_double(frb_read(buf, 8))
+
+    return pgproto_types.LineSegment((p1_x, p1_y), (p2_x, p2_y))
+
+
+cdef point_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    wbuf.write_int32(16)
+    wbuf.write_double(obj[0])
+    wbuf.write_double(obj[1])
+
+
+cdef point_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        double x = hton.unpack_double(frb_read(buf, 8))
+        double y = hton.unpack_double(frb_read(buf, 8))
+
+    return pgproto_types.Point(x, y)
+
+
+cdef path_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    cdef:
+        int8_t is_closed = 0
+        ssize_t npts
+        ssize_t encoded_len
+        int32_t i
+
+    if cpython.PyTuple_Check(obj):
+        is_closed = 1
+    elif cpython.PyList_Check(obj):
+        is_closed = 0
+    elif isinstance(obj, pgproto_types.Path):
+        is_closed = obj.is_closed
+
+    npts = len(obj)
+    encoded_len = 1 + 4 + 16 * npts
+    if encoded_len > _MAXINT32:
+        raise ValueError('path value too long')
+
+    wbuf.write_int32(<int32_t>encoded_len)
+    wbuf.write_byte(is_closed)
+    wbuf.write_int32(<int32_t>npts)
+
+    _encode_points(wbuf, obj)
+
+
+cdef path_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int8_t is_closed = <int8_t>(frb_read(buf, 1)[0])
+
+    return pgproto_types.Path(*_decode_points(buf), is_closed=is_closed == 1)
+
+
+cdef poly_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    cdef:
+        bint is_closed
+        ssize_t npts
+        ssize_t encoded_len
+        int32_t i
+
+    npts = len(obj)
+    encoded_len = 4 + 16 * npts
+    if encoded_len > _MAXINT32:
+        raise ValueError('polygon value too long')
+
+    wbuf.write_int32(<int32_t>encoded_len)
+    wbuf.write_int32(<int32_t>npts)
+    _encode_points(wbuf, obj)
+
+
+cdef poly_decode(CodecContext settings, FRBuffer *buf):
+    return pgproto_types.Polygon(*_decode_points(buf))
+
+
+cdef circle_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    wbuf.write_int32(24)
+    wbuf.write_double(obj[0][0])
+    wbuf.write_double(obj[0][1])
+    wbuf.write_double(obj[1])
+
+
+cdef circle_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        double center_x = hton.unpack_double(frb_read(buf, 8))
+        double center_y = hton.unpack_double(frb_read(buf, 8))
+        double radius = hton.unpack_double(frb_read(buf, 8))
+
+    return pgproto_types.Circle((center_x, center_y), radius)
diff --git a/asyncpg/pgproto/codecs/hstore.pyx b/asyncpg/pgproto/codecs/hstore.pyx
new file mode 100644 (file)
index 0000000..09051c7
--- /dev/null
@@ -0,0 +1,73 @@
+# 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 hstore_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        char *str
+        ssize_t size
+        ssize_t count
+        object items
+        WriteBuffer item_buf = WriteBuffer.new()
+
+    count = len(obj)
+    if count > _MAXINT32:
+        raise ValueError('hstore value is too large')
+    item_buf.write_int32(<int32_t>count)
+
+    if hasattr(obj, 'items'):
+        items = obj.items()
+    else:
+        items = obj
+
+    for k, v in items:
+        if k is None:
+            raise ValueError('null value not allowed in hstore key')
+        as_pg_string_and_size(settings, k, &str, &size)
+        item_buf.write_int32(<int32_t>size)
+        item_buf.write_cstr(str, size)
+        if v is None:
+            item_buf.write_int32(<int32_t>-1)
+        else:
+            as_pg_string_and_size(settings, v, &str, &size)
+            item_buf.write_int32(<int32_t>size)
+            item_buf.write_cstr(str, size)
+
+    buf.write_int32(item_buf.len())
+    buf.write_buffer(item_buf)
+
+
+cdef hstore_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        dict result
+        uint32_t elem_count
+        int32_t elem_len
+        uint32_t i
+        str k
+        str v
+
+    result = {}
+
+    elem_count = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+    if elem_count == 0:
+        return result
+
+    for i in range(elem_count):
+        elem_len = hton.unpack_int32(frb_read(buf, 4))
+        if elem_len < 0:
+            raise ValueError('null value not allowed in hstore key')
+
+        k = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+
+        elem_len = hton.unpack_int32(frb_read(buf, 4))
+        if elem_len < 0:
+            v = None
+        else:
+            v = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+
+        result[k] = v
+
+    return result
diff --git a/asyncpg/pgproto/codecs/int.pyx b/asyncpg/pgproto/codecs/int.pyx
new file mode 100644 (file)
index 0000000..e4d2f87
--- /dev/null
@@ -0,0 +1,102 @@
+# 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 bool_encode(CodecContext settings, WriteBuffer buf, obj):
+    if not cpython.PyBool_Check(obj):
+        raise TypeError('a boolean is required (got type {})'.format(
+            type(obj).__name__))
+
+    buf.write_int32(1)
+    buf.write_byte(b'\x01' if obj is True else b'\x00')
+
+
+cdef bool_decode(CodecContext settings, FRBuffer *buf):
+    return frb_read(buf, 1)[0] is b'\x01'
+
+
+cdef int2_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef int overflow = 0
+    cdef long val
+
+    try:
+        val = cpython.PyLong_AsLong(obj)
+    except OverflowError:
+        overflow = 1
+
+    if overflow or val < INT16_MIN or val > INT16_MAX:
+        raise OverflowError('value out of int16 range')
+
+    buf.write_int32(2)
+    buf.write_int16(<int16_t>val)
+
+
+cdef int2_decode(CodecContext settings, FRBuffer *buf):
+    return cpython.PyLong_FromLong(hton.unpack_int16(frb_read(buf, 2)))
+
+
+cdef int4_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef int overflow = 0
+    cdef long val = 0
+
+    try:
+        val = cpython.PyLong_AsLong(obj)
+    except OverflowError:
+        overflow = 1
+
+    # "long" and "long long" have the same size for x86_64, need an extra check
+    if overflow or (sizeof(val) > 4 and (val < INT32_MIN or val > INT32_MAX)):
+        raise OverflowError('value out of int32 range')
+
+    buf.write_int32(4)
+    buf.write_int32(<int32_t>val)
+
+
+cdef int4_decode(CodecContext settings, FRBuffer *buf):
+    return cpython.PyLong_FromLong(hton.unpack_int32(frb_read(buf, 4)))
+
+
+cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef int overflow = 0
+    cdef unsigned long val = 0
+
+    try:
+        val = cpython.PyLong_AsUnsignedLong(obj)
+    except OverflowError:
+        overflow = 1
+
+    # "long" and "long long" have the same size for x86_64, need an extra check
+    if overflow or (sizeof(val) > 4 and val > UINT32_MAX):
+        raise OverflowError('value out of uint32 range')
+
+    buf.write_int32(4)
+    buf.write_int32(<int32_t>val)
+
+
+cdef uint4_decode(CodecContext settings, FRBuffer *buf):
+    return cpython.PyLong_FromUnsignedLong(
+        <uint32_t>hton.unpack_int32(frb_read(buf, 4)))
+
+
+cdef int8_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef int overflow = 0
+    cdef long long val
+
+    try:
+        val = cpython.PyLong_AsLongLong(obj)
+    except OverflowError:
+        overflow = 1
+
+    # Just in case for systems with "long long" bigger than 8 bytes
+    if overflow or (sizeof(val) > 8 and (val < INT64_MIN or val > INT64_MAX)):
+        raise OverflowError('value out of int64 range')
+
+    buf.write_int32(8)
+    buf.write_int64(<int64_t>val)
+
+
+cdef int8_decode(CodecContext settings, FRBuffer *buf):
+    return cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
diff --git a/asyncpg/pgproto/codecs/json.pyx b/asyncpg/pgproto/codecs/json.pyx
new file mode 100644 (file)
index 0000000..d1b50a0
--- /dev/null
@@ -0,0 +1,29 @@
+# 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 jsonb_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        char *str
+        ssize_t size
+
+    as_pg_string_and_size(settings, obj, &str, &size)
+
+    if size > 0x7fffffff - 1:
+        raise ValueError('string too long')
+
+    buf.write_int32(<int32_t>size + 1)
+    buf.write_byte(1)  # JSONB format version
+    buf.write_cstr(str, size)
+
+
+cdef jsonb_decode(CodecContext settings, FRBuffer *buf):
+    cdef uint8_t format = <uint8_t>(frb_read(buf, 1)[0])
+
+    if format != 1:
+        raise ValueError('unexpected JSONB format: {}'.format(format))
+
+    return text_decode(settings, buf)
diff --git a/asyncpg/pgproto/codecs/misc.pyx b/asyncpg/pgproto/codecs/misc.pyx
new file mode 100644 (file)
index 0000000..99b19c9
--- /dev/null
@@ -0,0 +1,16 @@
+# 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 void_encode(CodecContext settings, WriteBuffer buf, obj):
+    # Void is zero bytes
+    buf.write_int32(0)
+
+
+cdef void_decode(CodecContext settings, FRBuffer *buf):
+    # Do nothing; void will be passed as NULL so this function
+    # will never be called.
+    pass
diff --git a/asyncpg/pgproto/codecs/network.pyx b/asyncpg/pgproto/codecs/network.pyx
new file mode 100644 (file)
index 0000000..6c25083
--- /dev/null
@@ -0,0 +1,119 @@
+# 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
+
+
+import ipaddress
+
+
+# defined in postgresql/src/include/inet.h
+#
+DEF PGSQL_AF_INET = 2  # AF_INET
+DEF PGSQL_AF_INET6 = 3  # AF_INET + 1
+
+
+_ipaddr = ipaddress.ip_address
+_ipnet = ipaddress.ip_network
+
+
+cdef inline uint8_t _ip_max_prefix_len(int32_t family):
+    # Maximum number of bits in the network prefix of the specified
+    # IP protocol version.
+    if family == PGSQL_AF_INET:
+        return 32
+    else:
+        return 128
+
+
+cdef inline int32_t _ip_addr_len(int32_t family):
+    # Length of address in bytes for the specified IP protocol version.
+    if family == PGSQL_AF_INET:
+        return 4
+    else:
+        return 16
+
+
+cdef inline int8_t _ver_to_family(int32_t version):
+    if version == 4:
+        return PGSQL_AF_INET
+    else:
+        return PGSQL_AF_INET6
+
+
+cdef inline _net_encode(WriteBuffer buf, int8_t family, uint32_t bits,
+                        int8_t is_cidr, bytes addr):
+
+    cdef:
+        char *addrbytes
+        ssize_t addrlen
+
+    cpython.PyBytes_AsStringAndSize(addr, &addrbytes, &addrlen)
+
+    buf.write_int32(4 + <int32_t>addrlen)
+    buf.write_byte(family)
+    buf.write_byte(<int8_t>bits)
+    buf.write_byte(is_cidr)
+    buf.write_byte(<int8_t>addrlen)
+    buf.write_cstr(addrbytes, addrlen)
+
+
+cdef net_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int32_t family = <int32_t>frb_read(buf, 1)[0]
+        uint8_t bits = <uint8_t>frb_read(buf, 1)[0]
+        int32_t is_cidr = <int32_t>frb_read(buf, 1)[0]
+        int32_t addrlen = <int32_t>frb_read(buf, 1)[0]
+        bytes addr
+        uint8_t max_prefix_len = _ip_max_prefix_len(family)
+
+    if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:
+        raise ValueError('invalid address family in "{}" value'.format(
+            'cidr' if is_cidr else 'inet'
+        ))
+
+    max_prefix_len = _ip_max_prefix_len(family)
+
+    if bits > max_prefix_len:
+        raise ValueError('invalid network prefix length in "{}" value'.format(
+            'cidr' if is_cidr else 'inet'
+        ))
+
+    if addrlen != _ip_addr_len(family):
+        raise ValueError('invalid address length in "{}" value'.format(
+            'cidr' if is_cidr else 'inet'
+        ))
+
+    addr = cpython.PyBytes_FromStringAndSize(frb_read(buf, addrlen), addrlen)
+
+    if is_cidr or bits != max_prefix_len:
+        return _ipnet(addr).supernet(new_prefix=cpython.PyLong_FromLong(bits))
+    else:
+        return _ipaddr(addr)
+
+
+cdef cidr_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        object ipnet
+        int8_t family
+
+    ipnet = _ipnet(obj)
+    family = _ver_to_family(ipnet.version)
+    _net_encode(buf, family, ipnet.prefixlen, 1, ipnet.network_address.packed)
+
+
+cdef inet_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        object ipaddr
+        int8_t family
+
+    try:
+        ipaddr = _ipaddr(obj)
+    except ValueError:
+        # PostgreSQL accepts *both* CIDR and host values
+        # for the host datatype.
+        cidr_encode(settings, buf, obj)
+    else:
+        family = _ver_to_family(ipaddr.version)
+        _net_encode(buf, family, _ip_max_prefix_len(family), 0, ipaddr.packed)
diff --git a/asyncpg/pgproto/codecs/numeric.pyx b/asyncpg/pgproto/codecs/numeric.pyx
new file mode 100644 (file)
index 0000000..981af0e
--- /dev/null
@@ -0,0 +1,307 @@
+# 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
+
+
+from libc.math cimport abs, log10
+from libc.stdio cimport snprintf
+
+import decimal
+
+# defined in postgresql/src/backend/utils/adt/numeric.c
+DEF DEC_DIGITS = 4
+DEF MAX_DSCALE = 0x3FFF
+DEF NUMERIC_POS = 0x0000
+DEF NUMERIC_NEG = 0x4000
+DEF NUMERIC_NAN = 0xC000
+
+_Dec = decimal.Decimal
+
+
+cdef numeric_encode_text(CodecContext settings, WriteBuffer buf, obj):
+    text_encode(settings, buf, str(obj))
+
+
+cdef numeric_decode_text(CodecContext settings, FRBuffer *buf):
+    return _Dec(text_decode(settings, buf))
+
+
+cdef numeric_encode_binary(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        object dec
+        object dt
+        int64_t exponent
+        int64_t i
+        int64_t j
+        tuple pydigits
+        int64_t num_pydigits
+        int16_t pgdigit
+        int64_t num_pgdigits
+        int16_t dscale
+        int64_t dweight
+        int64_t weight
+        uint16_t sign
+        int64_t padding_size = 0
+
+    if isinstance(obj, _Dec):
+        dec = obj
+    else:
+        dec = _Dec(obj)
+
+    dt = dec.as_tuple()
+    if dt.exponent == 'F':
+        raise ValueError('numeric type does not support infinite values')
+
+    if dt.exponent == 'n' or dt.exponent == 'N':
+        # NaN
+        sign = NUMERIC_NAN
+        num_pgdigits = 0
+        weight = 0
+        dscale = 0
+    else:
+        exponent = dt.exponent
+        if exponent < 0 and -exponent > MAX_DSCALE:
+            raise ValueError(
+                'cannot encode Decimal value into numeric: '
+                'exponent is too small')
+
+        if dt.sign:
+            sign = NUMERIC_NEG
+        else:
+            sign = NUMERIC_POS
+
+        pydigits = dt.digits
+        num_pydigits = len(pydigits)
+
+        dweight = num_pydigits + exponent - 1
+        if dweight >= 0:
+            weight = (dweight + DEC_DIGITS) // DEC_DIGITS - 1
+        else:
+            weight = -((-dweight - 1) // DEC_DIGITS + 1)
+
+        if weight > 2 ** 16 - 1:
+            raise ValueError(
+                    'cannot encode Decimal value into numeric: '
+                    'exponent is too large')
+
+        padding_size = \
+            (weight + 1) * DEC_DIGITS - (dweight + 1)
+        num_pgdigits = \
+            (num_pydigits + padding_size + DEC_DIGITS - 1) // DEC_DIGITS
+
+        if num_pgdigits > 2 ** 16 - 1:
+            raise ValueError(
+                    'cannot encode Decimal value into numeric: '
+                    'number of digits is too large')
+
+        # Pad decimal digits to provide room for correct Postgres
+        # digit alignment in the digit computation loop.
+        pydigits = (0,) * DEC_DIGITS + pydigits + (0,) * DEC_DIGITS
+
+        if exponent < 0:
+            if -exponent > MAX_DSCALE:
+                raise ValueError(
+                    'cannot encode Decimal value into numeric: '
+                    'exponent is too small')
+            dscale = <int16_t>-exponent
+        else:
+            dscale = 0
+
+    buf.write_int32(2 + 2 + 2 + 2 + 2 * <uint16_t>num_pgdigits)
+    buf.write_int16(<int16_t>num_pgdigits)
+    buf.write_int16(<int16_t>weight)
+    buf.write_int16(<int16_t>sign)
+    buf.write_int16(dscale)
+
+    j = DEC_DIGITS - padding_size
+
+    for i in range(num_pgdigits):
+        pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +
+                   pydigits[j + 2] * 10 + pydigits[j + 3])
+        j += DEC_DIGITS
+        buf.write_int16(pgdigit)
+
+
+# The decoding strategy here is to form a string representation of
+# the numeric var, as it is faster than passing an iterable of digits.
+# For this reason the below code is pure overhead and is ~25% slower
+# than the simple text decoder above.  That said, we need the binary
+# decoder to support binary COPY with numeric values.
+cdef numeric_decode_binary(CodecContext settings, FRBuffer *buf):
+    cdef:
+        uint16_t num_pgdigits = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+        int16_t weight = hton.unpack_int16(frb_read(buf, 2))
+        uint16_t sign = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+        uint16_t dscale = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+        int16_t pgdigit0
+        ssize_t i
+        int16_t pgdigit
+        object pydigits
+        ssize_t num_pydigits
+        ssize_t buf_size
+        int64_t exponent
+        int64_t abs_exponent
+        ssize_t exponent_chars
+        ssize_t front_padding = 0
+        ssize_t trailing_padding = 0
+        ssize_t num_fract_digits
+        ssize_t dscale_left
+        char smallbuf[_NUMERIC_DECODER_SMALLBUF_SIZE]
+        char *charbuf
+        char *bufptr
+        bint buf_allocated = False
+
+    if sign == NUMERIC_NAN:
+        # Not-a-number
+        return _Dec('NaN')
+
+    if num_pgdigits == 0:
+        # Zero
+        return _Dec('0e-' + str(dscale))
+
+    pgdigit0 = hton.unpack_int16(frb_read(buf, 2))
+    if weight >= 0:
+        if pgdigit0 < 10:
+            front_padding = 3
+        elif pgdigit0 < 100:
+            front_padding = 2
+        elif pgdigit0 < 1000:
+            front_padding = 1
+
+    # Maximum possible number of decimal digits in base 10.
+    num_pydigits = num_pgdigits * DEC_DIGITS + dscale
+    # Exponent.
+    exponent = (weight + 1) * DEC_DIGITS - front_padding
+    abs_exponent = abs(exponent)
+    # Number of characters required to render absolute exponent value.
+    exponent_chars = <ssize_t>log10(<double>abs_exponent) + 1
+
+    buf_size = (
+        1 +                 # sign
+        1 +                 # leading zero
+        1 +                 # decimal dot
+        num_pydigits +      # digits
+        2 +                 # exponent indicator (E-,E+)
+        exponent_chars +    # exponent
+        1                   # null terminator char
+    )
+
+    if buf_size > _NUMERIC_DECODER_SMALLBUF_SIZE:
+        charbuf = <char *>cpython.PyMem_Malloc(<size_t>buf_size)
+        buf_allocated = True
+    else:
+        charbuf = smallbuf
+
+    try:
+        bufptr = charbuf
+
+        if sign == NUMERIC_NEG:
+            bufptr[0] = b'-'
+            bufptr += 1
+
+        bufptr[0] = b'0'
+        bufptr[1] = b'.'
+        bufptr += 2
+
+        if weight >= 0:
+            bufptr = _unpack_digit_stripping_lzeros(bufptr, pgdigit0)
+        else:
+            bufptr = _unpack_digit(bufptr, pgdigit0)
+
+        for i in range(1, num_pgdigits):
+            pgdigit = hton.unpack_int16(frb_read(buf, 2))
+            bufptr = _unpack_digit(bufptr, pgdigit)
+
+        if dscale:
+            if weight >= 0:
+                num_fract_digits = num_pgdigits - weight - 1
+            else:
+                num_fract_digits = num_pgdigits
+
+            # Check how much dscale is left to render (trailing zeros).
+            dscale_left = dscale - num_fract_digits * DEC_DIGITS
+            if dscale_left > 0:
+                for i in range(dscale_left):
+                    bufptr[i] = <char>b'0'
+
+            # If display scale is _less_ than the number of rendered digits,
+            # dscale_left will be negative and this will strip the excess
+            # trailing zeros.
+            bufptr += dscale_left
+
+        if exponent != 0:
+            bufptr[0] = b'E'
+            if exponent < 0:
+                bufptr[1] = b'-'
+            else:
+                bufptr[1] = b'+'
+            bufptr += 2
+            snprintf(bufptr, <size_t>exponent_chars + 1, '%d',
+                     <int>abs_exponent)
+            bufptr += exponent_chars
+
+        bufptr[0] = 0
+
+        pydigits = cpythonx.PyUnicode_FromString(charbuf)
+
+        return _Dec(pydigits)
+
+    finally:
+        if buf_allocated:
+            cpython.PyMem_Free(charbuf)
+
+
+cdef inline char *_unpack_digit_stripping_lzeros(char *buf, int64_t pgdigit):
+    cdef:
+        int64_t d
+        bint significant
+
+    d = pgdigit // 1000
+    significant = (d > 0)
+    if significant:
+        pgdigit -= d * 1000
+        buf[0] = <char>(d + <int32_t>b'0')
+        buf += 1
+
+    d = pgdigit // 100
+    significant |= (d > 0)
+    if significant:
+        pgdigit -= d * 100
+        buf[0] = <char>(d + <int32_t>b'0')
+        buf += 1
+
+    d = pgdigit // 10
+    significant |= (d > 0)
+    if significant:
+        pgdigit -= d * 10
+        buf[0] = <char>(d + <int32_t>b'0')
+        buf += 1
+
+    buf[0] = <char>(pgdigit + <int32_t>b'0')
+    buf += 1
+
+    return buf
+
+
+cdef inline char *_unpack_digit(char *buf, int64_t pgdigit):
+    cdef:
+        int64_t d
+
+    d = pgdigit // 1000
+    pgdigit -= d * 1000
+    buf[0] = <char>(d + <int32_t>b'0')
+
+    d = pgdigit // 100
+    pgdigit -= d * 100
+    buf[1] = <char>(d + <int32_t>b'0')
+
+    d = pgdigit // 10
+    pgdigit -= d * 10
+    buf[2] = <char>(d + <int32_t>b'0')
+
+    buf[3] = <char>(pgdigit + <int32_t>b'0')
+    buf += 4
+
+    return buf
diff --git a/asyncpg/pgproto/codecs/text.pyx b/asyncpg/pgproto/codecs/text.pyx
new file mode 100644 (file)
index 0000000..993bb11
--- /dev/null
@@ -0,0 +1,48 @@
+# 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 inline as_pg_string_and_size(
+        CodecContext settings, obj, char **cstr, ssize_t *size):
+
+    if not cpython.PyUnicode_Check(obj):
+        raise TypeError('expected str, got {}'.format(type(obj).__name__))
+
+    if settings.is_encoding_utf8():
+        cstr[0] = cpythonx.PyUnicode_AsUTF8AndSize(obj, size)
+    else:
+        encoded = settings.get_text_codec().encode(obj)
+        cpython.PyBytes_AsStringAndSize(encoded, cstr, size)
+
+    if size[0] > 0x7fffffff:
+        raise ValueError('string too long')
+
+
+cdef text_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        char *str
+        ssize_t size
+
+    as_pg_string_and_size(settings, obj, &str, &size)
+
+    buf.write_int32(<int32_t>size)
+    buf.write_cstr(str, size)
+
+
+cdef inline decode_pg_string(CodecContext settings, const char* data,
+                             ssize_t len):
+
+    if settings.is_encoding_utf8():
+        # decode UTF-8 in strict mode
+        return cpython.PyUnicode_DecodeUTF8(data, len, NULL)
+    else:
+        bytes = cpython.PyBytes_FromStringAndSize(data, len)
+        return settings.get_text_codec().decode(bytes)
+
+
+cdef text_decode(CodecContext settings, FRBuffer *buf):
+    cdef ssize_t buf_len = buf.len
+    return decode_pg_string(settings, frb_read_all(buf), buf_len)
diff --git a/asyncpg/pgproto/codecs/tid.pyx b/asyncpg/pgproto/codecs/tid.pyx
new file mode 100644 (file)
index 0000000..b39bddc
--- /dev/null
@@ -0,0 +1,51 @@
+# 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 tid_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef int overflow = 0
+    cdef unsigned long block, offset
+
+    if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+        raise TypeError(
+            'list or tuple expected (got type {})'.format(type(obj)))
+
+    if len(obj) != 2:
+        raise ValueError(
+            'invalid number of elements in tid tuple, expecting 2')
+
+    try:
+        block = cpython.PyLong_AsUnsignedLong(obj[0])
+    except OverflowError:
+        overflow = 1
+
+    # "long" and "long long" have the same size for x86_64, need an extra check
+    if overflow or (sizeof(block) > 4 and block > UINT32_MAX):
+        raise OverflowError('tuple id block value out of uint32 range')
+
+    try:
+        offset = cpython.PyLong_AsUnsignedLong(obj[1])
+        overflow = 0
+    except OverflowError:
+        overflow = 1
+
+    if overflow or offset > 65535:
+        raise OverflowError('tuple id offset value out of uint16 range')
+
+    buf.write_int32(6)
+    buf.write_int32(<int32_t>block)
+    buf.write_int16(<int16_t>offset)
+
+
+cdef tid_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        uint32_t block
+        uint16_t offset
+
+    block = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+    offset = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+
+    return (block, offset)
diff --git a/asyncpg/pgproto/codecs/txid.pyx b/asyncpg/pgproto/codecs/txid.pyx
new file mode 100644 (file)
index 0000000..a51c330
--- /dev/null
@@ -0,0 +1,61 @@
+# 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 txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj):
+    cdef:
+        ssize_t nxip
+        int64_t xmin
+        int64_t xmax
+        int i
+        WriteBuffer xip_buf = WriteBuffer.new()
+
+    if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+        raise TypeError(
+            'list or tuple expected (got type {})'.format(type(obj)))
+
+    if len(obj) != 3:
+        raise ValueError(
+            'invalid number of elements in txid_snapshot tuple, expecting 4')
+
+    nxip = len(obj[2])
+    if nxip > _MAXINT32:
+        raise ValueError('txid_snapshot value is too long')
+
+    xmin = obj[0]
+    xmax = obj[1]
+
+    for i in range(nxip):
+        xip_buf.write_int64(obj[2][i])
+
+    buf.write_int32(20 + xip_buf.len())
+
+    buf.write_int32(<int32_t>nxip)
+    buf.write_int64(obj[0])
+    buf.write_int64(obj[1])
+    buf.write_buffer(xip_buf)
+
+
+cdef txid_snapshot_decode(CodecContext settings, FRBuffer *buf):
+    cdef:
+        int32_t nxip
+        int64_t xmin
+        int64_t xmax
+        tuple xip_tup
+        int32_t i
+        object xip
+
+    nxip = hton.unpack_int32(frb_read(buf, 4))
+    xmin = hton.unpack_int64(frb_read(buf, 8))
+    xmax = hton.unpack_int64(frb_read(buf, 8))
+
+    xip_tup = cpython.PyTuple_New(nxip)
+    for i in range(nxip):
+        xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+        cpython.Py_INCREF(xip)
+        cpython.PyTuple_SET_ITEM(xip_tup, i, xip)
+
+    return (xmin, xmax, xip_tup)
diff --git a/asyncpg/pgproto/codecs/uuid.pyx b/asyncpg/pgproto/codecs/uuid.pyx
new file mode 100644 (file)
index 0000000..368c0ad
--- /dev/null
@@ -0,0 +1,22 @@
+# 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
+
+
+import uuid
+
+
+_UUID = uuid.UUID
+
+
+cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj):
+    if cpython.PyUnicode_Check(obj):
+        obj = _UUID(obj)
+
+    bytea_encode(settings, wbuf, obj.bytes)
+
+
+cdef uuid_decode(CodecContext settings, FRBuffer *buf):
+    return _UUID(bytes=bytea_decode(settings, buf))
diff --git a/asyncpg/pgproto/consts.pxi b/asyncpg/pgproto/consts.pxi
new file mode 100644 (file)
index 0000000..dbce085
--- /dev/null
@@ -0,0 +1,12 @@
+# 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
+
+
+DEF _BUFFER_INITIAL_SIZE = 1024
+DEF _BUFFER_MAX_GROW = 65536
+DEF _BUFFER_FREELIST_SIZE = 256
+DEF _MAXINT32 = 2**31 - 1
+DEF _NUMERIC_DECODER_SMALLBUF_SIZE = 256
diff --git a/asyncpg/pgproto/cpythonx.pxd b/asyncpg/pgproto/cpythonx.pxd
new file mode 100644 (file)
index 0000000..ad363b3
--- /dev/null
@@ -0,0 +1,16 @@
+# 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
+
+
+from cpython cimport Py_buffer
+
+cdef extern from "Python.h":
+    int PyByteArray_Resize(object, ssize_t) except -1
+    object PyByteArray_FromStringAndSize(const char *, ssize_t)
+    char* PyByteArray_AsString(object)
+
+    object PyUnicode_FromString(const char *u)
+    char* PyUnicode_AsUTF8AndSize(object unicode, ssize_t *size) except NULL
diff --git a/asyncpg/pgproto/debug.h b/asyncpg/pgproto/debug.h
new file mode 100644 (file)
index 0000000..946c10c
--- /dev/null
@@ -0,0 +1,3 @@
+#ifndef PG_DEBUG
+#define PG_DEBUG 0
+#endif
diff --git a/asyncpg/pgproto/debug.pxd b/asyncpg/pgproto/debug.pxd
new file mode 100644 (file)
index 0000000..5e59ec1
--- /dev/null
@@ -0,0 +1,10 @@
+# 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 extern from "debug.h":
+
+       cdef int PG_DEBUG
diff --git a/asyncpg/pgproto/exceptions.py b/asyncpg/pgproto/exceptions.py
new file mode 100644 (file)
index 0000000..8bbab65
--- /dev/null
@@ -0,0 +1,9 @@
+# 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
+
+
+class BufferError(Exception):
+    pass
diff --git a/asyncpg/pgproto/frb.pxd b/asyncpg/pgproto/frb.pxd
new file mode 100644 (file)
index 0000000..1ae9561
--- /dev/null
@@ -0,0 +1,49 @@
+# 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:
+
+    struct FRBuffer:
+        const char* buf
+        ssize_t len
+
+    inline ssize_t frb_get_len(FRBuffer *frb):
+        return frb.len
+
+    inline void frb_set_len(FRBuffer *frb, ssize_t new_len):
+        frb.len = new_len
+
+    inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+        frb.buf = buf
+        frb.len = len
+
+    inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:
+        cdef const char *result
+
+        if n > frb.len:
+            frb_check(frb, n)
+
+        result = frb.buf
+        frb.buf += n
+        frb.len -= n
+
+        return result
+
+    inline const char* frb_read_all(FRBuffer *frb):
+        cdef const char *result
+        result = frb.buf
+        frb.buf += frb.len
+        frb.len = 0
+        return result
+
+    inline FRBuffer *frb_slice_from(FRBuffer *frb,
+                                    FRBuffer* source, ssize_t len):
+        frb.buf = frb_read(source, len)
+        frb.len = len
+        return frb
+
+    object frb_check(FRBuffer *frb, ssize_t n)
diff --git a/asyncpg/pgproto/frb.pyx b/asyncpg/pgproto/frb.pyx
new file mode 100644 (file)
index 0000000..f11f6b9
--- /dev/null
@@ -0,0 +1,12 @@
+# 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 object frb_check(FRBuffer *frb, ssize_t n):
+    if n > frb.len:
+        raise AssertionError(
+            f'insufficient data in buffer: requested {n} '
+            f'remaining {frb.len}')
diff --git a/asyncpg/pgproto/hton.h b/asyncpg/pgproto/hton.h
new file mode 100644 (file)
index 0000000..3f6777f
--- /dev/null
@@ -0,0 +1,199 @@
+#include <stdint.h>
+
+#if defined(__linux__) || defined(__CYGWIN__)
+#include <endian.h>
+#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#include <sys/endian.h>
+#elif defined(__DragonFly__)
+#include <sys/endian.h>
+#elif defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#elif defined(_WIN32) || defined(_WIN64) || defined(__WINDOWS__)
+/* Assume Windows is always LE.  There seems to be no reliable way
+   to detect endianness there */
+#define __LITTLE_ENDIAN 1234
+#define __BIG_ENDIAN 4321
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#else
+#error Cannot determine platform byte order.
+#endif
+
+
+#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
+
+#define apg_bswap16(x) __builtin_bswap16(x)
+#define apg_bswap32(x) __builtin_bswap32(x)
+#define apg_bswap64(x) __builtin_bswap64(x)
+
+#elif defined(_MSC_VER)
+
+#define apg_bswap16(x) _byteswap_ushort(x)
+#define apg_bswap32(x) _byteswap_ulong(x)
+#define apg_bswap64(x) _byteswap_uint64(x)
+
+#else
+
+static inline uint16_t
+apg_bswap16(uint16_t)
+{
+    return ((x << 8) & 0xff00) | (x >> 8) & 0x00ff));
+}
+
+static inline uint32_t
+apg_bswap32(uint32_t x)
+{
+    return (
+        ((x << 24) & 0xff000000) | ((x << 8) & 0x00ff0000) |
+               ((x >> 8) & 0x0000ff00) | ((x >> 24) & 0x000000ff)
+    );
+}
+
+static inline uint64_t
+apg_bswap64(uint64_t x)
+{
+       return (
+               ((x << 56) & 0xff00000000000000ULL) |
+               ((x << 40) & 0x00ff000000000000ULL) |
+               ((x << 24) & 0x0000ff0000000000ULL) |
+               ((x << 8) & 0x000000ff00000000ULL) |
+               ((x >> 8) & 0x00000000ff000000ULL) |
+               ((x >> 24) & 0x0000000000ff0000ULL) |
+               ((x >> 40) & 0x000000000000ff00ULL) |
+               ((x >> 56) & 0x00000000000000ffULL);
+    );
+}
+
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+
+#define apg_hton16(x) (x)
+#define apg_hton32(x) (x)
+#define apg_hton64(x) (x)
+
+#define apg_ntoh16(x) (x)
+#define apg_ntoh32(x) (x)
+#define apg_ntoh64(x) (x)
+
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+
+#define apg_hton16(x) apg_bswap16(x)
+#define apg_hton32(x) apg_bswap32(x)
+#define apg_hton64(x) apg_bswap64(x)
+
+#define apg_ntoh16(x) apg_bswap16(x)
+#define apg_ntoh32(x) apg_bswap32(x)
+#define apg_ntoh64(x) apg_bswap64(x)
+
+#else
+
+#error Unsupported byte order.
+
+#endif
+
+
+static inline void
+pack_int16(char *buf, int16_t x)
+{
+    uint16_t nx = apg_hton16((uint16_t)x);
+    /* NOTE: the memcpy below is _important_ to support systems
+       which disallow unaligned access.  On systems, which do
+       allow unaligned access it will be optimized away by the
+       compiler
+    */
+    memcpy(buf, &nx, sizeof(uint16_t));
+}
+
+
+static inline void
+pack_int32(char *buf, int64_t x)
+{
+    uint32_t nx = apg_hton32((uint32_t)x);
+    memcpy(buf, &nx, sizeof(uint32_t));
+}
+
+
+static inline void
+pack_int64(char *buf, int64_t x)
+{
+    uint64_t nx = apg_hton64((uint64_t)x);
+    memcpy(buf, &nx, sizeof(uint64_t));
+}
+
+
+static inline int16_t
+unpack_int16(const char *buf)
+{
+    uint16_t nx;
+    memcpy((char *)&nx, buf, sizeof(uint16_t));
+    return (int16_t)apg_ntoh16(nx);
+}
+
+
+static inline int32_t
+unpack_int32(const char *buf)
+{
+    uint32_t nx;
+    memcpy((char *)&nx, buf, sizeof(uint32_t));
+    return (int32_t)apg_ntoh32(nx);
+}
+
+
+static inline int64_t
+unpack_int64(const char *buf)
+{
+    uint64_t nx;
+    memcpy((char *)&nx, buf, sizeof(uint64_t));
+    return (int64_t)apg_ntoh64(nx);
+}
+
+
+union _apg_floatconv {
+    uint32_t i;
+    float f;
+};
+
+
+union _apg_doubleconv {
+    uint64_t i;
+    double f;
+};
+
+
+static inline void
+pack_float(char *buf, float f)
+{
+    union _apg_floatconv v;
+    v.f = f;
+    pack_int32(buf, (int32_t)v.i);
+}
+
+
+static inline void
+pack_double(char *buf, double f)
+{
+    union _apg_doubleconv v;
+    v.f = f;
+    pack_int64(buf, (int64_t)v.i);
+}
+
+
+static inline float
+unpack_float(const char *buf)
+{
+    union _apg_floatconv v;
+    v.i = (uint32_t)unpack_int32(buf);
+    return v.f;
+}
+
+
+static inline double
+unpack_double(const char *buf)
+{
+    union _apg_doubleconv v;
+    v.i = (uint64_t)unpack_int64(buf);
+    return v.f;
+}
diff --git a/asyncpg/pgproto/hton.pxd b/asyncpg/pgproto/hton.pxd
new file mode 100644 (file)
index 0000000..29b0006
--- /dev/null
@@ -0,0 +1,21 @@
+# 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
+
+
+from libc.stdint cimport int16_t, int32_t, uint16_t, uint32_t, int64_t, uint64_t
+
+
+cdef extern from "./hton.h":
+    cdef void pack_int16(char *buf, int16_t x);
+    cdef void pack_int32(char *buf, int32_t x);
+    cdef void pack_int64(char *buf, int64_t x);
+    cdef void pack_float(char *buf, float f);
+    cdef void pack_double(char *buf, double f);
+    cdef int16_t unpack_int16(const char *buf);
+    cdef int32_t unpack_int32(const char *buf);
+    cdef int64_t unpack_int64(const char *buf);
+    cdef float unpack_float(const char *buf);
+    cdef double unpack_double(const char *buf);
diff --git a/asyncpg/pgproto/pgproto.c b/asyncpg/pgproto/pgproto.c
new file mode 100644 (file)
index 0000000..e0d7bd8
--- /dev/null
@@ -0,0 +1,33605 @@
+/* Generated by Cython 0.29 */
+
+/* BEGIN: Cython Metadata
+{
+    "distutils": {
+        "depends": [
+            "asyncpg/pgproto/debug.h"
+        ],
+        "extra_compile_args": [
+            "-O2",
+            "-fsigned-char",
+            "-Wall",
+            "-Wsign-compare",
+            "-Wconversion"
+        ],
+        "include_dirs": [
+            "./asyncpg/pgproto"
+        ],
+        "name": "asyncpg.pgproto.pgproto",
+        "sources": [
+            "asyncpg/pgproto/pgproto.pyx"
+        ]
+    },
+    "module_name": "asyncpg.pgproto.pgproto"
+}
+END: Cython Metadata */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+    #error Python headers needed to compile C extensions, please install development version of Python.
+#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
+    #error Cython requires Python 2.6+ or Python 3.3+.
+#else
+#define CYTHON_ABI "0_29"
+#define CYTHON_HEX_VERSION 0x001D00F0
+#define CYTHON_FUTURE_DIVISION 1
+#include <stddef.h>
+#ifndef offsetof
+  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+  #ifndef __stdcall
+    #define __stdcall
+  #endif
+  #ifndef __cdecl
+    #define __cdecl
+  #endif
+  #ifndef __fastcall
+    #define __fastcall
+  #endif
+#endif
+#ifndef DL_IMPORT
+  #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+  #define DL_EXPORT(t) t
+#endif
+#define __PYX_COMMA ,
+#ifndef HAVE_LONG_LONG
+  #if PY_VERSION_HEX >= 0x02070000
+    #define HAVE_LONG_LONG
+  #endif
+#endif
+#ifndef PY_LONG_LONG
+  #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef Py_HUGE_VAL
+  #define Py_HUGE_VAL HUGE_VAL
+#endif
+#ifdef PYPY_VERSION
+  #define CYTHON_COMPILING_IN_PYPY 1
+  #define CYTHON_COMPILING_IN_PYSTON 0
+  #define CYTHON_COMPILING_IN_CPYTHON 0
+  #undef CYTHON_USE_TYPE_SLOTS
+  #define CYTHON_USE_TYPE_SLOTS 0
+  #undef CYTHON_USE_PYTYPE_LOOKUP
+  #define CYTHON_USE_PYTYPE_LOOKUP 0
+  #if PY_VERSION_HEX < 0x03050000
+    #undef CYTHON_USE_ASYNC_SLOTS
+    #define CYTHON_USE_ASYNC_SLOTS 0
+  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
+    #define CYTHON_USE_ASYNC_SLOTS 1
+  #endif
+  #undef CYTHON_USE_PYLIST_INTERNALS
+  #define CYTHON_USE_PYLIST_INTERNALS 0
+  #undef CYTHON_USE_UNICODE_INTERNALS
+  #define CYTHON_USE_UNICODE_INTERNALS 0
+  #undef CYTHON_USE_UNICODE_WRITER
+  #define CYTHON_USE_UNICODE_WRITER 0
+  #undef CYTHON_USE_PYLONG_INTERNALS
+  #define CYTHON_USE_PYLONG_INTERNALS 0
+  #undef CYTHON_AVOID_BORROWED_REFS
+  #define CYTHON_AVOID_BORROWED_REFS 1
+  #undef CYTHON_ASSUME_SAFE_MACROS
+  #define CYTHON_ASSUME_SAFE_MACROS 0
+  #undef CYTHON_UNPACK_METHODS
+  #define CYTHON_UNPACK_METHODS 0
+  #undef CYTHON_FAST_THREAD_STATE
+  #define CYTHON_FAST_THREAD_STATE 0
+  #undef CYTHON_FAST_PYCALL
+  #define CYTHON_FAST_PYCALL 0
+  #undef CYTHON_PEP489_MULTI_PHASE_INIT
+  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
+  #undef CYTHON_USE_TP_FINALIZE
+  #define CYTHON_USE_TP_FINALIZE 0
+  #undef CYTHON_USE_DICT_VERSIONS
+  #define CYTHON_USE_DICT_VERSIONS 0
+  #undef CYTHON_USE_EXC_INFO_STACK
+  #define CYTHON_USE_EXC_INFO_STACK 0
+#elif defined(PYSTON_VERSION)
+  #define CYTHON_COMPILING_IN_PYPY 0
+  #define CYTHON_COMPILING_IN_PYSTON 1
+  #define CYTHON_COMPILING_IN_CPYTHON 0
+  #ifndef CYTHON_USE_TYPE_SLOTS
+    #define CYTHON_USE_TYPE_SLOTS 1
+  #endif
+  #undef CYTHON_USE_PYTYPE_LOOKUP
+  #define CYTHON_USE_PYTYPE_LOOKUP 0
+  #undef CYTHON_USE_ASYNC_SLOTS
+  #define CYTHON_USE_ASYNC_SLOTS 0
+  #undef CYTHON_USE_PYLIST_INTERNALS
+  #define CYTHON_USE_PYLIST_INTERNALS 0
+  #ifndef CYTHON_USE_UNICODE_INTERNALS
+    #define CYTHON_USE_UNICODE_INTERNALS 1
+  #endif
+  #undef CYTHON_USE_UNICODE_WRITER
+  #define CYTHON_USE_UNICODE_WRITER 0
+  #undef CYTHON_USE_PYLONG_INTERNALS
+  #define CYTHON_USE_PYLONG_INTERNALS 0
+  #ifndef CYTHON_AVOID_BORROWED_REFS
+    #define CYTHON_AVOID_BORROWED_REFS 0
+  #endif
+  #ifndef CYTHON_ASSUME_SAFE_MACROS
+    #define CYTHON_ASSUME_SAFE_MACROS 1
+  #endif
+  #ifndef CYTHON_UNPACK_METHODS
+    #define CYTHON_UNPACK_METHODS 1
+  #endif
+  #undef CYTHON_FAST_THREAD_STATE
+  #define CYTHON_FAST_THREAD_STATE 0
+  #undef CYTHON_FAST_PYCALL
+  #define CYTHON_FAST_PYCALL 0
+  #undef CYTHON_PEP489_MULTI_PHASE_INIT
+  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
+  #undef CYTHON_USE_TP_FINALIZE
+  #define CYTHON_USE_TP_FINALIZE 0
+  #undef CYTHON_USE_DICT_VERSIONS
+  #define CYTHON_USE_DICT_VERSIONS 0
+  #undef CYTHON_USE_EXC_INFO_STACK
+  #define CYTHON_USE_EXC_INFO_STACK 0
+#else
+  #define CYTHON_COMPILING_IN_PYPY 0
+  #define CYTHON_COMPILING_IN_PYSTON 0
+  #define CYTHON_COMPILING_IN_CPYTHON 1
+  #ifndef CYTHON_USE_TYPE_SLOTS
+    #define CYTHON_USE_TYPE_SLOTS 1
+  #endif
+  #if PY_VERSION_HEX < 0x02070000
+    #undef CYTHON_USE_PYTYPE_LOOKUP
+    #define CYTHON_USE_PYTYPE_LOOKUP 0
+  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
+    #define CYTHON_USE_PYTYPE_LOOKUP 1
+  #endif
+  #if PY_MAJOR_VERSION < 3
+    #undef CYTHON_USE_ASYNC_SLOTS
+    #define CYTHON_USE_ASYNC_SLOTS 0
+  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
+    #define CYTHON_USE_ASYNC_SLOTS 1
+  #endif
+  #if PY_VERSION_HEX < 0x02070000
+    #undef CYTHON_USE_PYLONG_INTERNALS
+    #define CYTHON_USE_PYLONG_INTERNALS 0
+  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
+    #define CYTHON_USE_PYLONG_INTERNALS 1
+  #endif
+  #ifndef CYTHON_USE_PYLIST_INTERNALS
+    #define CYTHON_USE_PYLIST_INTERNALS 1
+  #endif
+  #ifndef CYTHON_USE_UNICODE_INTERNALS
+    #define CYTHON_USE_UNICODE_INTERNALS 1
+  #endif
+  #if PY_VERSION_HEX < 0x030300F0
+    #undef CYTHON_USE_UNICODE_WRITER
+    #define CYTHON_USE_UNICODE_WRITER 0
+  #elif !defined(CYTHON_USE_UNICODE_WRITER)
+    #define CYTHON_USE_UNICODE_WRITER 1
+  #endif
+  #ifndef CYTHON_AVOID_BORROWED_REFS
+    #define CYTHON_AVOID_BORROWED_REFS 0
+  #endif
+  #ifndef CYTHON_ASSUME_SAFE_MACROS
+    #define CYTHON_ASSUME_SAFE_MACROS 1
+  #endif
+  #ifndef CYTHON_UNPACK_METHODS
+    #define CYTHON_UNPACK_METHODS 1
+  #endif
+  #ifndef CYTHON_FAST_THREAD_STATE
+    #define CYTHON_FAST_THREAD_STATE 1
+  #endif
+  #ifndef CYTHON_FAST_PYCALL
+    #define CYTHON_FAST_PYCALL 1
+  #endif
+  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
+    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
+  #endif
+  #ifndef CYTHON_USE_TP_FINALIZE
+    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
+  #endif
+  #ifndef CYTHON_USE_DICT_VERSIONS
+    #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
+  #endif
+  #ifndef CYTHON_USE_EXC_INFO_STACK
+    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
+  #endif
+#endif
+#if !defined(CYTHON_FAST_PYCCALL)
+#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
+#endif
+#if CYTHON_USE_PYLONG_INTERNALS
+  #include "longintrepr.h"
+  #undef SHIFT
+  #undef BASE
+  #undef MASK
+#endif
+#ifndef __has_attribute
+  #define __has_attribute(x) 0
+#endif
+#ifndef __has_cpp_attribute
+  #define __has_cpp_attribute(x) 0
+#endif
+#ifndef CYTHON_RESTRICT
+  #if defined(__GNUC__)
+    #define CYTHON_RESTRICT __restrict__
+  #elif defined(_MSC_VER) && _MSC_VER >= 1400
+    #define CYTHON_RESTRICT __restrict
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_RESTRICT restrict
+  #else
+    #define CYTHON_RESTRICT
+  #endif
+#endif
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#     define CYTHON_UNUSED __attribute__ ((__unused__))
+#   else
+#     define CYTHON_UNUSED
+#   endif
+# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+#   define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+#   define CYTHON_UNUSED
+# endif
+#endif
+#ifndef CYTHON_MAYBE_UNUSED_VAR
+#  if defined(__cplusplus)
+     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
+#  else
+#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
+#  endif
+#endif
+#ifndef CYTHON_NCP_UNUSED
+# if CYTHON_COMPILING_IN_CPYTHON
+#  define CYTHON_NCP_UNUSED
+# else
+#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
+# endif
+#endif
+#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
+#ifdef _MSC_VER
+    #ifndef _MSC_STDINT_H_
+        #if _MSC_VER < 1300
+           typedef unsigned char     uint8_t;
+           typedef unsigned int      uint32_t;
+        #else
+           typedef unsigned __int8   uint8_t;
+           typedef unsigned __int32  uint32_t;
+        #endif
+    #endif
+#else
+   #include <stdint.h>
+#endif
+#ifndef CYTHON_FALLTHROUGH
+  #if defined(__cplusplus) && __cplusplus >= 201103L
+    #if __has_cpp_attribute(fallthrough)
+      #define CYTHON_FALLTHROUGH [[fallthrough]]
+    #elif __has_cpp_attribute(clang::fallthrough)
+      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
+    #elif __has_cpp_attribute(gnu::fallthrough)
+      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
+    #endif
+  #endif
+  #ifndef CYTHON_FALLTHROUGH
+    #if __has_attribute(fallthrough)
+      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
+    #else
+      #define CYTHON_FALLTHROUGH
+    #endif
+  #endif
+  #if defined(__clang__ ) && defined(__apple_build_version__)
+    #if __apple_build_version__ < 7000000
+      #undef  CYTHON_FALLTHROUGH
+      #define CYTHON_FALLTHROUGH
+    #endif
+  #endif
+#endif
+
+#ifndef CYTHON_INLINE
+  #if defined(__clang__)
+    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
+  #elif defined(__GNUC__)
+    #define CYTHON_INLINE __inline__
+  #elif defined(_MSC_VER)
+    #define CYTHON_INLINE __inline
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_INLINE inline
+  #else
+    #define CYTHON_INLINE
+  #endif
+#endif
+
+#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
+  #define Py_OptimizeFlag 0
+#endif
+#define __PYX_BUILD_PY_SSIZE_T "n"
+#define CYTHON_FORMAT_SSIZE_T "z"
+#if PY_MAJOR_VERSION < 3
+  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
+          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+  #define __Pyx_DefaultClassType PyClass_Type
+#else
+  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
+          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+  #define __Pyx_DefaultClassType PyType_Type
+#endif
+#ifndef Py_TPFLAGS_CHECKTYPES
+  #define Py_TPFLAGS_CHECKTYPES 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_INDEX
+  #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
+  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_FINALIZE
+  #define Py_TPFLAGS_HAVE_FINALIZE 0
+#endif
+#ifndef METH_STACKLESS
+  #define METH_STACKLESS 0
+#endif
+#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
+  #ifndef METH_FASTCALL
+     #define METH_FASTCALL 0x80
+  #endif
+  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
+  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
+                                                          Py_ssize_t nargs, PyObject *kwnames);
+#else
+  #define __Pyx_PyCFunctionFast _PyCFunctionFast
+  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
+#endif
+#if CYTHON_FAST_PYCCALL
+#define __Pyx_PyFastCFunction_Check(func)\
+    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
+#else
+#define __Pyx_PyFastCFunction_Check(func) 0
+#endif
+#if CYTHON_USE_DICT_VERSIONS
+#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
+#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
+    (version_var) = __PYX_GET_DICT_VERSION(dict);\
+    (cache_var) = (value);
+#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
+        static PY_UINT64_T __pyx_dict_version = 0;\
+        static PyObject *__pyx_dict_cached_value = NULL;\
+        if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
+            (VAR) = __pyx_dict_cached_value;\
+        } else {\
+            (VAR) = __pyx_dict_cached_value = (LOOKUP);\
+            __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
+        }\
+    }
+#else
+#define __PYX_GET_DICT_VERSION(dict)  (0)
+#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
+#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
+  #define PyObject_Malloc(s)   PyMem_Malloc(s)
+  #define PyObject_Free(p)     PyMem_Free(p)
+  #define PyObject_Realloc(p)  PyMem_Realloc(p)
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
+  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
+  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
+  #define PyMem_RawFree(p)             PyMem_Free(p)
+#endif
+#if CYTHON_COMPILING_IN_PYSTON
+  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
+  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
+#else
+  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
+  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
+#endif
+#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
+  #define __Pyx_PyThreadState_Current PyThreadState_GET()
+#elif PY_VERSION_HEX >= 0x03060000
+  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
+#elif PY_VERSION_HEX >= 0x03000000
+  #define __Pyx_PyThreadState_Current PyThreadState_GET()
+#else
+  #define __Pyx_PyThreadState_Current _PyThreadState_Current
+#endif
+#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
+#include "pythread.h"
+#define Py_tss_NEEDS_INIT 0
+typedef int Py_tss_t;
+static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
+  *key = PyThread_create_key();
+  return 0; // PyThread_create_key reports success always
+}
+static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
+  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
+  *key = Py_tss_NEEDS_INIT;
+  return key;
+}
+static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
+  PyObject_Free(key);
+}
+static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
+  return *key != Py_tss_NEEDS_INIT;
+}
+static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
+  PyThread_delete_key(*key);
+  *key = Py_tss_NEEDS_INIT;
+}
+static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
+  return PyThread_set_key_value(*key, value);
+}
+static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
+  return PyThread_get_key_value(*key);
+}
+#endif // TSS (Thread Specific Storage) API
+#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
+#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
+#else
+#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
+#endif
+#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
+  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
+  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
+#else
+  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
+  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
+#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
+#else
+#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
+#endif
+#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
+  #define CYTHON_PEP393_ENABLED 1
+  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
+                                              0 : _PyUnicode_Ready((PyObject *)(op)))
+  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
+  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
+  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
+  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
+  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
+  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
+  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
+  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
+#else
+  #define CYTHON_PEP393_ENABLED 0
+  #define PyUnicode_1BYTE_KIND  1
+  #define PyUnicode_2BYTE_KIND  2
+  #define PyUnicode_4BYTE_KIND  4
+  #define __Pyx_PyUnicode_READY(op)       (0)
+  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
+  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
+  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
+  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
+  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
+  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
+  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
+  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
+#endif
+#if CYTHON_COMPILING_IN_PYPY
+  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
+#else
+  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
+      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
+  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
+  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
+  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
+#endif
+#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
+#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
+#if PY_MAJOR_VERSION >= 3
+  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
+#else
+  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
+#endif
+#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
+  #define PyObject_ASCII(o)            PyObject_Repr(o)
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyBaseString_Type            PyUnicode_Type
+  #define PyStringObject               PyUnicodeObject
+  #define PyString_Type                PyUnicode_Type
+  #define PyString_Check               PyUnicode_Check
+  #define PyString_CheckExact          PyUnicode_CheckExact
+  #define PyObject_Unicode             PyObject_Str
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
+  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
+#else
+  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
+  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
+#endif
+#ifndef PySet_CheckExact
+  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
+#endif
+#if CYTHON_ASSUME_SAFE_MACROS
+  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
+#else
+  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyIntObject                  PyLongObject
+  #define PyInt_Type                   PyLong_Type
+  #define PyInt_Check(op)              PyLong_Check(op)
+  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
+  #define PyInt_FromString             PyLong_FromString
+  #define PyInt_FromUnicode            PyLong_FromUnicode
+  #define PyInt_FromLong               PyLong_FromLong
+  #define PyInt_FromSize_t             PyLong_FromSize_t
+  #define PyInt_FromSsize_t            PyLong_FromSsize_t
+  #define PyInt_AsLong                 PyLong_AsLong
+  #define PyInt_AS_LONG                PyLong_AS_LONG
+  #define PyInt_AsSsize_t              PyLong_AsSsize_t
+  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
+  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+  #define PyNumber_Int                 PyNumber_Long
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyBoolObject                 PyLongObject
+#endif
+#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
+  #ifndef PyUnicode_InternFromString
+    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
+  #endif
+#endif
+#if PY_VERSION_HEX < 0x030200A4
+  typedef long Py_hash_t;
+  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
+#else
+  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
+#else
+  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
+#endif
+#if CYTHON_USE_ASYNC_SLOTS
+  #if PY_VERSION_HEX >= 0x030500B1
+    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
+    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
+  #else
+    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
+  #endif
+#else
+  #define __Pyx_PyType_AsAsync(obj) NULL
+#endif
+#ifndef __Pyx_PyAsyncMethodsStruct
+    typedef struct {
+        unaryfunc am_await;
+        unaryfunc am_aiter;
+        unaryfunc am_anext;
+    } __Pyx_PyAsyncMethodsStruct;
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+  #define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#ifdef NAN
+#define __PYX_NAN() ((float) NAN)
+#else
+static CYTHON_INLINE float __PYX_NAN() {
+  float value;
+  memset(&value, 0xFF, sizeof(value));
+  return value;
+}
+#endif
+#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
+#define __Pyx_truncl trunc
+#else
+#define __Pyx_truncl truncl
+#endif
+
+
+#define __PYX_ERR(f_index, lineno, Ln_error) \
+{ \
+  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
+}
+
+#ifndef __PYX_EXTERN_C
+  #ifdef __cplusplus
+    #define __PYX_EXTERN_C extern "C"
+  #else
+    #define __PYX_EXTERN_C extern
+  #endif
+#endif
+
+#define __PYX_HAVE__asyncpg__pgproto__pgproto
+#define __PYX_HAVE_API__asyncpg__pgproto__pgproto
+/* Early includes */
+#include <string.h>
+#include <stdio.h>
+#include "pythread.h"
+#include <stdint.h>
+#include "./hton.h"
+#include "debug.h"
+#include "datetime.h"
+#include <math.h>
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
+                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
+
+#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
+#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
+#define __PYX_DEFAULT_STRING_ENCODING ""
+#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
+#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
+#define __Pyx_uchar_cast(c) ((unsigned char)c)
+#define __Pyx_long_cast(x) ((long)x)
+#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
+    (sizeof(type) < sizeof(Py_ssize_t))  ||\
+    (sizeof(type) > sizeof(Py_ssize_t) &&\
+          likely(v < (type)PY_SSIZE_T_MAX ||\
+                 v == (type)PY_SSIZE_T_MAX)  &&\
+          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
+                                v == (type)PY_SSIZE_T_MIN)))  ||\
+    (sizeof(type) == sizeof(Py_ssize_t) &&\
+          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
+                               v == (type)PY_SSIZE_T_MAX)))  )
+static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
+    return (size_t) i < (size_t) limit;
+}
+#if defined (__cplusplus) && __cplusplus >= 201103L
+    #include <cstdlib>
+    #define __Pyx_sst_abs(value) std::abs(value)
+#elif SIZEOF_INT >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) abs(value)
+#elif SIZEOF_LONG >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) labs(value)
+#elif defined (_MSC_VER)
+    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define __Pyx_sst_abs(value) llabs(value)
+#elif defined (__GNUC__)
+    #define __Pyx_sst_abs(value) __builtin_llabs(value)
+#else
+    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
+#endif
+static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
+static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
+#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
+#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
+#define __Pyx_PyBytes_FromString        PyBytes_FromString
+#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
+#if PY_MAJOR_VERSION < 3
+    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
+    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
+#else
+    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
+    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
+#endif
+#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
+#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
+#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
+#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
+#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
+static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
+    const Py_UNICODE *u_end = u;
+    while (*u_end++) ;
+    return (size_t)(u_end - u - 1);
+}
+#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
+#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
+#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
+#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
+#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
+static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
+#define __Pyx_PySequence_Tuple(obj)\
+    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+#if CYTHON_ASSUME_SAFE_MACROS
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+#else
+#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
+#endif
+#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
+#if PY_MAJOR_VERSION >= 3
+#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
+#else
+#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
+#endif
+#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
+#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+static int __Pyx_sys_getdefaultencoding_not_ascii;
+static int __Pyx_init_sys_getdefaultencoding_params(void) {
+    PyObject* sys;
+    PyObject* default_encoding = NULL;
+    PyObject* ascii_chars_u = NULL;
+    PyObject* ascii_chars_b = NULL;
+    const char* default_encoding_c;
+    sys = PyImport_ImportModule("sys");
+    if (!sys) goto bad;
+    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
+    Py_DECREF(sys);
+    if (!default_encoding) goto bad;
+    default_encoding_c = PyBytes_AsString(default_encoding);
+    if (!default_encoding_c) goto bad;
+    if (strcmp(default_encoding_c, "ascii") == 0) {
+        __Pyx_sys_getdefaultencoding_not_ascii = 0;
+    } else {
+        char ascii_chars[128];
+        int c;
+        for (c = 0; c < 128; c++) {
+            ascii_chars[c] = c;
+        }
+        __Pyx_sys_getdefaultencoding_not_ascii = 1;
+        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
+        if (!ascii_chars_u) goto bad;
+        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
+        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
+            PyErr_Format(
+                PyExc_ValueError,
+                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
+                default_encoding_c);
+            goto bad;
+        }
+        Py_DECREF(ascii_chars_u);
+        Py_DECREF(ascii_chars_b);
+    }
+    Py_DECREF(default_encoding);
+    return 0;
+bad:
+    Py_XDECREF(default_encoding);
+    Py_XDECREF(ascii_chars_u);
+    Py_XDECREF(ascii_chars_b);
+    return -1;
+}
+#endif
+#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
+#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
+#else
+#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
+#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+static char* __PYX_DEFAULT_STRING_ENCODING;
+static int __Pyx_init_sys_getdefaultencoding_params(void) {
+    PyObject* sys;
+    PyObject* default_encoding = NULL;
+    char* default_encoding_c;
+    sys = PyImport_ImportModule("sys");
+    if (!sys) goto bad;
+    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
+    Py_DECREF(sys);
+    if (!default_encoding) goto bad;
+    default_encoding_c = PyBytes_AsString(default_encoding);
+    if (!default_encoding_c) goto bad;
+    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
+    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
+    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
+    Py_DECREF(default_encoding);
+    return 0;
+bad:
+    Py_XDECREF(default_encoding);
+    return -1;
+}
+#endif
+#endif
+
+
+/* Test for GCC > 2.95 */
+#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
+  #define likely(x)   __builtin_expect(!!(x), 1)
+  #define unlikely(x) __builtin_expect(!!(x), 0)
+#else /* !__GNUC__ or GCC < 2.95 */
+  #define likely(x)   (x)
+  #define unlikely(x) (x)
+#endif /* __GNUC__ */
+static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
+
+static PyObject *__pyx_m = NULL;
+static PyObject *__pyx_d;
+static PyObject *__pyx_b;
+static PyObject *__pyx_cython_runtime = NULL;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static PyObject *__pyx_empty_unicode;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+  "asyncpg/pgproto/./frb.pyx",
+  "asyncpg/pgproto/./buffer.pyx",
+  "stringsource",
+  "asyncpg/pgproto/./codecs/context.pyx",
+  "asyncpg/pgproto/./codecs/text.pyx",
+  "asyncpg/pgproto/./codecs/int.pyx",
+  "asyncpg/pgproto/./codecs/numeric.pyx",
+  "asyncpg/pgproto/./codecs/bytea.pyx",
+  "asyncpg/pgproto/./codecs/datetime.pyx",
+  "asyncpg/pgproto/./codecs/float.pyx",
+  "asyncpg/pgproto/./codecs/json.pyx",
+  "asyncpg/pgproto/./codecs/uuid.pyx",
+  "asyncpg/pgproto/./codecs/bits.pyx",
+  "asyncpg/pgproto/./codecs/geometry.pyx",
+  "asyncpg/pgproto/./codecs/hstore.pyx",
+  "asyncpg/pgproto/./codecs/misc.pyx",
+  "asyncpg/pgproto/./codecs/network.pyx",
+  "asyncpg/pgproto/./codecs/tid.pyx",
+  "asyncpg/pgproto/./codecs/txid.pyx",
+  "asyncpg/pgproto/./frb.pxd",
+  "asyncpg/pgproto/./buffer.pxd",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/datetime.pxd",
+  "asyncpg/pgproto/pgproto.pyx",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/type.pxd",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/bool.pxd",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/complex.pxd",
+};
+
+/*--- Type declarations ---*/
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext;
+struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer;
+
+/* "asyncpg/pgproto/frb.pxd":10
+ * cdef:
+ * 
+ *     struct FRBuffer:             # <<<<<<<<<<<<<<
+ *         const char* buf
+ *         ssize_t len
+ */
+struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer {
+  char const *buf;
+  Py_ssize_t len;
+};
+
+/* "asyncpg/pgproto/buffer.pxd":56
+ * 
+ * 
+ * ctypedef const char * (*try_consume_message_method)(object, ssize_t*)             # <<<<<<<<<<<<<<
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ * ctypedef int32_t (*take_message_method)(object) except -1
+ */
+typedef char const *(*__pyx_t_7asyncpg_7pgproto_7pgproto_try_consume_message_method)(PyObject *, Py_ssize_t *);
+
+/* "asyncpg/pgproto/buffer.pxd":57
+ * 
+ * ctypedef const char * (*try_consume_message_method)(object, ssize_t*)
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1             # <<<<<<<<<<<<<<
+ * ctypedef int32_t (*take_message_method)(object) except -1
+ * ctypedef char (*get_message_type_method)(object)
+ */
+typedef int32_t (*__pyx_t_7asyncpg_7pgproto_7pgproto_take_message_type_method)(PyObject *, char);
+
+/* "asyncpg/pgproto/buffer.pxd":58
+ * ctypedef const char * (*try_consume_message_method)(object, ssize_t*)
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ * ctypedef int32_t (*take_message_method)(object) except -1             # <<<<<<<<<<<<<<
+ * ctypedef char (*get_message_type_method)(object)
+ * 
+ */
+typedef int32_t (*__pyx_t_7asyncpg_7pgproto_7pgproto_take_message_method)(PyObject *);
+
+/* "asyncpg/pgproto/buffer.pxd":59
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ * ctypedef int32_t (*take_message_method)(object) except -1
+ * ctypedef char (*get_message_type_method)(object)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+typedef char (*__pyx_t_7asyncpg_7pgproto_7pgproto_get_message_type_method)(PyObject *);
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":14
+ * 
+ * 
+ * ctypedef object (*encode_func)(CodecContext settings,             # <<<<<<<<<<<<<<
+ *                                WriteBuffer buf,
+ *                                object obj)
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_7pgproto_7pgproto_encode_func)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":18
+ *                                object obj)
+ * 
+ * ctypedef object (*decode_func)(CodecContext settings,             # <<<<<<<<<<<<<<
+ *                                FRBuffer *buf)
+ * 
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_7pgproto_7pgproto_decode_func)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+
+/* "asyncpg/pgproto/buffer.pxd":8
+ * 
+ * 
+ * cdef class WriteBuffer:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         # Preallocated small buffer
+ */
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_vtab;
+  int _smallbuf_inuse;
+  char _smallbuf[0x400];
+  char *_buf;
+  Py_ssize_t _size;
+  Py_ssize_t _length;
+  int _view_count;
+  int _message_mode;
+};
+
+
+/* "asyncpg/pgproto/buffer.pxd":62
+ * 
+ * 
+ * cdef class ReadBuffer:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         # A deque of buffers (bytes objects)
+ */
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_vtab;
+  PyObject *_bufs;
+  PyObject *_bufs_append;
+  PyObject *_bufs_popleft;
+  PyObject *_buf0;
+  PyObject *_buf0_prev;
+  int32_t _bufs_len;
+  Py_ssize_t _pos0;
+  Py_ssize_t _len0;
+  Py_ssize_t _length;
+  char _current_message_type;
+  int32_t _current_message_len;
+  Py_ssize_t _current_message_len_unread;
+  int _current_message_ready;
+};
+
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":8
+ * 
+ * 
+ * cdef class CodecContext:             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef get_text_codec(self)
+ */
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_vtab;
+};
+
+
+
+/* "asyncpg/pgproto/buffer.pyx":18
+ * @cython.final
+ * @cython.freelist(_BUFFER_FREELIST_SIZE)
+ * cdef class WriteBuffer:             # <<<<<<<<<<<<<<
+ * 
+ *     def __cinit__(self):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer {
+  PyObject *(*len)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*_check_readonly)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*_ensure_alloced)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t);
+  PyObject *(*_reallocate)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t);
+  PyObject *(*start_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+  PyObject *(*end_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*write_buffer)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*write_byte)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+  PyObject *(*write_bytes)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*write_bytestring)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*write_str)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, PyObject *);
+  PyObject *(*write_utf8)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*write_cstr)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char const *, Py_ssize_t);
+  PyObject *(*write_int16)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int16_t);
+  PyObject *(*write_int32)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t);
+  PyObject *(*write_int64)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int64_t);
+  PyObject *(*write_float)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, float);
+  PyObject *(*write_double)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, double);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*new_message)(char);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*new)(void);
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__reallocate(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_start_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_end_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_buffer(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytestring(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_str(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char const *, Py_ssize_t);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int16_t);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int64_t);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_float(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, float);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, double);
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new_message(char);
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new(void);
+
+
+/* "asyncpg/pgproto/buffer.pyx":216
+ * @cython.final
+ * @cython.freelist(_BUFFER_FREELIST_SIZE)
+ * cdef class ReadBuffer:             # <<<<<<<<<<<<<<
+ * 
+ *     def __cinit__(self):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer {
+  PyObject *(*len)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char (*get_message_type)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int32_t (*get_message_length)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*read_utf8)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*feed_data)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, PyObject *);
+  PyObject *(*_ensure_first_buf)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*_switch_to_next_buf)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char (*read_byte)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char const *(*_try_read_bytes)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+  PyObject *(*_read_into)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char *, Py_ssize_t);
+  PyObject *(*_read_and_discard)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+  PyObject *(*read_bytes)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+  int32_t (*read_int32)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int16_t (*read_int16)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*read_cstr)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int32_t (*take_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int32_t (*take_message_type)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char);
+  int32_t (*put_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char const *(*try_consume_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t *);
+  PyObject *(*consume_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*discard_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*redirect_messages)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+  PyObject *(*consume_messages)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char);
+  PyObject *(*finish_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*_finish_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *(*new_message_parser)(PyObject *);
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_feed_data(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, PyObject *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__switch_to_next_buf(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_byte(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_into(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char *, Py_ssize_t);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_and_discard(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int32(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE int16_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int16(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_cstr(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char);
+static int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_put_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_try_consume_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_discard_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_redirect_messages(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_messages(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char);
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_finish_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_new_message_parser(PyObject *);
+
+
+/* "asyncpg/pgproto/codecs/context.pyx":8
+ * 
+ * 
+ * cdef class CodecContext:             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef get_text_codec(self):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext {
+  PyObject *(*get_text_codec)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, int __pyx_skip_dispatch);
+  PyObject *(*is_encoding_utf8)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *);
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext;
+
+/* --- Runtime support code (head) --- */
+/* Refnanny.proto */
+#ifndef CYTHON_REFNANNY
+  #define CYTHON_REFNANNY 0
+#endif
+#if CYTHON_REFNANNY
+  typedef struct {
+    void (*INCREF)(void*, PyObject*, int);
+    void (*DECREF)(void*, PyObject*, int);
+    void (*GOTREF)(void*, PyObject*, int);
+    void (*GIVEREF)(void*, PyObject*, int);
+    void* (*SetupContext)(const char*, int, const char*);
+    void (*FinishContext)(void**);
+  } __Pyx_RefNannyAPIStruct;
+  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
+  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+#ifdef WITH_THREAD
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          if (acquire_gil) {\
+              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+              PyGILState_Release(__pyx_gilstate_save);\
+          } else {\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+          }
+#else
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+#endif
+  #define __Pyx_RefNannyFinishContext()\
+          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+  #define __Pyx_RefNannyDeclarations
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)
+  #define __Pyx_RefNannyFinishContext()
+  #define __Pyx_INCREF(r) Py_INCREF(r)
+  #define __Pyx_DECREF(r) Py_DECREF(r)
+  #define __Pyx_GOTREF(r)
+  #define __Pyx_GIVEREF(r)
+  #define __Pyx_XINCREF(r) Py_XINCREF(r)
+  #define __Pyx_XDECREF(r) Py_XDECREF(r)
+  #define __Pyx_XGOTREF(r)
+  #define __Pyx_XGIVEREF(r)
+#endif
+#define __Pyx_XDECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_XDECREF(tmp);\
+    } while (0)
+#define __Pyx_DECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_DECREF(tmp);\
+    } while (0)
+#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
+#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
+
+/* PyObjectGetAttrStr.proto */
+#if CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
+#else
+#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
+#endif
+
+/* GetBuiltinName.proto */
+static PyObject *__Pyx_GetBuiltinName(PyObject *name);
+
+/* BuildPyUnicode.proto */
+static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
+                                                int prepend_sign, char padding_char);
+
+/* CIntToPyUnicode.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char);
+
+/* IncludeStringH.proto */
+#include <string.h>
+
+/* JoinPyUnicode.proto */
+static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
+                                      Py_UCS4 max_char);
+
+/* PyCFunctionFastCall.proto */
+#if CYTHON_FAST_PYCCALL
+static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
+#else
+#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
+#endif
+
+/* PyFunctionFastCall.proto */
+#if CYTHON_FAST_PYCALL
+#define __Pyx_PyFunction_FastCall(func, args, nargs)\
+    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
+#if 1 || PY_VERSION_HEX < 0x030600B1
+static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
+#else
+#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
+#endif
+#define __Pyx_BUILD_ASSERT_EXPR(cond)\
+    (sizeof(char [1 - 2*!(cond)]) - 1)
+#ifndef Py_MEMBER_SIZE
+#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
+#endif
+  static size_t __pyx_pyframe_localsplus_offset = 0;
+  #include "frameobject.h"
+  #define __Pxy_PyFrame_Initialize_Offsets()\
+    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
+     (void)(__pyx_pyframe_localsplus_offset = PyFrame_Type.tp_basicsize - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
+  #define __Pyx_PyFrame_GetLocalsplus(frame)\
+    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
+#endif
+
+/* PyObjectCall.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
+#else
+#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
+#endif
+
+/* PyObjectCallMethO.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
+#endif
+
+/* PyObjectCallOneArg.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
+
+/* PyThreadStateGet.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
+#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
+#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
+#else
+#define __Pyx_PyThreadState_declare
+#define __Pyx_PyThreadState_assign
+#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
+#endif
+
+/* PyErrFetchRestore.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
+#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
+#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
+#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
+#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
+static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
+#else
+#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
+#endif
+#else
+#define __Pyx_PyErr_Clear() PyErr_Clear()
+#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
+#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
+#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
+#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
+#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
+#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
+#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
+#endif
+
+/* RaiseException.proto */
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
+
+/* RaiseArgTupleInvalid.proto */
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
+
+/* KeywordStringCheck.proto */
+static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);
+
+/* GetModuleGlobalName.proto */
+#if CYTHON_USE_DICT_VERSIONS
+#define __Pyx_GetModuleGlobalName(var, name)  {\
+    static PY_UINT64_T __pyx_dict_version = 0;\
+    static PyObject *__pyx_dict_cached_value = NULL;\
+    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
+        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
+        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
+}
+#define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
+    PY_UINT64_T __pyx_dict_version;\
+    PyObject *__pyx_dict_cached_value;\
+    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
+}
+static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
+#else
+#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
+#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
+static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
+#endif
+
+/* PyObjectCall2Args.proto */
+static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);
+
+/* WriteUnraisableException.proto */
+static void __Pyx_WriteUnraisable(const char *name, int clineno,
+                                  int lineno, const char *filename,
+                                  int full_traceback, int nogil);
+
+/* PyObjectCallNoArg.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
+#else
+#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
+#endif
+
+/* GetItemInt.proto */
+#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
+    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
+               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
+#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
+    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
+                                                              int wraparound, int boundscheck);
+#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
+    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
+                                                              int wraparound, int boundscheck);
+static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
+                                                     int is_list, int wraparound, int boundscheck);
+
+/* None.proto */
+static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);
+
+/* PyErrExceptionMatches.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
+static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
+#else
+#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
+#endif
+
+/* GetAttr.proto */
+static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);
+
+/* GetAttr3.proto */
+static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);
+
+/* GetException.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
+static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#else
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
+#endif
+
+/* SwapException.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#else
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
+#endif
+
+/* GetTopmostException.proto */
+#if CYTHON_USE_EXC_INFO_STACK
+static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
+#endif
+
+/* SaveResetException.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
+#else
+#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
+#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
+#endif
+
+/* None.proto */
+static CYTHON_INLINE int64_t __Pyx_div_int64_t(int64_t, int64_t);
+
+/* None.proto */
+static CYTHON_INLINE int64_t __Pyx_mod_int64_t(int64_t, int64_t);
+
+/* None.proto */
+static CYTHON_INLINE long __Pyx_div_long(long, long);
+
+/* None.proto */
+static CYTHON_INLINE long __Pyx_mod_long(long, long);
+
+/* BytesEquals.proto */
+static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);
+
+/* UnicodeEquals.proto */
+static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);
+
+/* py_abs.proto */
+#if CYTHON_USE_PYLONG_INTERNALS
+static PyObject *__Pyx_PyLong_AbsNeg(PyObject *num);
+#define __Pyx_PyNumber_Absolute(x)\
+    ((likely(PyLong_CheckExact(x))) ?\
+         (likely(Py_SIZE(x) >= 0) ? (Py_INCREF(x), (x)) : __Pyx_PyLong_AbsNeg(x)) :\
+         PyNumber_Absolute(x))
+#else
+#define __Pyx_PyNumber_Absolute(x)  PyNumber_Absolute(x)
+#endif
+
+/* HasAttr.proto */
+static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);
+
+/* RaiseTooManyValuesToUnpack.proto */
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
+
+/* RaiseNeedMoreValuesToUnpack.proto */
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
+
+/* IterFinish.proto */
+static CYTHON_INLINE int __Pyx_IterFinish(void);
+
+/* UnpackItemEndCheck.proto */
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);
+
+/* PyIntBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, long intval, int inplace);
+#else
+#define __Pyx_PyInt_AddCObj(op1, op2, intval, inplace)\
+    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
+#endif
+
+/* RaiseDoubleKeywords.proto */
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
+
+/* ParseKeywords.proto */
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
+    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
+    const char* function_name);
+
+/* Import.proto */
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
+
+/* ImportFrom.proto */
+static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
+
+/* PyObject_GenericGetAttrNoDict.proto */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
+#else
+#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
+#endif
+
+/* SetVTable.proto */
+static int __Pyx_SetVtable(PyObject *dict, void *vtable);
+
+/* SetupReduce.proto */
+static int __Pyx_setup_reduce(PyObject* type_obj);
+
+/* PyObject_GenericGetAttr.proto */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
+#else
+#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
+#endif
+
+/* TypeImport.proto */
+#ifndef __PYX_HAVE_RT_ImportType_proto
+#define __PYX_HAVE_RT_ImportType_proto
+enum __Pyx_ImportType_CheckSize {
+   __Pyx_ImportType_CheckSize_Error = 0,
+   __Pyx_ImportType_CheckSize_Warn = 1,
+   __Pyx_ImportType_CheckSize_Ignore = 2
+};
+static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
+#endif
+
+/* CLineInTraceback.proto */
+#ifdef CYTHON_CLINE_IN_TRACEBACK
+#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
+#else
+static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
+#endif
+
+/* CodeObjectCache.proto */
+typedef struct {
+    PyCodeObject* code_object;
+    int code_line;
+} __Pyx_CodeObjectCacheEntry;
+struct __Pyx_CodeObjectCache {
+    int count;
+    int max_count;
+    __Pyx_CodeObjectCacheEntry* entries;
+};
+static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
+static PyCodeObject *__pyx_find_code_object(int code_line);
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
+
+/* AddTraceback.proto */
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+                               int py_line, const char *filename);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int16_t __Pyx_PyInt_As_int16_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int8_t __Pyx_PyInt_As_int8_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);
+
+/* FastTypeChecks.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
+static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
+#else
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
+#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
+#endif
+#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
+
+/* CheckBinaryVersion.proto */
+static int __Pyx_check_binary_version(void);
+
+/* FunctionExport.proto */
+static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);
+
+/* InitStrings.proto */
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, Py_ssize_t __pyx_v_extra_length); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__reallocate(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, Py_ssize_t __pyx_v_new_size); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_start_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, char __pyx_v_type); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_end_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_buffer(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, char __pyx_v_b); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_data); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytestring(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_string); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_str(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_string, PyObject *__pyx_v_encoding); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_string); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, char const *__pyx_v_data, Py_ssize_t __pyx_v_len); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, int16_t __pyx_v_i); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, int32_t __pyx_v_i); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, int64_t __pyx_v_i); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_float(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, float __pyx_v_f); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, double __pyx_v_d); /* proto*/
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new_message(char __pyx_v_type); /* proto*/
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new(void); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_feed_data(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, PyObject *__pyx_v_data); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__switch_to_next_buf(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t __pyx_v_nbytes); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_into(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, char *__pyx_v_buf, Py_ssize_t __pyx_v_nbytes); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_and_discard(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t __pyx_v_nbytes); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t __pyx_v_nbytes); /* proto*/
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_byte(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int32(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE int16_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int16(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_cstr(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_put_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_try_consume_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t *__pyx_v_len); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_discard_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_redirect_messages(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_messages(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_finish_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_new_message_parser(PyObject *__pyx_v_data); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_is_encoding_utf8(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+
+/* Module declarations from 'cython' */
+
+/* Module declarations from 'cpython.version' */
+
+/* Module declarations from '__builtin__' */
+
+/* Module declarations from 'cpython.type' */
+static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
+
+/* Module declarations from 'libc.string' */
+
+/* Module declarations from 'libc.stdio' */
+
+/* Module declarations from 'cpython.object' */
+
+/* Module declarations from 'cpython.ref' */
+
+/* Module declarations from 'cpython.exc' */
+
+/* Module declarations from 'cpython.module' */
+
+/* Module declarations from 'cpython.mem' */
+
+/* Module declarations from 'cpython.tuple' */
+
+/* Module declarations from 'cpython.list' */
+
+/* Module declarations from 'cpython.sequence' */
+
+/* Module declarations from 'cpython.mapping' */
+
+/* Module declarations from 'cpython.iterator' */
+
+/* Module declarations from 'cpython.number' */
+
+/* Module declarations from 'cpython.int' */
+
+/* Module declarations from '__builtin__' */
+
+/* Module declarations from 'cpython.bool' */
+static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;
+
+/* Module declarations from 'cpython.long' */
+
+/* Module declarations from 'cpython.float' */
+
+/* Module declarations from '__builtin__' */
+
+/* Module declarations from 'cpython.complex' */
+static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
+
+/* Module declarations from 'cpython.string' */
+
+/* Module declarations from 'cpython.unicode' */
+
+/* Module declarations from 'cpython.dict' */
+
+/* Module declarations from 'cpython.instance' */
+
+/* Module declarations from 'cpython.function' */
+
+/* Module declarations from 'cpython.method' */
+
+/* Module declarations from 'cpython.weakref' */
+
+/* Module declarations from 'cpython.getargs' */
+
+/* Module declarations from 'cpython.pythread' */
+
+/* Module declarations from 'cpython.pystate' */
+
+/* Module declarations from 'cpython.cobject' */
+
+/* Module declarations from 'cpython.oldbuffer' */
+
+/* Module declarations from 'cpython.set' */
+
+/* Module declarations from 'cpython.buffer' */
+
+/* Module declarations from 'cpython.bytes' */
+
+/* Module declarations from 'cpython.pycapsule' */
+
+/* Module declarations from 'datetime' */
+
+/* Module declarations from 'cpython.datetime' */
+static PyTypeObject *__pyx_ptype_7cpython_8datetime_date = 0;
+static PyTypeObject *__pyx_ptype_7cpython_8datetime_time = 0;
+static PyTypeObject *__pyx_ptype_7cpython_8datetime_datetime = 0;
+static PyTypeObject *__pyx_ptype_7cpython_8datetime_timedelta = 0;
+static PyTypeObject *__pyx_ptype_7cpython_8datetime_tzinfo = 0;
+static CYTHON_INLINE void __pyx_f_7cpython_8datetime_import_datetime(void); /*proto*/
+
+/* Module declarations from 'cpython' */
+
+/* Module declarations from 'libc.stdint' */
+
+/* Module declarations from 'asyncpg.pgproto' */
+
+/* Module declarations from 'asyncpg.pgproto.cpythonx' */
+
+/* Module declarations from 'asyncpg.pgproto.hton' */
+
+/* Module declarations from 'asyncpg.pgproto.debug' */
+
+/* Module declarations from 'libc' */
+
+/* Module declarations from 'libc.math' */
+
+/* Module declarations from 'asyncpg.pgproto.pgproto' */
+static PyTypeObject *__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext = 0;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_epoch_datetime_ts;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_epoch_datetime_utc_ts;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_offset_ord;
+static int64_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_infinity;
+static int64_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_negative_infinity;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_infinity;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_negative_infinity;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_datetime_ord;
+static int64_t __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_datetime_ts;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_datetime_ord;
+static int64_t __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_datetime_ts;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_date_ord;
+static int32_t __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_date_ord;
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t); /*proto*/
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_check(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, PyObject *, char **, Py_ssize_t *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_decode_pg_string(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, char const *, Py_ssize_t); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__local_timezone(void); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int64_t, int32_t); /*proto*/
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto__decode_time(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, int64_t *, int32_t *); /*proto*/
+static CYTHON_INLINE char *__pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit_stripping_lzeros(char *, int64_t); /*proto*/
+static CYTHON_INLINE char *__pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit(char *, int64_t); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__encode_points(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__decode_points(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static CYTHON_INLINE uint8_t __pyx_f_7asyncpg_7pgproto_7pgproto__ip_max_prefix_len(int32_t); /*proto*/
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto__ip_addr_len(int32_t); /*proto*/
+static CYTHON_INLINE int8_t __pyx_f_7asyncpg_7pgproto_7pgproto__ver_to_family(int32_t); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__net_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int8_t, uint32_t, int8_t, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext__set_state(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, PyObject *); /*proto*/
+#define __Pyx_MODULE_NAME "asyncpg.pgproto.pgproto"
+extern int __pyx_module_is_main_asyncpg__pgproto__pgproto;
+int __pyx_module_is_main_asyncpg__pgproto__pgproto = 0;
+
+/* Implementation of 'asyncpg.pgproto.pgproto' */
+static PyObject *__pyx_builtin_AssertionError;
+static PyObject *__pyx_builtin_MemoryError;
+static PyObject *__pyx_builtin_TypeError;
+static PyObject *__pyx_builtin_chr;
+static PyObject *__pyx_builtin_print;
+static PyObject *__pyx_builtin_NotImplementedError;
+static PyObject *__pyx_builtin_ValueError;
+static PyObject *__pyx_builtin_OverflowError;
+static PyObject *__pyx_builtin_range;
+static const char __pyx_k_F[] = "F";
+static const char __pyx_k_N[] = "N";
+static const char __pyx_k_n[] = "n";
+static const char __pyx_k_0e[] = "0e-";
+static const char __pyx_k__3[] = "";
+static const char __pyx_k__4[] = "\000";
+static const char __pyx_k_Box[] = "Box";
+static const char __pyx_k_Dec[] = "_Dec";
+static const char __pyx_k_NaN[] = "NaN";
+static const char __pyx_k_add[] = "__add__";
+static const char __pyx_k_chr[] = "chr";
+static const char __pyx_k_day[] = "day";
+static const char __pyx_k_len[] = "__len__";
+static const char __pyx_k_new[] = "__new__";
+static const char __pyx_k_now[] = "now";
+static const char __pyx_k_utc[] = "utc";
+static const char __pyx_k_Line[] = "Line";
+static const char __pyx_k_Path[] = "Path";
+static const char __pyx_k_UUID[] = "_UUID";
+static const char __pyx_k_cidr[] = "cidr";
+static const char __pyx_k_date[] = "date";
+static const char __pyx_k_days[] = "days";
+static const char __pyx_k_dict[] = "__dict__";
+static const char __pyx_k_find[] = "find";
+static const char __pyx_k_hour[] = "hour";
+static const char __pyx_k_inet[] = "inet";
+static const char __pyx_k_main[] = "__main__";
+static const char __pyx_k_name[] = "__name__";
+static const char __pyx_k_sign[] = "sign";
+static const char __pyx_k_test[] = "__test__";
+static const char __pyx_k_time[] = "time";
+static const char __pyx_k_uuid[] = "uuid";
+static const char __pyx_k_year[] = "year";
+static const char __pyx_k_Point[] = "Point";
+static const char __pyx_k_bytes[] = "bytes";
+static const char __pyx_k_deque[] = "deque";
+static const char __pyx_k_ipnet[] = "_ipnet";
+static const char __pyx_k_items[] = "items";
+static const char __pyx_k_month[] = "month";
+static const char __pyx_k_print[] = "print";
+static const char __pyx_k_range[] = "range";
+static const char __pyx_k_types[] = "types";
+static const char __pyx_k_utf_8[] = "utf-8";
+static const char __pyx_k_Circle[] = "Circle";
+static const char __pyx_k_UUID_2[] = "UUID";
+static const char __pyx_k_append[] = "append";
+static const char __pyx_k_decode[] = "decode";
+static const char __pyx_k_digits[] = "digits";
+static const char __pyx_k_encode[] = "encode";
+static const char __pyx_k_format[] = "format";
+static const char __pyx_k_import[] = "__import__";
+static const char __pyx_k_ipaddr[] = "_ipaddr";
+static const char __pyx_k_minute[] = "minute";
+static const char __pyx_k_packed[] = "packed";
+static const char __pyx_k_pickle[] = "pickle";
+static const char __pyx_k_reduce[] = "__reduce__";
+static const char __pyx_k_second[] = "second";
+static const char __pyx_k_tzinfo[] = "tzinfo";
+static const char __pyx_k_update[] = "update";
+static const char __pyx_k_Decimal[] = "Decimal";
+static const char __pyx_k_MAXYEAR[] = "MAXYEAR";
+static const char __pyx_k_MINYEAR[] = "MINYEAR";
+static const char __pyx_k_Polygon[] = "Polygon";
+static const char __pyx_k_decimal[] = "decimal";
+static const char __pyx_k_minutes[] = "minutes";
+static const char __pyx_k_popleft[] = "popleft";
+static const char __pyx_k_replace[] = "replace";
+static const char __pyx_k_seconds[] = "seconds";
+static const char __pyx_k_version[] = "version";
+static const char __pyx_k_as_tuple[] = "as_tuple";
+static const char __pyx_k_datetime[] = "datetime";
+static const char __pyx_k_exponent[] = "exponent";
+static const char __pyx_k_getstate[] = "__getstate__";
+static const char __pyx_k_pyx_type[] = "__pyx_type";
+static const char __pyx_k_setstate[] = "__setstate__";
+static const char __pyx_k_supernet[] = "supernet";
+static const char __pyx_k_timezone[] = "timezone";
+static const char __pyx_k_BitString[] = "BitString";
+static const char __pyx_k_TypeError[] = "TypeError";
+static const char __pyx_k_frombytes[] = "frombytes";
+static const char __pyx_k_ipaddress[] = "ipaddress";
+static const char __pyx_k_is_closed[] = "is_closed";
+static const char __pyx_k_prefixlen[] = "prefixlen";
+static const char __pyx_k_pyx_state[] = "__pyx_state";
+static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
+static const char __pyx_k_remaining[] = " remaining ";
+static const char __pyx_k_timedelta[] = "timedelta";
+static const char __pyx_k_timestamp[] = "timestamp";
+static const char __pyx_k_toordinal[] = "toordinal";
+static const char __pyx_k_utcoffset[] = "utcoffset";
+static const char __pyx_k_ReadBuffer[] = "ReadBuffer";
+static const char __pyx_k_ValueError[] = "ValueError";
+static const char __pyx_k_astimezone[] = "astimezone";
+static const char __pyx_k_exceptions[] = "exceptions";
+static const char __pyx_k_ip_address[] = "ip_address";
+static const char __pyx_k_ip_network[] = "ip_network";
+static const char __pyx_k_new_prefix[] = "new_prefix";
+static const char __pyx_k_pyx_result[] = "__pyx_result";
+static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
+static const char __pyx_k_BufferError[] = "BufferError";
+static const char __pyx_k_LineSegment[] = "LineSegment";
+static const char __pyx_k_MemoryError[] = "MemoryError";
+static const char __pyx_k_PickleError[] = "PickleError";
+static const char __pyx_k_WriteBuffer[] = "WriteBuffer";
+static const char __pyx_k_collections[] = "collections";
+static const char __pyx_k_fromordinal[] = "fromordinal";
+static const char __pyx_k_microsecond[] = "microsecond";
+static const char __pyx_k_CodecContext[] = "CodecContext";
+static const char __pyx_k_microseconds[] = "microseconds";
+static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
+static const char __pyx_k_stringsource[] = "stringsource";
+static const char __pyx_k_OverflowError[] = "OverflowError";
+static const char __pyx_k_infinity_date[] = "infinity_date";
+static const char __pyx_k_pg_epoch_date[] = "pg_epoch_date";
+static const char __pyx_k_pgproto_types[] = "pgproto_types";
+static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
+static const char __pyx_k_AssertionError[] = "AssertionError";
+static const char __pyx_k_get_text_codec[] = "get_text_codec";
+static const char __pyx_k_buffer_overread[] = "buffer overread";
+static const char __pyx_k_network_address[] = "network_address";
+static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
+static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
+static const char __pyx_k_string_too_long[] = "string too long";
+static const char __pyx_k_expected_str_got[] = "expected str, got {}";
+static const char __pyx_k_date_from_ordinal[] = "date_from_ordinal";
+static const char __pyx_k_infinity_datetime[] = "infinity_datetime";
+static const char __pyx_k_pg_epoch_datetime[] = "pg_epoch_datetime";
+static const char __pyx_k_bit_value_too_long[] = "bit value too long";
+static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
+static const char __pyx_k_empty_first_buffer[] = "empty first buffer";
+static const char __pyx_k_NotImplementedError[] = "NotImplementedError";
+static const char __pyx_k_path_value_too_long[] = "path value too long";
+static const char __pyx_k_no_message_to_consume[] = "no message to consume";
+static const char __pyx_k_no_message_to_discard[] = "no message to discard";
+static const char __pyx_k_pg_epoch_datetime_utc[] = "pg_epoch_datetime_utc";
+static const char __pyx_k_negative_infinity_date[] = "negative_infinity_date";
+static const char __pyx_k_polygon_value_too_long[] = "polygon value too long";
+static const char __pyx_k_asyncpg_pgproto_pgproto[] = "asyncpg.pgproto.pgproto";
+static const char __pyx_k_unexpected_JSONB_format[] = "unexpected JSONB format: {}";
+static const char __pyx_k_value_out_of_int16_range[] = "value out of int16 range";
+static const char __pyx_k_value_out_of_int32_range[] = "value out of int32 range";
+static const char __pyx_k_value_out_of_int64_range[] = "value out of int64 range";
+static const char __pyx_k_hstore_value_is_too_large[] = "hstore value is too large";
+static const char __pyx_k_pyx_unpickle_CodecContext[] = "__pyx_unpickle_CodecContext";
+static const char __pyx_k_read_cstr_buffer_overread[] = "read_cstr: buffer overread";
+static const char __pyx_k_value_out_of_uint32_range[] = "value out of uint32 range";
+static const char __pyx_k_negative_infinity_datetime[] = "negative_infinity_datetime";
+static const char __pyx_k_value_out_of_float32_range[] = "value out of float32 range";
+static const char __pyx_k_not_enough_data_to_read_bytes[] = "not enough data to read {} bytes";
+static const char __pyx_k_a_boolean_is_required_got_type[] = "a boolean is required (got type {})";
+static const char __pyx_k_consume_full_messages_called_on[] = "consume_full_messages called on a buffer without a complete first message";
+static const char __pyx_k_discarding_message_r_unread_dat[] = "!!! discarding message {!r} unread data: {!r}";
+static const char __pyx_k_end_message_buffer_is_too_small[] = "end_message: buffer is too small";
+static const char __pyx_k_feed_data_bytes_object_expected[] = "feed_data: bytes object expected";
+static const char __pyx_k_invalid_address_family_in_value[] = "invalid address family in \"{}\" value";
+static const char __pyx_k_invalid_address_length_in_value[] = "invalid address length in \"{}\" value";
+static const char __pyx_k_list_or_tuple_expected_got_type[] = "list or tuple expected (got type {})";
+static const char __pyx_k_the_buffer_is_in_read_only_mode[] = "the buffer is in read-only mode";
+static const char __pyx_k_txid_snapshot_value_is_too_long[] = "txid_snapshot value is too long";
+static const char __pyx_k_Deallocating_buffer_with_attache[] = "Deallocating buffer with attached memoryviews";
+static const char __pyx_k_Incompatible_checksums_s_vs_0xd4[] = "Incompatible checksums (%s vs 0xd41d8cd = ())";
+static const char __pyx_k_cannot_encode_Decimal_value_into[] = "cannot encode Decimal value into numeric: exponent is too small";
+static const char __pyx_k_cannot_put_message_no_message_ta[] = "cannot put message: no message taken";
+static const char __pyx_k_cannot_start_message_for_a_non_e[] = "cannot start_message for a non-empty buffer";
+static const char __pyx_k_consume_full_messages_called_wit[] = "consume_full_messages called with a wrong mtype";
+static const char __pyx_k_date_tuple_encoder_expecting_1_e[] = "date tuple encoder: expecting 1 element in tuple, got {}";
+static const char __pyx_k_debug_first_buffer_of_ReadBuffer[] = "debug: first buffer of ReadBuffer is empty";
+static const char __pyx_k_debug_second_buffer_of_ReadBuffe[] = "debug: second buffer of ReadBuffer is empty";
+static const char __pyx_k_end_message_can_only_be_called_w[] = "end_message can only be called with start_message";
+static const char __pyx_k_end_message_message_is_too_large[] = "end_message: message is too large";
+static const char __pyx_k_expected_a_datetime_date_or_date[] = "expected a datetime.date or datetime.datetime instance, got {!r}";
+static const char __pyx_k_failed_to_read_one_byte_on_a_non[] = "failed to read one byte on a non-empty buffer";
+static const char __pyx_k_insufficient_data_in_buffer_requ[] = "insufficient data in buffer: requested ";
+static const char __pyx_k_interval_tuple_encoder_expecting[] = "interval tuple encoder: expecting 3 elements in tuple, got {}";
+static const char __pyx_k_invalid_network_prefix_length_in[] = "invalid network prefix length in \"{}\" value";
+static const char __pyx_k_invalid_number_of_elements_in_ti[] = "invalid number of elements in tid tuple, expecting 2";
+static const char __pyx_k_invalid_number_of_elements_in_tx[] = "invalid number of elements in txid_snapshot tuple, expecting 4";
+static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
+static const char __pyx_k_not_enough_data_to_read_one_byte[] = "not enough data to read one byte";
+static const char __pyx_k_null_value_not_allowed_in_hstore[] = "null value not allowed in hstore key";
+static const char __pyx_k_numeric_type_does_not_support_in[] = "numeric type does not support infinite values";
+static const char __pyx_k_read_cstr_only_works_when_the_me[] = "read_cstr only works when the message guaranteed to be in the buffer";
+static const char __pyx_k_time_tuple_encoder_expecting_1_e[] = "time tuple encoder: expecting 1 element in tuple, got {}";
+static const char __pyx_k_time_tuple_encoder_expecting_2_e[] = "time tuple encoder: expecting 2 elements2 in tuple, got {}";
+static const char __pyx_k_timestamp_tuple_encoder_expectin[] = "timestamp tuple encoder: expecting 1 element in tuple, got {}";
+static const char __pyx_k_tuple_id_block_value_out_of_uint[] = "tuple id block value out of uint32 range";
+static const char __pyx_k_tuple_id_offset_value_out_of_uin[] = "tuple id offset value out of uint16 range";
+static const char __pyx_k_consume_full_messages_called_on_2[] = "consume_full_messages called on a partially read message";
+static const char __pyx_k_cannot_encode_Decimal_value_into_2[] = "cannot encode Decimal value into numeric: exponent is too large";
+static const char __pyx_k_cannot_encode_Decimal_value_into_3[] = "cannot encode Decimal value into numeric: number of digits is too large";
+static PyObject *__pyx_kp_u_0e;
+static PyObject *__pyx_n_s_AssertionError;
+static PyObject *__pyx_n_s_BitString;
+static PyObject *__pyx_n_s_Box;
+static PyObject *__pyx_n_s_BufferError;
+static PyObject *__pyx_n_s_Circle;
+static PyObject *__pyx_n_s_CodecContext;
+static PyObject *__pyx_kp_u_Deallocating_buffer_with_attache;
+static PyObject *__pyx_n_s_Dec;
+static PyObject *__pyx_n_s_Decimal;
+static PyObject *__pyx_n_u_F;
+static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xd4;
+static PyObject *__pyx_n_s_Line;
+static PyObject *__pyx_n_s_LineSegment;
+static PyObject *__pyx_n_s_MAXYEAR;
+static PyObject *__pyx_n_s_MINYEAR;
+static PyObject *__pyx_n_s_MemoryError;
+static PyObject *__pyx_n_u_N;
+static PyObject *__pyx_n_u_NaN;
+static PyObject *__pyx_n_s_NotImplementedError;
+static PyObject *__pyx_n_s_OverflowError;
+static PyObject *__pyx_n_s_Path;
+static PyObject *__pyx_n_s_PickleError;
+static PyObject *__pyx_n_s_Point;
+static PyObject *__pyx_n_s_Polygon;
+static PyObject *__pyx_n_s_ReadBuffer;
+static PyObject *__pyx_n_s_TypeError;
+static PyObject *__pyx_n_s_UUID;
+static PyObject *__pyx_n_s_UUID_2;
+static PyObject *__pyx_n_s_ValueError;
+static PyObject *__pyx_n_s_WriteBuffer;
+static PyObject *__pyx_n_s__3;
+static PyObject *__pyx_kp_b__3;
+static PyObject *__pyx_kp_b__4;
+static PyObject *__pyx_kp_u_a_boolean_is_required_got_type;
+static PyObject *__pyx_n_s_add;
+static PyObject *__pyx_n_s_append;
+static PyObject *__pyx_n_s_as_tuple;
+static PyObject *__pyx_n_s_astimezone;
+static PyObject *__pyx_n_s_asyncpg_pgproto_pgproto;
+static PyObject *__pyx_kp_u_bit_value_too_long;
+static PyObject *__pyx_kp_u_buffer_overread;
+static PyObject *__pyx_n_s_bytes;
+static PyObject *__pyx_kp_u_cannot_encode_Decimal_value_into;
+static PyObject *__pyx_kp_u_cannot_encode_Decimal_value_into_2;
+static PyObject *__pyx_kp_u_cannot_encode_Decimal_value_into_3;
+static PyObject *__pyx_kp_u_cannot_put_message_no_message_ta;
+static PyObject *__pyx_kp_u_cannot_start_message_for_a_non_e;
+static PyObject *__pyx_n_s_chr;
+static PyObject *__pyx_n_u_cidr;
+static PyObject *__pyx_n_s_cline_in_traceback;
+static PyObject *__pyx_n_s_collections;
+static PyObject *__pyx_kp_u_consume_full_messages_called_on;
+static PyObject *__pyx_kp_u_consume_full_messages_called_on_2;
+static PyObject *__pyx_kp_u_consume_full_messages_called_wit;
+static PyObject *__pyx_n_s_date;
+static PyObject *__pyx_n_s_date_from_ordinal;
+static PyObject *__pyx_kp_u_date_tuple_encoder_expecting_1_e;
+static PyObject *__pyx_n_s_datetime;
+static PyObject *__pyx_n_s_day;
+static PyObject *__pyx_n_s_days;
+static PyObject *__pyx_kp_u_debug_first_buffer_of_ReadBuffer;
+static PyObject *__pyx_kp_u_debug_second_buffer_of_ReadBuffe;
+static PyObject *__pyx_n_s_decimal;
+static PyObject *__pyx_n_s_decode;
+static PyObject *__pyx_n_s_deque;
+static PyObject *__pyx_n_s_dict;
+static PyObject *__pyx_n_s_digits;
+static PyObject *__pyx_kp_u_discarding_message_r_unread_dat;
+static PyObject *__pyx_kp_u_empty_first_buffer;
+static PyObject *__pyx_n_s_encode;
+static PyObject *__pyx_kp_u_end_message_buffer_is_too_small;
+static PyObject *__pyx_kp_u_end_message_can_only_be_called_w;
+static PyObject *__pyx_kp_u_end_message_message_is_too_large;
+static PyObject *__pyx_n_s_exceptions;
+static PyObject *__pyx_kp_u_expected_a_datetime_date_or_date;
+static PyObject *__pyx_kp_u_expected_str_got;
+static PyObject *__pyx_n_s_exponent;
+static PyObject *__pyx_kp_u_failed_to_read_one_byte_on_a_non;
+static PyObject *__pyx_kp_u_feed_data_bytes_object_expected;
+static PyObject *__pyx_n_s_find;
+static PyObject *__pyx_n_s_format;
+static PyObject *__pyx_n_s_frombytes;
+static PyObject *__pyx_n_s_fromordinal;
+static PyObject *__pyx_n_s_get_text_codec;
+static PyObject *__pyx_n_s_getstate;
+static PyObject *__pyx_n_s_hour;
+static PyObject *__pyx_kp_u_hstore_value_is_too_large;
+static PyObject *__pyx_n_s_import;
+static PyObject *__pyx_n_u_inet;
+static PyObject *__pyx_n_s_infinity_date;
+static PyObject *__pyx_n_s_infinity_datetime;
+static PyObject *__pyx_kp_u_insufficient_data_in_buffer_requ;
+static PyObject *__pyx_kp_u_interval_tuple_encoder_expecting;
+static PyObject *__pyx_kp_u_invalid_address_family_in_value;
+static PyObject *__pyx_kp_u_invalid_address_length_in_value;
+static PyObject *__pyx_kp_u_invalid_network_prefix_length_in;
+static PyObject *__pyx_kp_u_invalid_number_of_elements_in_ti;
+static PyObject *__pyx_kp_u_invalid_number_of_elements_in_tx;
+static PyObject *__pyx_n_s_ip_address;
+static PyObject *__pyx_n_s_ip_network;
+static PyObject *__pyx_n_s_ipaddr;
+static PyObject *__pyx_n_s_ipaddress;
+static PyObject *__pyx_n_s_ipnet;
+static PyObject *__pyx_n_s_is_closed;
+static PyObject *__pyx_n_s_items;
+static PyObject *__pyx_n_u_items;
+static PyObject *__pyx_n_s_len;
+static PyObject *__pyx_kp_u_list_or_tuple_expected_got_type;
+static PyObject *__pyx_n_s_main;
+static PyObject *__pyx_n_s_microsecond;
+static PyObject *__pyx_n_s_microseconds;
+static PyObject *__pyx_n_s_minute;
+static PyObject *__pyx_n_s_minutes;
+static PyObject *__pyx_n_s_month;
+static PyObject *__pyx_n_u_n;
+static PyObject *__pyx_n_s_name;
+static PyObject *__pyx_n_s_negative_infinity_date;
+static PyObject *__pyx_n_s_negative_infinity_datetime;
+static PyObject *__pyx_n_s_network_address;
+static PyObject *__pyx_n_s_new;
+static PyObject *__pyx_n_s_new_prefix;
+static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
+static PyObject *__pyx_kp_u_no_message_to_consume;
+static PyObject *__pyx_kp_u_no_message_to_discard;
+static PyObject *__pyx_kp_u_not_enough_data_to_read_bytes;
+static PyObject *__pyx_kp_u_not_enough_data_to_read_one_byte;
+static PyObject *__pyx_n_s_now;
+static PyObject *__pyx_kp_u_null_value_not_allowed_in_hstore;
+static PyObject *__pyx_kp_u_numeric_type_does_not_support_in;
+static PyObject *__pyx_n_s_packed;
+static PyObject *__pyx_kp_u_path_value_too_long;
+static PyObject *__pyx_n_s_pg_epoch_date;
+static PyObject *__pyx_n_s_pg_epoch_datetime;
+static PyObject *__pyx_n_s_pg_epoch_datetime_utc;
+static PyObject *__pyx_n_s_pgproto_types;
+static PyObject *__pyx_n_s_pickle;
+static PyObject *__pyx_kp_u_polygon_value_too_long;
+static PyObject *__pyx_n_s_popleft;
+static PyObject *__pyx_n_s_prefixlen;
+static PyObject *__pyx_n_s_print;
+static PyObject *__pyx_n_s_pyx_PickleError;
+static PyObject *__pyx_n_s_pyx_checksum;
+static PyObject *__pyx_n_s_pyx_result;
+static PyObject *__pyx_n_s_pyx_state;
+static PyObject *__pyx_n_s_pyx_type;
+static PyObject *__pyx_n_s_pyx_unpickle_CodecContext;
+static PyObject *__pyx_n_s_pyx_vtable;
+static PyObject *__pyx_n_s_range;
+static PyObject *__pyx_kp_u_read_cstr_buffer_overread;
+static PyObject *__pyx_kp_u_read_cstr_only_works_when_the_me;
+static PyObject *__pyx_n_s_reduce;
+static PyObject *__pyx_n_s_reduce_cython;
+static PyObject *__pyx_n_s_reduce_ex;
+static PyObject *__pyx_kp_u_remaining;
+static PyObject *__pyx_n_s_replace;
+static PyObject *__pyx_n_s_second;
+static PyObject *__pyx_n_s_seconds;
+static PyObject *__pyx_n_s_setstate;
+static PyObject *__pyx_n_s_setstate_cython;
+static PyObject *__pyx_n_s_sign;
+static PyObject *__pyx_kp_u_string_too_long;
+static PyObject *__pyx_kp_s_stringsource;
+static PyObject *__pyx_n_s_supernet;
+static PyObject *__pyx_n_s_test;
+static PyObject *__pyx_kp_u_the_buffer_is_in_read_only_mode;
+static PyObject *__pyx_n_s_time;
+static PyObject *__pyx_kp_u_time_tuple_encoder_expecting_1_e;
+static PyObject *__pyx_kp_u_time_tuple_encoder_expecting_2_e;
+static PyObject *__pyx_n_s_timedelta;
+static PyObject *__pyx_n_s_timestamp;
+static PyObject *__pyx_kp_u_timestamp_tuple_encoder_expectin;
+static PyObject *__pyx_n_s_timezone;
+static PyObject *__pyx_n_s_toordinal;
+static PyObject *__pyx_kp_u_tuple_id_block_value_out_of_uint;
+static PyObject *__pyx_kp_u_tuple_id_offset_value_out_of_uin;
+static PyObject *__pyx_kp_u_txid_snapshot_value_is_too_long;
+static PyObject *__pyx_n_s_types;
+static PyObject *__pyx_n_s_tzinfo;
+static PyObject *__pyx_kp_u_unexpected_JSONB_format;
+static PyObject *__pyx_n_s_update;
+static PyObject *__pyx_n_s_utc;
+static PyObject *__pyx_n_s_utcoffset;
+static PyObject *__pyx_kp_u_utf_8;
+static PyObject *__pyx_n_s_uuid;
+static PyObject *__pyx_kp_u_value_out_of_float32_range;
+static PyObject *__pyx_kp_u_value_out_of_int16_range;
+static PyObject *__pyx_kp_u_value_out_of_int32_range;
+static PyObject *__pyx_kp_u_value_out_of_int64_range;
+static PyObject *__pyx_kp_u_value_out_of_uint32_range;
+static PyObject *__pyx_n_s_version;
+static PyObject *__pyx_n_s_year;
+static int __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer___cinit__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto */
+static void __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_2__dealloc__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto */
+static int __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_4__getbuffer__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, Py_buffer *__pyx_v_buffer, int __pyx_v_flags); /* proto */
+static void __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_6__releasebuffer__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, CYTHON_UNUSED Py_buffer *__pyx_v_buffer); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
+static int __pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer___cinit__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer_2__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer_4__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_2__reduce_cython__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_4__setstate_cython__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_tp_new_7asyncpg_7pgproto_7pgproto_WriteBuffer(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_7pgproto_7pgproto_ReadBuffer(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_7pgproto_7pgproto_CodecContext(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_int_0;
+static PyObject *__pyx_int_1;
+static PyObject *__pyx_int_10;
+static PyObject *__pyx_int_12;
+static PyObject *__pyx_int_20;
+static PyObject *__pyx_int_23;
+static PyObject *__pyx_int_31;
+static PyObject *__pyx_int_59;
+static PyObject *__pyx_int_100;
+static PyObject *__pyx_int_1000;
+static PyObject *__pyx_int_2000;
+static PyObject *__pyx_int_999999;
+static PyObject *__pyx_int_222419149;
+static PyObject *__pyx_tuple_;
+static PyObject *__pyx_tuple__2;
+static PyObject *__pyx_tuple__5;
+static PyObject *__pyx_tuple__6;
+static PyObject *__pyx_tuple__7;
+static PyObject *__pyx_tuple__8;
+static PyObject *__pyx_tuple__9;
+static PyObject *__pyx_tuple__10;
+static PyObject *__pyx_tuple__11;
+static PyObject *__pyx_tuple__12;
+static PyObject *__pyx_tuple__13;
+static PyObject *__pyx_tuple__14;
+static PyObject *__pyx_tuple__15;
+static PyObject *__pyx_tuple__16;
+static PyObject *__pyx_tuple__17;
+static PyObject *__pyx_tuple__18;
+static PyObject *__pyx_tuple__19;
+static PyObject *__pyx_tuple__20;
+static PyObject *__pyx_tuple__21;
+static PyObject *__pyx_tuple__22;
+static PyObject *__pyx_tuple__23;
+static PyObject *__pyx_tuple__24;
+static PyObject *__pyx_tuple__25;
+static PyObject *__pyx_tuple__26;
+static PyObject *__pyx_tuple__27;
+static PyObject *__pyx_tuple__28;
+static PyObject *__pyx_tuple__29;
+static PyObject *__pyx_codeobj__30;
+/* Late includes */
+
+/* "asyncpg/pgproto/frb.pyx":8
+ * 
+ * 
+ * cdef object frb_check(FRBuffer *frb, ssize_t n):             # <<<<<<<<<<<<<<
+ *     if n > frb.len:
+ *         raise AssertionError(
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_check(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, Py_ssize_t __pyx_v_n) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  Py_UCS4 __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("frb_check", 0);
+
+  /* "asyncpg/pgproto/frb.pyx":9
+ * 
+ * cdef object frb_check(FRBuffer *frb, ssize_t n):
+ *     if n > frb.len:             # <<<<<<<<<<<<<<
+ *         raise AssertionError(
+ *             f'insufficient data in buffer: requested {n} '
+ */
+  __pyx_t_1 = ((__pyx_v_n > __pyx_v_frb->len) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/frb.pyx":11
+ *     if n > frb.len:
+ *         raise AssertionError(
+ *             f'insufficient data in buffer: requested {n} '             # <<<<<<<<<<<<<<
+ *             f'remaining {frb.len}')
+ */
+    __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_3 = 0;
+    __pyx_t_4 = 127;
+    __Pyx_INCREF(__pyx_kp_u_insufficient_data_in_buffer_requ);
+    __pyx_t_3 += 39;
+    __Pyx_GIVEREF(__pyx_kp_u_insufficient_data_in_buffer_requ);
+    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_insufficient_data_in_buffer_requ);
+    __pyx_t_5 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_v_n, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
+    __pyx_t_5 = 0;
+    __Pyx_INCREF(__pyx_kp_u_remaining);
+    __pyx_t_3 += 11;
+    __Pyx_GIVEREF(__pyx_kp_u_remaining);
+    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_remaining);
+
+    /* "asyncpg/pgproto/frb.pyx":12
+ *         raise AssertionError(
+ *             f'insufficient data in buffer: requested {n} '
+ *             f'remaining {frb.len}')             # <<<<<<<<<<<<<<
+ */
+    __pyx_t_5 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_v_frb->len, 0, ' ', 'd'); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_5);
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/frb.pyx":11
+ *     if n > frb.len:
+ *         raise AssertionError(
+ *             f'insufficient data in buffer: requested {n} '             # <<<<<<<<<<<<<<
+ *             f'remaining {frb.len}')
+ */
+    __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 4, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/frb.pyx":10
+ * cdef object frb_check(FRBuffer *frb, ssize_t n):
+ *     if n > frb.len:
+ *         raise AssertionError(             # <<<<<<<<<<<<<<
+ *             f'insufficient data in buffer: requested {n} '
+ *             f'remaining {frb.len}')
+ */
+    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_AssertionError, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(0, 10, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/frb.pyx":9
+ * 
+ * cdef object frb_check(FRBuffer *frb, ssize_t n):
+ *     if n > frb.len:             # <<<<<<<<<<<<<<
+ *         raise AssertionError(
+ *             f'insufficient data in buffer: requested {n} '
+ */
+  }
+
+  /* "asyncpg/pgproto/frb.pyx":8
+ * 
+ * 
+ * cdef object frb_check(FRBuffer *frb, ssize_t n):             # <<<<<<<<<<<<<<
+ *     if n > frb.len:
+ *         raise AssertionError(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.frb_check", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":20
+ * cdef class WriteBuffer:
+ * 
+ *     def __cinit__(self):             # <<<<<<<<<<<<<<
+ *         self._smallbuf_inuse = True
+ *         self._buf = self._smallbuf
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
+    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
+  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer___cinit__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer___cinit__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  char *__pyx_t_1;
+  __Pyx_RefNannySetupContext("__cinit__", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":21
+ * 
+ *     def __cinit__(self):
+ *         self._smallbuf_inuse = True             # <<<<<<<<<<<<<<
+ *         self._buf = self._smallbuf
+ *         self._size = _BUFFER_INITIAL_SIZE
+ */
+  __pyx_v_self->_smallbuf_inuse = 1;
+
+  /* "asyncpg/pgproto/buffer.pyx":22
+ *     def __cinit__(self):
+ *         self._smallbuf_inuse = True
+ *         self._buf = self._smallbuf             # <<<<<<<<<<<<<<
+ *         self._size = _BUFFER_INITIAL_SIZE
+ *         self._length = 0
+ */
+  __pyx_t_1 = __pyx_v_self->_smallbuf;
+  __pyx_v_self->_buf = __pyx_t_1;
+
+  /* "asyncpg/pgproto/buffer.pyx":23
+ *         self._smallbuf_inuse = True
+ *         self._buf = self._smallbuf
+ *         self._size = _BUFFER_INITIAL_SIZE             # <<<<<<<<<<<<<<
+ *         self._length = 0
+ *         self._message_mode = 0
+ */
+  __pyx_v_self->_size = 0x400;
+
+  /* "asyncpg/pgproto/buffer.pyx":24
+ *         self._buf = self._smallbuf
+ *         self._size = _BUFFER_INITIAL_SIZE
+ *         self._length = 0             # <<<<<<<<<<<<<<
+ *         self._message_mode = 0
+ * 
+ */
+  __pyx_v_self->_length = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":25
+ *         self._size = _BUFFER_INITIAL_SIZE
+ *         self._length = 0
+ *         self._message_mode = 0             # <<<<<<<<<<<<<<
+ * 
+ *     def __dealloc__(self):
+ */
+  __pyx_v_self->_message_mode = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":20
+ * cdef class WriteBuffer:
+ * 
+ *     def __cinit__(self):             # <<<<<<<<<<<<<<
+ *         self._smallbuf_inuse = True
+ *         self._buf = self._smallbuf
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":27
+ *         self._message_mode = 0
+ * 
+ *     def __dealloc__(self):             # <<<<<<<<<<<<<<
+ *         if self._buf is not NULL and not self._smallbuf_inuse:
+ *             cpython.PyMem_Free(self._buf)
+ */
+
+/* Python wrapper */
+static void __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_3__dealloc__(PyObject *__pyx_v_self) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+  __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_2__dealloc__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+static void __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_2__dealloc__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("__dealloc__", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":28
+ * 
+ *     def __dealloc__(self):
+ *         if self._buf is not NULL and not self._smallbuf_inuse:             # <<<<<<<<<<<<<<
+ *             cpython.PyMem_Free(self._buf)
+ *             self._buf = NULL
+ */
+  __pyx_t_2 = ((__pyx_v_self->_buf != NULL) != 0);
+  if (__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = ((!(__pyx_v_self->_smallbuf_inuse != 0)) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":29
+ *     def __dealloc__(self):
+ *         if self._buf is not NULL and not self._smallbuf_inuse:
+ *             cpython.PyMem_Free(self._buf)             # <<<<<<<<<<<<<<
+ *             self._buf = NULL
+ *             self._size = 0
+ */
+    PyMem_Free(__pyx_v_self->_buf);
+
+    /* "asyncpg/pgproto/buffer.pyx":30
+ *         if self._buf is not NULL and not self._smallbuf_inuse:
+ *             cpython.PyMem_Free(self._buf)
+ *             self._buf = NULL             # <<<<<<<<<<<<<<
+ *             self._size = 0
+ * 
+ */
+    __pyx_v_self->_buf = NULL;
+
+    /* "asyncpg/pgproto/buffer.pyx":31
+ *             cpython.PyMem_Free(self._buf)
+ *             self._buf = NULL
+ *             self._size = 0             # <<<<<<<<<<<<<<
+ * 
+ *         if self._view_count:
+ */
+    __pyx_v_self->_size = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":28
+ * 
+ *     def __dealloc__(self):
+ *         if self._buf is not NULL and not self._smallbuf_inuse:             # <<<<<<<<<<<<<<
+ *             cpython.PyMem_Free(self._buf)
+ *             self._buf = NULL
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":33
+ *             self._size = 0
+ * 
+ *         if self._view_count:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'Deallocating buffer with attached memoryviews')
+ */
+  __pyx_t_1 = (__pyx_v_self->_view_count != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":34
+ * 
+ *         if self._view_count:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'Deallocating buffer with attached memoryviews')
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 34, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 34, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_Deallocating_buffer_with_attache) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_Deallocating_buffer_with_attache);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 34, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(1, 34, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":33
+ *             self._size = 0
+ * 
+ *         if self._view_count:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'Deallocating buffer with attached memoryviews')
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":27
+ *         self._message_mode = 0
+ * 
+ *     def __dealloc__(self):             # <<<<<<<<<<<<<<
+ *         if self._buf is not NULL and not self._smallbuf_inuse:
+ *             cpython.PyMem_Free(self._buf)
+ */
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_WriteUnraisable("asyncpg.pgproto.pgproto.WriteBuffer.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "asyncpg/pgproto/buffer.pyx":37
+ *                 'Deallocating buffer with attached memoryviews')
+ * 
+ *     def __getbuffer__(self, Py_buffer *buffer, int flags):             # <<<<<<<<<<<<<<
+ *         self._view_count += 1
+ * 
+ */
+
+/* Python wrapper */
+static CYTHON_UNUSED int __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_5__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_buffer, int __pyx_v_flags); /*proto*/
+static CYTHON_UNUSED int __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_5__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_buffer, int __pyx_v_flags) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_4__getbuffer__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_self), ((Py_buffer *)__pyx_v_buffer), ((int)__pyx_v_flags));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_4__getbuffer__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, Py_buffer *__pyx_v_buffer, int __pyx_v_flags) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  if (__pyx_v_buffer == NULL) {
+    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
+    return -1;
+  }
+  __Pyx_RefNannySetupContext("__getbuffer__", 0);
+  __pyx_v_buffer->obj = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(__pyx_v_buffer->obj);
+
+  /* "asyncpg/pgproto/buffer.pyx":38
+ * 
+ *     def __getbuffer__(self, Py_buffer *buffer, int flags):
+ *         self._view_count += 1             # <<<<<<<<<<<<<<
+ * 
+ *         cpython.PyBuffer_FillInfo(
+ */
+  __pyx_v_self->_view_count = (__pyx_v_self->_view_count + 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":40
+ *         self._view_count += 1
+ * 
+ *         cpython.PyBuffer_FillInfo(             # <<<<<<<<<<<<<<
+ *             buffer, self, self._buf, self._length,
+ *             1,  # read-only
+ */
+  __pyx_t_1 = PyBuffer_FillInfo(__pyx_v_buffer, ((PyObject *)__pyx_v_self), __pyx_v_self->_buf, __pyx_v_self->_length, 1, __pyx_v_flags); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 40, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/buffer.pyx":37
+ *                 'Deallocating buffer with attached memoryviews')
+ * 
+ *     def __getbuffer__(self, Py_buffer *buffer, int flags):             # <<<<<<<<<<<<<<
+ *         self._view_count += 1
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  if (__pyx_v_buffer->obj != NULL) {
+    __Pyx_GOTREF(__pyx_v_buffer->obj);
+    __Pyx_DECREF(__pyx_v_buffer->obj); __pyx_v_buffer->obj = 0;
+  }
+  goto __pyx_L2;
+  __pyx_L0:;
+  if (__pyx_v_buffer->obj == Py_None) {
+    __Pyx_GOTREF(__pyx_v_buffer->obj);
+    __Pyx_DECREF(__pyx_v_buffer->obj); __pyx_v_buffer->obj = 0;
+  }
+  __pyx_L2:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":45
+ *             flags)
+ * 
+ *     def __releasebuffer__(self, Py_buffer *buffer):             # <<<<<<<<<<<<<<
+ *         self._view_count -= 1
+ * 
+ */
+
+/* Python wrapper */
+static CYTHON_UNUSED void __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_7__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_buffer); /*proto*/
+static CYTHON_UNUSED void __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_7__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_buffer) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
+  __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_6__releasebuffer__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_self), ((Py_buffer *)__pyx_v_buffer));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+static void __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_6__releasebuffer__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, CYTHON_UNUSED Py_buffer *__pyx_v_buffer) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__releasebuffer__", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":46
+ * 
+ *     def __releasebuffer__(self, Py_buffer *buffer):
+ *         self._view_count -= 1             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _check_readonly(self):
+ */
+  __pyx_v_self->_view_count = (__pyx_v_self->_view_count - 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":45
+ *             flags)
+ * 
+ *     def __releasebuffer__(self, Py_buffer *buffer):             # <<<<<<<<<<<<<<
+ *         self._view_count -= 1
+ * 
+ */
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "asyncpg/pgproto/buffer.pyx":48
+ *         self._view_count -= 1
+ * 
+ *     cdef inline _check_readonly(self):             # <<<<<<<<<<<<<<
+ *         if self._view_count:
+ *             raise exceptions.BufferError('the buffer is in read-only mode')
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_check_readonly", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":49
+ * 
+ *     cdef inline _check_readonly(self):
+ *         if self._view_count:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('the buffer is in read-only mode')
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_self->_view_count != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":50
+ *     cdef inline _check_readonly(self):
+ *         if self._view_count:
+ *             raise exceptions.BufferError('the buffer is in read-only mode')             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _ensure_alloced(self, ssize_t extra_length):
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 50, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 50, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_the_buffer_is_in_read_only_mode) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_the_buffer_is_in_read_only_mode);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 50, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 50, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":49
+ * 
+ *     cdef inline _check_readonly(self):
+ *         if self._view_count:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('the buffer is in read-only mode')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":48
+ *         self._view_count -= 1
+ * 
+ *     cdef inline _check_readonly(self):             # <<<<<<<<<<<<<<
+ *         if self._view_count:
+ *             raise exceptions.BufferError('the buffer is in read-only mode')
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer._check_readonly", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":52
+ *             raise exceptions.BufferError('the buffer is in read-only mode')
+ * 
+ *     cdef inline _ensure_alloced(self, ssize_t extra_length):             # <<<<<<<<<<<<<<
+ *         cdef ssize_t new_size = extra_length + self._length
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, Py_ssize_t __pyx_v_extra_length) {
+  Py_ssize_t __pyx_v_new_size;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_ensure_alloced", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":53
+ * 
+ *     cdef inline _ensure_alloced(self, ssize_t extra_length):
+ *         cdef ssize_t new_size = extra_length + self._length             # <<<<<<<<<<<<<<
+ * 
+ *         if new_size > self._size:
+ */
+  __pyx_v_new_size = (__pyx_v_extra_length + __pyx_v_self->_length);
+
+  /* "asyncpg/pgproto/buffer.pyx":55
+ *         cdef ssize_t new_size = extra_length + self._length
+ * 
+ *         if new_size > self._size:             # <<<<<<<<<<<<<<
+ *             self._reallocate(new_size)
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_new_size > __pyx_v_self->_size) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":56
+ * 
+ *         if new_size > self._size:
+ *             self._reallocate(new_size)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _reallocate(self, ssize_t new_size):
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__reallocate(__pyx_v_self, __pyx_v_new_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 56, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":55
+ *         cdef ssize_t new_size = extra_length + self._length
+ * 
+ *         if new_size > self._size:             # <<<<<<<<<<<<<<
+ *             self._reallocate(new_size)
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":52
+ *             raise exceptions.BufferError('the buffer is in read-only mode')
+ * 
+ *     cdef inline _ensure_alloced(self, ssize_t extra_length):             # <<<<<<<<<<<<<<
+ *         cdef ssize_t new_size = extra_length + self._length
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer._ensure_alloced", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":58
+ *             self._reallocate(new_size)
+ * 
+ *     cdef _reallocate(self, ssize_t new_size):             # <<<<<<<<<<<<<<
+ *         cdef char *new_buf
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__reallocate(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, Py_ssize_t __pyx_v_new_size) {
+  char *__pyx_v_new_buf;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("_reallocate", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":61
+ *         cdef char *new_buf
+ * 
+ *         if new_size < _BUFFER_MAX_GROW:             # <<<<<<<<<<<<<<
+ *             new_size = _BUFFER_MAX_GROW
+ *         else:
+ */
+  __pyx_t_1 = ((__pyx_v_new_size < 0x10000) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":62
+ * 
+ *         if new_size < _BUFFER_MAX_GROW:
+ *             new_size = _BUFFER_MAX_GROW             # <<<<<<<<<<<<<<
+ *         else:
+ *             # Add a little extra
+ */
+    __pyx_v_new_size = 0x10000;
+
+    /* "asyncpg/pgproto/buffer.pyx":61
+ *         cdef char *new_buf
+ * 
+ *         if new_size < _BUFFER_MAX_GROW:             # <<<<<<<<<<<<<<
+ *             new_size = _BUFFER_MAX_GROW
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":65
+ *         else:
+ *             # Add a little extra
+ *             new_size += _BUFFER_INITIAL_SIZE             # <<<<<<<<<<<<<<
+ * 
+ *         if self._smallbuf_inuse:
+ */
+  /*else*/ {
+    __pyx_v_new_size = (__pyx_v_new_size + 0x400);
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/buffer.pyx":67
+ *             new_size += _BUFFER_INITIAL_SIZE
+ * 
+ *         if self._smallbuf_inuse:             # <<<<<<<<<<<<<<
+ *             new_buf = <char*>cpython.PyMem_Malloc(
+ *                 sizeof(char) * <size_t>new_size)
+ */
+  __pyx_t_1 = (__pyx_v_self->_smallbuf_inuse != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":68
+ * 
+ *         if self._smallbuf_inuse:
+ *             new_buf = <char*>cpython.PyMem_Malloc(             # <<<<<<<<<<<<<<
+ *                 sizeof(char) * <size_t>new_size)
+ *             if new_buf is NULL:
+ */
+    __pyx_v_new_buf = ((char *)PyMem_Malloc(((sizeof(char)) * ((size_t)__pyx_v_new_size))));
+
+    /* "asyncpg/pgproto/buffer.pyx":70
+ *             new_buf = <char*>cpython.PyMem_Malloc(
+ *                 sizeof(char) * <size_t>new_size)
+ *             if new_buf is NULL:             # <<<<<<<<<<<<<<
+ *                 self._buf = NULL
+ *                 self._size = 0
+ */
+    __pyx_t_1 = ((__pyx_v_new_buf == NULL) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/pgproto/buffer.pyx":71
+ *                 sizeof(char) * <size_t>new_size)
+ *             if new_buf is NULL:
+ *                 self._buf = NULL             # <<<<<<<<<<<<<<
+ *                 self._size = 0
+ *                 self._length = 0
+ */
+      __pyx_v_self->_buf = NULL;
+
+      /* "asyncpg/pgproto/buffer.pyx":72
+ *             if new_buf is NULL:
+ *                 self._buf = NULL
+ *                 self._size = 0             # <<<<<<<<<<<<<<
+ *                 self._length = 0
+ *                 raise MemoryError
+ */
+      __pyx_v_self->_size = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":73
+ *                 self._buf = NULL
+ *                 self._size = 0
+ *                 self._length = 0             # <<<<<<<<<<<<<<
+ *                 raise MemoryError
+ *             memcpy(new_buf, self._buf, <size_t>self._size)
+ */
+      __pyx_v_self->_length = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":74
+ *                 self._size = 0
+ *                 self._length = 0
+ *                 raise MemoryError             # <<<<<<<<<<<<<<
+ *             memcpy(new_buf, self._buf, <size_t>self._size)
+ *             self._size = new_size
+ */
+      PyErr_NoMemory(); __PYX_ERR(1, 74, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/buffer.pyx":70
+ *             new_buf = <char*>cpython.PyMem_Malloc(
+ *                 sizeof(char) * <size_t>new_size)
+ *             if new_buf is NULL:             # <<<<<<<<<<<<<<
+ *                 self._buf = NULL
+ *                 self._size = 0
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":75
+ *                 self._length = 0
+ *                 raise MemoryError
+ *             memcpy(new_buf, self._buf, <size_t>self._size)             # <<<<<<<<<<<<<<
+ *             self._size = new_size
+ *             self._buf = new_buf
+ */
+    (void)(memcpy(__pyx_v_new_buf, __pyx_v_self->_buf, ((size_t)__pyx_v_self->_size)));
+
+    /* "asyncpg/pgproto/buffer.pyx":76
+ *                 raise MemoryError
+ *             memcpy(new_buf, self._buf, <size_t>self._size)
+ *             self._size = new_size             # <<<<<<<<<<<<<<
+ *             self._buf = new_buf
+ *             self._smallbuf_inuse = False
+ */
+    __pyx_v_self->_size = __pyx_v_new_size;
+
+    /* "asyncpg/pgproto/buffer.pyx":77
+ *             memcpy(new_buf, self._buf, <size_t>self._size)
+ *             self._size = new_size
+ *             self._buf = new_buf             # <<<<<<<<<<<<<<
+ *             self._smallbuf_inuse = False
+ *         else:
+ */
+    __pyx_v_self->_buf = __pyx_v_new_buf;
+
+    /* "asyncpg/pgproto/buffer.pyx":78
+ *             self._size = new_size
+ *             self._buf = new_buf
+ *             self._smallbuf_inuse = False             # <<<<<<<<<<<<<<
+ *         else:
+ *             new_buf = <char*>cpython.PyMem_Realloc(
+ */
+    __pyx_v_self->_smallbuf_inuse = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":67
+ *             new_size += _BUFFER_INITIAL_SIZE
+ * 
+ *         if self._smallbuf_inuse:             # <<<<<<<<<<<<<<
+ *             new_buf = <char*>cpython.PyMem_Malloc(
+ *                 sizeof(char) * <size_t>new_size)
+ */
+    goto __pyx_L4;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":80
+ *             self._smallbuf_inuse = False
+ *         else:
+ *             new_buf = <char*>cpython.PyMem_Realloc(             # <<<<<<<<<<<<<<
+ *                 <void*>self._buf, <size_t>new_size)
+ *             if new_buf is NULL:
+ */
+  /*else*/ {
+
+    /* "asyncpg/pgproto/buffer.pyx":81
+ *         else:
+ *             new_buf = <char*>cpython.PyMem_Realloc(
+ *                 <void*>self._buf, <size_t>new_size)             # <<<<<<<<<<<<<<
+ *             if new_buf is NULL:
+ *                 cpython.PyMem_Free(self._buf)
+ */
+    __pyx_v_new_buf = ((char *)PyMem_Realloc(((void *)__pyx_v_self->_buf), ((size_t)__pyx_v_new_size)));
+
+    /* "asyncpg/pgproto/buffer.pyx":82
+ *             new_buf = <char*>cpython.PyMem_Realloc(
+ *                 <void*>self._buf, <size_t>new_size)
+ *             if new_buf is NULL:             # <<<<<<<<<<<<<<
+ *                 cpython.PyMem_Free(self._buf)
+ *                 self._buf = NULL
+ */
+    __pyx_t_1 = ((__pyx_v_new_buf == NULL) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/pgproto/buffer.pyx":83
+ *                 <void*>self._buf, <size_t>new_size)
+ *             if new_buf is NULL:
+ *                 cpython.PyMem_Free(self._buf)             # <<<<<<<<<<<<<<
+ *                 self._buf = NULL
+ *                 self._size = 0
+ */
+      PyMem_Free(__pyx_v_self->_buf);
+
+      /* "asyncpg/pgproto/buffer.pyx":84
+ *             if new_buf is NULL:
+ *                 cpython.PyMem_Free(self._buf)
+ *                 self._buf = NULL             # <<<<<<<<<<<<<<
+ *                 self._size = 0
+ *                 self._length = 0
+ */
+      __pyx_v_self->_buf = NULL;
+
+      /* "asyncpg/pgproto/buffer.pyx":85
+ *                 cpython.PyMem_Free(self._buf)
+ *                 self._buf = NULL
+ *                 self._size = 0             # <<<<<<<<<<<<<<
+ *                 self._length = 0
+ *                 raise MemoryError
+ */
+      __pyx_v_self->_size = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":86
+ *                 self._buf = NULL
+ *                 self._size = 0
+ *                 self._length = 0             # <<<<<<<<<<<<<<
+ *                 raise MemoryError
+ *             self._buf = new_buf
+ */
+      __pyx_v_self->_length = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":87
+ *                 self._size = 0
+ *                 self._length = 0
+ *                 raise MemoryError             # <<<<<<<<<<<<<<
+ *             self._buf = new_buf
+ *             self._size = new_size
+ */
+      PyErr_NoMemory(); __PYX_ERR(1, 87, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/buffer.pyx":82
+ *             new_buf = <char*>cpython.PyMem_Realloc(
+ *                 <void*>self._buf, <size_t>new_size)
+ *             if new_buf is NULL:             # <<<<<<<<<<<<<<
+ *                 cpython.PyMem_Free(self._buf)
+ *                 self._buf = NULL
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":88
+ *                 self._length = 0
+ *                 raise MemoryError
+ *             self._buf = new_buf             # <<<<<<<<<<<<<<
+ *             self._size = new_size
+ * 
+ */
+    __pyx_v_self->_buf = __pyx_v_new_buf;
+
+    /* "asyncpg/pgproto/buffer.pyx":89
+ *                 raise MemoryError
+ *             self._buf = new_buf
+ *             self._size = new_size             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline start_message(self, char type):
+ */
+    __pyx_v_self->_size = __pyx_v_new_size;
+  }
+  __pyx_L4:;
+
+  /* "asyncpg/pgproto/buffer.pyx":58
+ *             self._reallocate(new_size)
+ * 
+ *     cdef _reallocate(self, ssize_t new_size):             # <<<<<<<<<<<<<<
+ *         cdef char *new_buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer._reallocate", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":91
+ *             self._size = new_size
+ * 
+ *     cdef inline start_message(self, char type):             # <<<<<<<<<<<<<<
+ *         if self._length != 0:
+ *             raise exceptions.BufferError(
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_start_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, char __pyx_v_type) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("start_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":92
+ * 
+ *     cdef inline start_message(self, char type):
+ *         if self._length != 0:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'cannot start_message for a non-empty buffer')
+ */
+  __pyx_t_1 = ((__pyx_v_self->_length != 0) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":93
+ *     cdef inline start_message(self, char type):
+ *         if self._length != 0:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'cannot start_message for a non-empty buffer')
+ *         self._ensure_alloced(5)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 93, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 93, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_cannot_start_message_for_a_non_e) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_cannot_start_message_for_a_non_e);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 93, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 93, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":92
+ * 
+ *     cdef inline start_message(self, char type):
+ *         if self._length != 0:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'cannot start_message for a non-empty buffer')
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":95
+ *             raise exceptions.BufferError(
+ *                 'cannot start_message for a non-empty buffer')
+ *         self._ensure_alloced(5)             # <<<<<<<<<<<<<<
+ *         self._message_mode = 1
+ *         self._buf[0] = type
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 5); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 95, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":96
+ *                 'cannot start_message for a non-empty buffer')
+ *         self._ensure_alloced(5)
+ *         self._message_mode = 1             # <<<<<<<<<<<<<<
+ *         self._buf[0] = type
+ *         self._length = 5
+ */
+  __pyx_v_self->_message_mode = 1;
+
+  /* "asyncpg/pgproto/buffer.pyx":97
+ *         self._ensure_alloced(5)
+ *         self._message_mode = 1
+ *         self._buf[0] = type             # <<<<<<<<<<<<<<
+ *         self._length = 5
+ * 
+ */
+  (__pyx_v_self->_buf[0]) = __pyx_v_type;
+
+  /* "asyncpg/pgproto/buffer.pyx":98
+ *         self._message_mode = 1
+ *         self._buf[0] = type
+ *         self._length = 5             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline end_message(self):
+ */
+  __pyx_v_self->_length = 5;
+
+  /* "asyncpg/pgproto/buffer.pyx":91
+ *             self._size = new_size
+ * 
+ *     cdef inline start_message(self, char type):             # <<<<<<<<<<<<<<
+ *         if self._length != 0:
+ *             raise exceptions.BufferError(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.start_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":100
+ *         self._length = 5
+ * 
+ *     cdef inline end_message(self):             # <<<<<<<<<<<<<<
+ *         # "length-1" to exclude the message type byte
+ *         cdef ssize_t mlen = self._length - 1
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_end_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  Py_ssize_t __pyx_v_mlen;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("end_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":102
+ *     cdef inline end_message(self):
+ *         # "length-1" to exclude the message type byte
+ *         cdef ssize_t mlen = self._length - 1             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_readonly()
+ */
+  __pyx_v_mlen = (__pyx_v_self->_length - 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":104
+ *         cdef ssize_t mlen = self._length - 1
+ * 
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         if not self._message_mode:
+ *             raise exceptions.BufferError(
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":105
+ * 
+ *         self._check_readonly()
+ *         if not self._message_mode:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'end_message can only be called with start_message')
+ */
+  __pyx_t_2 = ((!(__pyx_v_self->_message_mode != 0)) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":106
+ *         self._check_readonly()
+ *         if not self._message_mode:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'end_message can only be called with start_message')
+ *         if self._length < 5:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_end_message_can_only_be_called_w) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_end_message_can_only_be_called_w);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(1, 106, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":105
+ * 
+ *         self._check_readonly()
+ *         if not self._message_mode:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'end_message can only be called with start_message')
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":108
+ *             raise exceptions.BufferError(
+ *                 'end_message can only be called with start_message')
+ *         if self._length < 5:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('end_message: buffer is too small')
+ *         if mlen > _MAXINT32:
+ */
+  __pyx_t_2 = ((__pyx_v_self->_length < 5) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":109
+ *                 'end_message can only be called with start_message')
+ *         if self._length < 5:
+ *             raise exceptions.BufferError('end_message: buffer is too small')             # <<<<<<<<<<<<<<
+ *         if mlen > _MAXINT32:
+ *             raise exceptions.BufferError('end_message: message is too large')
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 109, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 109, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_end_message_buffer_is_too_small) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_end_message_buffer_is_too_small);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 109, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(1, 109, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":108
+ *             raise exceptions.BufferError(
+ *                 'end_message can only be called with start_message')
+ *         if self._length < 5:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('end_message: buffer is too small')
+ *         if mlen > _MAXINT32:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":110
+ *         if self._length < 5:
+ *             raise exceptions.BufferError('end_message: buffer is too small')
+ *         if mlen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('end_message: message is too large')
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_mlen > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":111
+ *             raise exceptions.BufferError('end_message: buffer is too small')
+ *         if mlen > _MAXINT32:
+ *             raise exceptions.BufferError('end_message: message is too large')             # <<<<<<<<<<<<<<
+ * 
+ *         hton.pack_int32(&self._buf[1], <int32_t>mlen)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 111, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 111, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_end_message_message_is_too_large) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_end_message_message_is_too_large);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 111, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(1, 111, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":110
+ *         if self._length < 5:
+ *             raise exceptions.BufferError('end_message: buffer is too small')
+ *         if mlen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('end_message: message is too large')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":113
+ *             raise exceptions.BufferError('end_message: message is too large')
+ * 
+ *         hton.pack_int32(&self._buf[1], <int32_t>mlen)             # <<<<<<<<<<<<<<
+ *         return self
+ * 
+ */
+  pack_int32((&(__pyx_v_self->_buf[1])), ((int32_t)__pyx_v_mlen));
+
+  /* "asyncpg/pgproto/buffer.pyx":114
+ * 
+ *         hton.pack_int32(&self._buf[1], <int32_t>mlen)
+ *         return self             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_buffer(self, WriteBuffer buf):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(((PyObject *)__pyx_v_self));
+  __pyx_r = ((PyObject *)__pyx_v_self);
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":100
+ *         self._length = 5
+ * 
+ *     cdef inline end_message(self):             # <<<<<<<<<<<<<<
+ *         # "length-1" to exclude the message type byte
+ *         cdef ssize_t mlen = self._length - 1
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.end_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":116
+ *         return self
+ * 
+ *     cdef write_buffer(self, WriteBuffer buf):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_buffer(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("write_buffer", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":117
+ * 
+ *     cdef write_buffer(self, WriteBuffer buf):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ * 
+ *         if not buf._length:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 117, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":119
+ *         self._check_readonly()
+ * 
+ *         if not buf._length:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  __pyx_t_2 = ((!(__pyx_v_buf->_length != 0)) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/buffer.pyx":120
+ * 
+ *         if not buf._length:
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         self._ensure_alloced(buf._length)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":119
+ *         self._check_readonly()
+ * 
+ *         if not buf._length:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":122
+ *             return
+ * 
+ *         self._ensure_alloced(buf._length)             # <<<<<<<<<<<<<<
+ *         memcpy(self._buf + self._length,
+ *                <void*>buf._buf,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, __pyx_v_buf->_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 122, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":123
+ * 
+ *         self._ensure_alloced(buf._length)
+ *         memcpy(self._buf + self._length,             # <<<<<<<<<<<<<<
+ *                <void*>buf._buf,
+ *                <size_t>buf._length)
+ */
+  (void)(memcpy((__pyx_v_self->_buf + __pyx_v_self->_length), ((void *)__pyx_v_buf->_buf), ((size_t)__pyx_v_buf->_length)));
+
+  /* "asyncpg/pgproto/buffer.pyx":126
+ *                <void*>buf._buf,
+ *                <size_t>buf._length)
+ *         self._length += buf._length             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_byte(self, char b):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + __pyx_v_buf->_length);
+
+  /* "asyncpg/pgproto/buffer.pyx":116
+ *         return self
+ * 
+ *     cdef write_buffer(self, WriteBuffer buf):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":128
+ *         self._length += buf._length
+ * 
+ *     cdef write_byte(self, char b):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, char __pyx_v_b) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_byte", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":129
+ * 
+ *     cdef write_byte(self, char b):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ * 
+ *         self._ensure_alloced(1)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 129, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":131
+ *         self._check_readonly()
+ * 
+ *         self._ensure_alloced(1)             # <<<<<<<<<<<<<<
+ *         self._buf[self._length] = b
+ *         self._length += 1
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 131, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":132
+ * 
+ *         self._ensure_alloced(1)
+ *         self._buf[self._length] = b             # <<<<<<<<<<<<<<
+ *         self._length += 1
+ * 
+ */
+  (__pyx_v_self->_buf[__pyx_v_self->_length]) = __pyx_v_b;
+
+  /* "asyncpg/pgproto/buffer.pyx":133
+ *         self._ensure_alloced(1)
+ *         self._buf[self._length] = b
+ *         self._length += 1             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_bytes(self, bytes data):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":128
+ *         self._length += buf._length
+ * 
+ *     cdef write_byte(self, char b):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_byte", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":135
+ *         self._length += 1
+ * 
+ *     cdef write_bytes(self, bytes data):             # <<<<<<<<<<<<<<
+ *         cdef char* buf
+ *         cdef ssize_t len
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_data) {
+  char *__pyx_v_buf;
+  Py_ssize_t __pyx_v_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("write_bytes", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":139
+ *         cdef ssize_t len
+ * 
+ *         cpython.PyBytes_AsStringAndSize(data, &buf, &len)             # <<<<<<<<<<<<<<
+ *         self.write_cstr(buf, len)
+ * 
+ */
+  __pyx_t_1 = PyBytes_AsStringAndSize(__pyx_v_data, (&__pyx_v_buf), ((Py_ssize_t *)(&__pyx_v_len))); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 139, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/buffer.pyx":140
+ * 
+ *         cpython.PyBytes_AsStringAndSize(data, &buf, &len)
+ *         self.write_cstr(buf, len)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_bytestring(self, bytes string):
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_self, __pyx_v_buf, __pyx_v_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 140, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":135
+ *         self._length += 1
+ * 
+ *     cdef write_bytes(self, bytes data):             # <<<<<<<<<<<<<<
+ *         cdef char* buf
+ *         cdef ssize_t len
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":142
+ *         self.write_cstr(buf, len)
+ * 
+ *     cdef write_bytestring(self, bytes string):             # <<<<<<<<<<<<<<
+ *         cdef char* buf
+ *         cdef ssize_t len
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytestring(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_string) {
+  char *__pyx_v_buf;
+  Py_ssize_t __pyx_v_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("write_bytestring", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":146
+ *         cdef ssize_t len
+ * 
+ *         cpython.PyBytes_AsStringAndSize(string, &buf, &len)             # <<<<<<<<<<<<<<
+ *         # PyBytes_AsStringAndSize returns a null-terminated buffer,
+ *         # but the null byte is not counted in len. hence the + 1
+ */
+  __pyx_t_1 = PyBytes_AsStringAndSize(__pyx_v_string, (&__pyx_v_buf), ((Py_ssize_t *)(&__pyx_v_len))); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 146, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/buffer.pyx":149
+ *         # PyBytes_AsStringAndSize returns a null-terminated buffer,
+ *         # but the null byte is not counted in len. hence the + 1
+ *         self.write_cstr(buf, len + 1)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_str(self, str string, str encoding):
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_self, __pyx_v_buf, (__pyx_v_len + 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 149, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":142
+ *         self.write_cstr(buf, len)
+ * 
+ *     cdef write_bytestring(self, bytes string):             # <<<<<<<<<<<<<<
+ *         cdef char* buf
+ *         cdef ssize_t len
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_bytestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":151
+ *         self.write_cstr(buf, len + 1)
+ * 
+ *     cdef write_str(self, str string, str encoding):             # <<<<<<<<<<<<<<
+ *         self.write_bytestring(string.encode(encoding))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_str(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_string, PyObject *__pyx_v_encoding) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("write_str", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":152
+ * 
+ *     cdef write_str(self, str string, str encoding):
+ *         self.write_bytestring(string.encode(encoding))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_utf8(self, str string):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_string, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_encoding);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 152, __pyx_L1_error)
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytestring(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":151
+ *         self.write_cstr(buf, len + 1)
+ * 
+ *     cdef write_str(self, str string, str encoding):             # <<<<<<<<<<<<<<
+ *         self.write_bytestring(string.encode(encoding))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":154
+ *         self.write_bytestring(string.encode(encoding))
+ * 
+ *     cdef write_utf8(self, str string):             # <<<<<<<<<<<<<<
+ *         self.write_bytestring(string.encode('utf-8'))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, PyObject *__pyx_v_string) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("write_utf8", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":155
+ * 
+ *     cdef write_utf8(self, str string):
+ *         self.write_bytestring(string.encode('utf-8'))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_cstr(self, const char *data, ssize_t len):
+ */
+  if (unlikely(__pyx_v_string == Py_None)) {
+    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "encode");
+    __PYX_ERR(1, 155, __pyx_L1_error)
+  }
+  __pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_string); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 155, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytestring(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 155, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":154
+ *         self.write_bytestring(string.encode(encoding))
+ * 
+ *     cdef write_utf8(self, str string):             # <<<<<<<<<<<<<<
+ *         self.write_bytestring(string.encode('utf-8'))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_utf8", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":157
+ *         self.write_bytestring(string.encode('utf-8'))
+ * 
+ *     cdef write_cstr(self, const char *data, ssize_t len):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(len)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, char const *__pyx_v_data, Py_ssize_t __pyx_v_len) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_cstr", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":158
+ * 
+ *     cdef write_cstr(self, const char *data, ssize_t len):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         self._ensure_alloced(len)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 158, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":159
+ *     cdef write_cstr(self, const char *data, ssize_t len):
+ *         self._check_readonly()
+ *         self._ensure_alloced(len)             # <<<<<<<<<<<<<<
+ * 
+ *         memcpy(self._buf + self._length, <void*>data, <size_t>len)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, __pyx_v_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 159, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":161
+ *         self._ensure_alloced(len)
+ * 
+ *         memcpy(self._buf + self._length, <void*>data, <size_t>len)             # <<<<<<<<<<<<<<
+ *         self._length += len
+ * 
+ */
+  (void)(memcpy((__pyx_v_self->_buf + __pyx_v_self->_length), ((void *)__pyx_v_data), ((size_t)__pyx_v_len)));
+
+  /* "asyncpg/pgproto/buffer.pyx":162
+ * 
+ *         memcpy(self._buf + self._length, <void*>data, <size_t>len)
+ *         self._length += len             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_int16(self, int16_t i):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + __pyx_v_len);
+
+  /* "asyncpg/pgproto/buffer.pyx":157
+ *         self.write_bytestring(string.encode('utf-8'))
+ * 
+ *     cdef write_cstr(self, const char *data, ssize_t len):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(len)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_cstr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":164
+ *         self._length += len
+ * 
+ *     cdef write_int16(self, int16_t i):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(2)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, int16_t __pyx_v_i) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_int16", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":165
+ * 
+ *     cdef write_int16(self, int16_t i):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         self._ensure_alloced(2)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 165, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":166
+ *     cdef write_int16(self, int16_t i):
+ *         self._check_readonly()
+ *         self._ensure_alloced(2)             # <<<<<<<<<<<<<<
+ * 
+ *         hton.pack_int16(&self._buf[self._length], i)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 166, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":168
+ *         self._ensure_alloced(2)
+ * 
+ *         hton.pack_int16(&self._buf[self._length], i)             # <<<<<<<<<<<<<<
+ *         self._length += 2
+ * 
+ */
+  pack_int16((&(__pyx_v_self->_buf[__pyx_v_self->_length])), __pyx_v_i);
+
+  /* "asyncpg/pgproto/buffer.pyx":169
+ * 
+ *         hton.pack_int16(&self._buf[self._length], i)
+ *         self._length += 2             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_int32(self, int32_t i):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + 2);
+
+  /* "asyncpg/pgproto/buffer.pyx":164
+ *         self._length += len
+ * 
+ *     cdef write_int16(self, int16_t i):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(2)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_int16", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":171
+ *         self._length += 2
+ * 
+ *     cdef write_int32(self, int32_t i):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(4)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, int32_t __pyx_v_i) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_int32", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":172
+ * 
+ *     cdef write_int32(self, int32_t i):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         self._ensure_alloced(4)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 172, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":173
+ *     cdef write_int32(self, int32_t i):
+ *         self._check_readonly()
+ *         self._ensure_alloced(4)             # <<<<<<<<<<<<<<
+ * 
+ *         hton.pack_int32(&self._buf[self._length], i)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 173, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":175
+ *         self._ensure_alloced(4)
+ * 
+ *         hton.pack_int32(&self._buf[self._length], i)             # <<<<<<<<<<<<<<
+ *         self._length += 4
+ * 
+ */
+  pack_int32((&(__pyx_v_self->_buf[__pyx_v_self->_length])), __pyx_v_i);
+
+  /* "asyncpg/pgproto/buffer.pyx":176
+ * 
+ *         hton.pack_int32(&self._buf[self._length], i)
+ *         self._length += 4             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_int64(self, int64_t i):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + 4);
+
+  /* "asyncpg/pgproto/buffer.pyx":171
+ *         self._length += 2
+ * 
+ *     cdef write_int32(self, int32_t i):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(4)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_int32", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":178
+ *         self._length += 4
+ * 
+ *     cdef write_int64(self, int64_t i):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(8)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, int64_t __pyx_v_i) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_int64", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":179
+ * 
+ *     cdef write_int64(self, int64_t i):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         self._ensure_alloced(8)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 179, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":180
+ *     cdef write_int64(self, int64_t i):
+ *         self._check_readonly()
+ *         self._ensure_alloced(8)             # <<<<<<<<<<<<<<
+ * 
+ *         hton.pack_int64(&self._buf[self._length], i)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 180, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":182
+ *         self._ensure_alloced(8)
+ * 
+ *         hton.pack_int64(&self._buf[self._length], i)             # <<<<<<<<<<<<<<
+ *         self._length += 8
+ * 
+ */
+  pack_int64((&(__pyx_v_self->_buf[__pyx_v_self->_length])), __pyx_v_i);
+
+  /* "asyncpg/pgproto/buffer.pyx":183
+ * 
+ *         hton.pack_int64(&self._buf[self._length], i)
+ *         self._length += 8             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_float(self, float f):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + 8);
+
+  /* "asyncpg/pgproto/buffer.pyx":178
+ *         self._length += 4
+ * 
+ *     cdef write_int64(self, int64_t i):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(8)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_int64", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":185
+ *         self._length += 8
+ * 
+ *     cdef write_float(self, float f):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(4)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_float(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, float __pyx_v_f) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_float", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":186
+ * 
+ *     cdef write_float(self, float f):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         self._ensure_alloced(4)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 186, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":187
+ *     cdef write_float(self, float f):
+ *         self._check_readonly()
+ *         self._ensure_alloced(4)             # <<<<<<<<<<<<<<
+ * 
+ *         hton.pack_float(&self._buf[self._length], f)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 187, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":189
+ *         self._ensure_alloced(4)
+ * 
+ *         hton.pack_float(&self._buf[self._length], f)             # <<<<<<<<<<<<<<
+ *         self._length += 4
+ * 
+ */
+  pack_float((&(__pyx_v_self->_buf[__pyx_v_self->_length])), __pyx_v_f);
+
+  /* "asyncpg/pgproto/buffer.pyx":190
+ * 
+ *         hton.pack_float(&self._buf[self._length], f)
+ *         self._length += 4             # <<<<<<<<<<<<<<
+ * 
+ *     cdef write_double(self, double d):
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + 4);
+
+  /* "asyncpg/pgproto/buffer.pyx":185
+ *         self._length += 8
+ * 
+ *     cdef write_float(self, float f):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(4)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_float", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":192
+ *         self._length += 4
+ * 
+ *     cdef write_double(self, double d):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(8)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, double __pyx_v_d) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("write_double", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":193
+ * 
+ *     cdef write_double(self, double d):
+ *         self._check_readonly()             # <<<<<<<<<<<<<<
+ *         self._ensure_alloced(8)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 193, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":194
+ *     cdef write_double(self, double d):
+ *         self._check_readonly()
+ *         self._ensure_alloced(8)             # <<<<<<<<<<<<<<
+ * 
+ *         hton.pack_double(&self._buf[self._length], d)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced(__pyx_v_self, 8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 194, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":196
+ *         self._ensure_alloced(8)
+ * 
+ *         hton.pack_double(&self._buf[self._length], d)             # <<<<<<<<<<<<<<
+ *         self._length += 8
+ * 
+ */
+  pack_double((&(__pyx_v_self->_buf[__pyx_v_self->_length])), __pyx_v_d);
+
+  /* "asyncpg/pgproto/buffer.pyx":197
+ * 
+ *         hton.pack_double(&self._buf[self._length], d)
+ *         self._length += 8             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + 8);
+
+  /* "asyncpg/pgproto/buffer.pyx":192
+ *         self._length += 4
+ * 
+ *     cdef write_double(self, double d):             # <<<<<<<<<<<<<<
+ *         self._check_readonly()
+ *         self._ensure_alloced(8)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.write_double", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":200
+ * 
+ *     @staticmethod
+ *     cdef WriteBuffer new_message(char type):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ */
+
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new_message(char __pyx_v_type) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("new_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":202
+ *     cdef WriteBuffer new_message(char type):
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)             # <<<<<<<<<<<<<<
+ *         buf.start_message(type)
+ *         return buf
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_tp_new_7asyncpg_7pgproto_7pgproto_WriteBuffer(((PyTypeObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 202, __pyx_L1_error)
+  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":203
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ *         buf.start_message(type)             # <<<<<<<<<<<<<<
+ *         return buf
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_start_message(__pyx_v_buf, __pyx_v_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 203, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":204
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ *         buf.start_message(type)
+ *         return buf             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_buf));
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":200
+ * 
+ *     @staticmethod
+ *     cdef WriteBuffer new_message(char type):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.new_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":207
+ * 
+ *     @staticmethod
+ *     cdef WriteBuffer new():             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ */
+
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new(void) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("new", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":209
+ *     cdef WriteBuffer new():
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)             # <<<<<<<<<<<<<<
+ *         return buf
+ * 
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_tp_new_7asyncpg_7pgproto_7pgproto_WriteBuffer(((PyTypeObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 209, __pyx_L1_error)
+  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":210
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ *         return buf             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_buf));
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":207
+ * 
+ *     @staticmethod
+ *     cdef WriteBuffer new():             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         buf = WriteBuffer.__new__(WriteBuffer)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.new", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_8__reduce_cython__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 2, __pyx_L1_error)
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_10__setstate_cython__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_11WriteBuffer_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 4, __pyx_L1_error)
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":218
+ * cdef class ReadBuffer:
+ * 
+ *     def __cinit__(self):             # <<<<<<<<<<<<<<
+ *         self._bufs = collections.deque()
+ *         self._bufs_append = self._bufs.append
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
+    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
+  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer___cinit__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer___cinit__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("__cinit__", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":219
+ * 
+ *     def __cinit__(self):
+ *         self._bufs = collections.deque()             # <<<<<<<<<<<<<<
+ *         self._bufs_append = self._bufs.append
+ *         self._bufs_popleft = self._bufs.popleft
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 219, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_deque); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 219, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 219, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_bufs);
+  __Pyx_DECREF(__pyx_v_self->_bufs);
+  __pyx_v_self->_bufs = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":220
+ *     def __cinit__(self):
+ *         self._bufs = collections.deque()
+ *         self._bufs_append = self._bufs.append             # <<<<<<<<<<<<<<
+ *         self._bufs_popleft = self._bufs.popleft
+ *         self._bufs_len = 0
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_bufs, __pyx_n_s_append); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 220, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_bufs_append);
+  __Pyx_DECREF(__pyx_v_self->_bufs_append);
+  __pyx_v_self->_bufs_append = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":221
+ *         self._bufs = collections.deque()
+ *         self._bufs_append = self._bufs.append
+ *         self._bufs_popleft = self._bufs.popleft             # <<<<<<<<<<<<<<
+ *         self._bufs_len = 0
+ *         self._buf0 = None
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_bufs, __pyx_n_s_popleft); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 221, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_bufs_popleft);
+  __Pyx_DECREF(__pyx_v_self->_bufs_popleft);
+  __pyx_v_self->_bufs_popleft = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":222
+ *         self._bufs_append = self._bufs.append
+ *         self._bufs_popleft = self._bufs.popleft
+ *         self._bufs_len = 0             # <<<<<<<<<<<<<<
+ *         self._buf0 = None
+ *         self._buf0_prev = None
+ */
+  __pyx_v_self->_bufs_len = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":223
+ *         self._bufs_popleft = self._bufs.popleft
+ *         self._bufs_len = 0
+ *         self._buf0 = None             # <<<<<<<<<<<<<<
+ *         self._buf0_prev = None
+ *         self._pos0 = 0
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_buf0);
+  __Pyx_DECREF(__pyx_v_self->_buf0);
+  __pyx_v_self->_buf0 = ((PyObject*)Py_None);
+
+  /* "asyncpg/pgproto/buffer.pyx":224
+ *         self._bufs_len = 0
+ *         self._buf0 = None
+ *         self._buf0_prev = None             # <<<<<<<<<<<<<<
+ *         self._pos0 = 0
+ *         self._len0 = 0
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_buf0_prev);
+  __Pyx_DECREF(__pyx_v_self->_buf0_prev);
+  __pyx_v_self->_buf0_prev = ((PyObject*)Py_None);
+
+  /* "asyncpg/pgproto/buffer.pyx":225
+ *         self._buf0 = None
+ *         self._buf0_prev = None
+ *         self._pos0 = 0             # <<<<<<<<<<<<<<
+ *         self._len0 = 0
+ *         self._length = 0
+ */
+  __pyx_v_self->_pos0 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":226
+ *         self._buf0_prev = None
+ *         self._pos0 = 0
+ *         self._len0 = 0             # <<<<<<<<<<<<<<
+ *         self._length = 0
+ * 
+ */
+  __pyx_v_self->_len0 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":227
+ *         self._pos0 = 0
+ *         self._len0 = 0
+ *         self._length = 0             # <<<<<<<<<<<<<<
+ * 
+ *         self._current_message_type = 0
+ */
+  __pyx_v_self->_length = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":229
+ *         self._length = 0
+ * 
+ *         self._current_message_type = 0             # <<<<<<<<<<<<<<
+ *         self._current_message_len = 0
+ *         self._current_message_len_unread = 0
+ */
+  __pyx_v_self->_current_message_type = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":230
+ * 
+ *         self._current_message_type = 0
+ *         self._current_message_len = 0             # <<<<<<<<<<<<<<
+ *         self._current_message_len_unread = 0
+ *         self._current_message_ready = 0
+ */
+  __pyx_v_self->_current_message_len = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":231
+ *         self._current_message_type = 0
+ *         self._current_message_len = 0
+ *         self._current_message_len_unread = 0             # <<<<<<<<<<<<<<
+ *         self._current_message_ready = 0
+ * 
+ */
+  __pyx_v_self->_current_message_len_unread = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":232
+ *         self._current_message_len = 0
+ *         self._current_message_len_unread = 0
+ *         self._current_message_ready = 0             # <<<<<<<<<<<<<<
+ * 
+ *     cdef feed_data(self, data):
+ */
+  __pyx_v_self->_current_message_ready = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":218
+ * cdef class ReadBuffer:
+ * 
+ *     def __cinit__(self):             # <<<<<<<<<<<<<<
+ *         self._bufs = collections.deque()
+ *         self._bufs_append = self._bufs.append
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":234
+ *         self._current_message_ready = 0
+ * 
+ *     cdef feed_data(self, data):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t dlen
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_feed_data(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, PyObject *__pyx_v_data) {
+  Py_ssize_t __pyx_v_dlen;
+  PyObject *__pyx_v_data_bytes = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("feed_data", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":239
+ *             bytes data_bytes
+ * 
+ *         if not cpython.PyBytes_CheckExact(data):             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('feed_data: bytes object expected')
+ *         data_bytes = <bytes>data
+ */
+  __pyx_t_1 = ((!(PyBytes_CheckExact(__pyx_v_data) != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":240
+ * 
+ *         if not cpython.PyBytes_CheckExact(data):
+ *             raise exceptions.BufferError('feed_data: bytes object expected')             # <<<<<<<<<<<<<<
+ *         data_bytes = <bytes>data
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 240, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 240, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_feed_data_bytes_object_expected) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_feed_data_bytes_object_expected);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 240, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 240, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":239
+ *             bytes data_bytes
+ * 
+ *         if not cpython.PyBytes_CheckExact(data):             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('feed_data: bytes object expected')
+ *         data_bytes = <bytes>data
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":241
+ *         if not cpython.PyBytes_CheckExact(data):
+ *             raise exceptions.BufferError('feed_data: bytes object expected')
+ *         data_bytes = <bytes>data             # <<<<<<<<<<<<<<
+ * 
+ *         dlen = cpython.Py_SIZE(data_bytes)
+ */
+  __pyx_t_2 = __pyx_v_data;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_v_data_bytes = ((PyObject*)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":243
+ *         data_bytes = <bytes>data
+ * 
+ *         dlen = cpython.Py_SIZE(data_bytes)             # <<<<<<<<<<<<<<
+ *         if dlen == 0:
+ *             # EOF?
+ */
+  __pyx_v_dlen = Py_SIZE(__pyx_v_data_bytes);
+
+  /* "asyncpg/pgproto/buffer.pyx":244
+ * 
+ *         dlen = cpython.Py_SIZE(data_bytes)
+ *         if dlen == 0:             # <<<<<<<<<<<<<<
+ *             # EOF?
+ *             return
+ */
+  __pyx_t_1 = ((__pyx_v_dlen == 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":246
+ *         if dlen == 0:
+ *             # EOF?
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         self._bufs_append(data_bytes)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":244
+ * 
+ *         dlen = cpython.Py_SIZE(data_bytes)
+ *         if dlen == 0:             # <<<<<<<<<<<<<<
+ *             # EOF?
+ *             return
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":248
+ *             return
+ * 
+ *         self._bufs_append(data_bytes)             # <<<<<<<<<<<<<<
+ *         self._length += dlen
+ * 
+ */
+  __Pyx_INCREF(__pyx_v_self->_bufs_append);
+  __pyx_t_4 = __pyx_v_self->_bufs_append; __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_data_bytes) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_data_bytes);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 248, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":249
+ * 
+ *         self._bufs_append(data_bytes)
+ *         self._length += dlen             # <<<<<<<<<<<<<<
+ * 
+ *         if self._bufs_len == 0:
+ */
+  __pyx_v_self->_length = (__pyx_v_self->_length + __pyx_v_dlen);
+
+  /* "asyncpg/pgproto/buffer.pyx":251
+ *         self._length += dlen
+ * 
+ *         if self._bufs_len == 0:             # <<<<<<<<<<<<<<
+ *             # First buffer
+ *             self._len0 = dlen
+ */
+  __pyx_t_1 = ((__pyx_v_self->_bufs_len == 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":253
+ *         if self._bufs_len == 0:
+ *             # First buffer
+ *             self._len0 = dlen             # <<<<<<<<<<<<<<
+ *             self._buf0 = data_bytes
+ * 
+ */
+    __pyx_v_self->_len0 = __pyx_v_dlen;
+
+    /* "asyncpg/pgproto/buffer.pyx":254
+ *             # First buffer
+ *             self._len0 = dlen
+ *             self._buf0 = data_bytes             # <<<<<<<<<<<<<<
+ * 
+ *         self._bufs_len += 1
+ */
+    __Pyx_INCREF(__pyx_v_data_bytes);
+    __Pyx_GIVEREF(__pyx_v_data_bytes);
+    __Pyx_GOTREF(__pyx_v_self->_buf0);
+    __Pyx_DECREF(__pyx_v_self->_buf0);
+    __pyx_v_self->_buf0 = __pyx_v_data_bytes;
+
+    /* "asyncpg/pgproto/buffer.pyx":251
+ *         self._length += dlen
+ * 
+ *         if self._bufs_len == 0:             # <<<<<<<<<<<<<<
+ *             # First buffer
+ *             self._len0 = dlen
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":256
+ *             self._buf0 = data_bytes
+ * 
+ *         self._bufs_len += 1             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _ensure_first_buf(self):
+ */
+  __pyx_v_self->_bufs_len = (__pyx_v_self->_bufs_len + 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":234
+ *         self._current_message_ready = 0
+ * 
+ *     cdef feed_data(self, data):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t dlen
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.feed_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_data_bytes);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":258
+ *         self._bufs_len += 1
+ * 
+ *     cdef inline _ensure_first_buf(self):             # <<<<<<<<<<<<<<
+ *         if self._len0 == 0:
+ *             raise exceptions.BufferError('empty first buffer')
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_ensure_first_buf", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":259
+ * 
+ *     cdef inline _ensure_first_buf(self):
+ *         if self._len0 == 0:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('empty first buffer')
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_self->_len0 == 0) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":260
+ *     cdef inline _ensure_first_buf(self):
+ *         if self._len0 == 0:
+ *             raise exceptions.BufferError('empty first buffer')             # <<<<<<<<<<<<<<
+ * 
+ *         if self._pos0 == self._len0:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 260, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 260, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_empty_first_buffer) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_empty_first_buffer);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 260, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 260, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":259
+ * 
+ *     cdef inline _ensure_first_buf(self):
+ *         if self._len0 == 0:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('empty first buffer')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":262
+ *             raise exceptions.BufferError('empty first buffer')
+ * 
+ *         if self._pos0 == self._len0:             # <<<<<<<<<<<<<<
+ *             self._switch_to_next_buf()
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_self->_pos0 == __pyx_v_self->_len0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":263
+ * 
+ *         if self._pos0 == self._len0:
+ *             self._switch_to_next_buf()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _switch_to_next_buf(self):
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__switch_to_next_buf(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 263, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":262
+ *             raise exceptions.BufferError('empty first buffer')
+ * 
+ *         if self._pos0 == self._len0:             # <<<<<<<<<<<<<<
+ *             self._switch_to_next_buf()
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":258
+ *         self._bufs_len += 1
+ * 
+ *     cdef inline _ensure_first_buf(self):             # <<<<<<<<<<<<<<
+ *         if self._len0 == 0:
+ *             raise exceptions.BufferError('empty first buffer')
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer._ensure_first_buf", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":265
+ *             self._switch_to_next_buf()
+ * 
+ *     cdef _switch_to_next_buf(self):             # <<<<<<<<<<<<<<
+ *         # The first buffer is fully read, discard it
+ *         self._bufs_popleft()
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__switch_to_next_buf(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  Py_ssize_t __pyx_t_4;
+  int __pyx_t_5;
+  __Pyx_RefNannySetupContext("_switch_to_next_buf", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":267
+ *     cdef _switch_to_next_buf(self):
+ *         # The first buffer is fully read, discard it
+ *         self._bufs_popleft()             # <<<<<<<<<<<<<<
+ *         self._bufs_len -= 1
+ * 
+ */
+  __Pyx_INCREF(__pyx_v_self->_bufs_popleft);
+  __pyx_t_2 = __pyx_v_self->_bufs_popleft; __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 267, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":268
+ *         # The first buffer is fully read, discard it
+ *         self._bufs_popleft()
+ *         self._bufs_len -= 1             # <<<<<<<<<<<<<<
+ * 
+ *         # Shouldn't fail, since we've checked that `_length >= 1`
+ */
+  __pyx_v_self->_bufs_len = (__pyx_v_self->_bufs_len - 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":272
+ *         # Shouldn't fail, since we've checked that `_length >= 1`
+ *         # in _ensure_first_buf()
+ *         self._buf0_prev = self._buf0             # <<<<<<<<<<<<<<
+ *         self._buf0 = <bytes>self._bufs[0]
+ * 
+ */
+  __pyx_t_1 = __pyx_v_self->_buf0;
+  __Pyx_INCREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_buf0_prev);
+  __Pyx_DECREF(__pyx_v_self->_buf0_prev);
+  __pyx_v_self->_buf0_prev = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":273
+ *         # in _ensure_first_buf()
+ *         self._buf0_prev = self._buf0
+ *         self._buf0 = <bytes>self._bufs[0]             # <<<<<<<<<<<<<<
+ * 
+ *         self._pos0 = 0
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->_bufs, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 273, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_t_1;
+  __Pyx_INCREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_GIVEREF(__pyx_t_2);
+  __Pyx_GOTREF(__pyx_v_self->_buf0);
+  __Pyx_DECREF(__pyx_v_self->_buf0);
+  __pyx_v_self->_buf0 = ((PyObject*)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":275
+ *         self._buf0 = <bytes>self._bufs[0]
+ * 
+ *         self._pos0 = 0             # <<<<<<<<<<<<<<
+ *         self._len0 = len(self._buf0)
+ * 
+ */
+  __pyx_v_self->_pos0 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":276
+ * 
+ *         self._pos0 = 0
+ *         self._len0 = len(self._buf0)             # <<<<<<<<<<<<<<
+ * 
+ *         if PG_DEBUG:
+ */
+  __pyx_t_2 = __pyx_v_self->_buf0;
+  __Pyx_INCREF(__pyx_t_2);
+  if (unlikely(__pyx_t_2 == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(1, 276, __pyx_L1_error)
+  }
+  __pyx_t_4 = PyBytes_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 276, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_self->_len0 = __pyx_t_4;
+
+  /* "asyncpg/pgproto/buffer.pyx":278
+ *         self._len0 = len(self._buf0)
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if self._len0 < 1:
+ *                 raise exceptions.BufferError(
+ */
+  __pyx_t_5 = (PG_DEBUG != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/pgproto/buffer.pyx":279
+ * 
+ *         if PG_DEBUG:
+ *             if self._len0 < 1:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError(
+ *                     'debug: second buffer of ReadBuffer is empty')
+ */
+    __pyx_t_5 = ((__pyx_v_self->_len0 < 1) != 0);
+    if (unlikely(__pyx_t_5)) {
+
+      /* "asyncpg/pgproto/buffer.pyx":280
+ *         if PG_DEBUG:
+ *             if self._len0 < 1:
+ *                 raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                     'debug: second buffer of ReadBuffer is empty')
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 280, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 280, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __pyx_t_1 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_1)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_1);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_kp_u_debug_second_buffer_of_ReadBuffe) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_debug_second_buffer_of_ReadBuffe);
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 280, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __PYX_ERR(1, 280, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/buffer.pyx":279
+ * 
+ *         if PG_DEBUG:
+ *             if self._len0 < 1:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError(
+ *                     'debug: second buffer of ReadBuffer is empty')
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":278
+ *         self._len0 = len(self._buf0)
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if self._len0 < 1:
+ *                 raise exceptions.BufferError(
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":265
+ *             self._switch_to_next_buf()
+ * 
+ *     cdef _switch_to_next_buf(self):             # <<<<<<<<<<<<<<
+ *         # The first buffer is fully read, discard it
+ *         self._bufs_popleft()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer._switch_to_next_buf", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":283
+ *                     'debug: second buffer of ReadBuffer is empty')
+ * 
+ *     cdef inline const char* _try_read_bytes(self, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         # Try to read *nbytes* from the first buffer.
+ *         #
+ */
+
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t __pyx_v_nbytes) {
+  char const *__pyx_v_result;
+  char const *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_try_read_bytes", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":295
+ *             const char *result
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if nbytes > self._length:
+ *                 return NULL
+ */
+  __pyx_t_1 = (PG_DEBUG != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":296
+ * 
+ *         if PG_DEBUG:
+ *             if nbytes > self._length:             # <<<<<<<<<<<<<<
+ *                 return NULL
+ * 
+ */
+    __pyx_t_1 = ((__pyx_v_nbytes > __pyx_v_self->_length) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":297
+ *         if PG_DEBUG:
+ *             if nbytes > self._length:
+ *                 return NULL             # <<<<<<<<<<<<<<
+ * 
+ *         if self._current_message_ready:
+ */
+      __pyx_r = NULL;
+      goto __pyx_L0;
+
+      /* "asyncpg/pgproto/buffer.pyx":296
+ * 
+ *         if PG_DEBUG:
+ *             if nbytes > self._length:             # <<<<<<<<<<<<<<
+ *                 return NULL
+ * 
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":295
+ *             const char *result
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if nbytes > self._length:
+ *                 return NULL
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":299
+ *                 return NULL
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             if self._current_message_len_unread < nbytes:
+ *                 return NULL
+ */
+  __pyx_t_1 = (__pyx_v_self->_current_message_ready != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":300
+ * 
+ *         if self._current_message_ready:
+ *             if self._current_message_len_unread < nbytes:             # <<<<<<<<<<<<<<
+ *                 return NULL
+ * 
+ */
+    __pyx_t_1 = ((__pyx_v_self->_current_message_len_unread < __pyx_v_nbytes) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":301
+ *         if self._current_message_ready:
+ *             if self._current_message_len_unread < nbytes:
+ *                 return NULL             # <<<<<<<<<<<<<<
+ * 
+ *         if self._pos0 + nbytes <= self._len0:
+ */
+      __pyx_r = NULL;
+      goto __pyx_L0;
+
+      /* "asyncpg/pgproto/buffer.pyx":300
+ * 
+ *         if self._current_message_ready:
+ *             if self._current_message_len_unread < nbytes:             # <<<<<<<<<<<<<<
+ *                 return NULL
+ * 
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":299
+ *                 return NULL
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             if self._current_message_len_unread < nbytes:
+ *                 return NULL
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":303
+ *                 return NULL
+ * 
+ *         if self._pos0 + nbytes <= self._len0:             # <<<<<<<<<<<<<<
+ *             result = cpython.PyBytes_AS_STRING(self._buf0)
+ *             result += self._pos0
+ */
+  __pyx_t_1 = (((__pyx_v_self->_pos0 + __pyx_v_nbytes) <= __pyx_v_self->_len0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":304
+ * 
+ *         if self._pos0 + nbytes <= self._len0:
+ *             result = cpython.PyBytes_AS_STRING(self._buf0)             # <<<<<<<<<<<<<<
+ *             result += self._pos0
+ *             self._pos0 += nbytes
+ */
+    __pyx_t_2 = __pyx_v_self->_buf0;
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_v_result = PyBytes_AS_STRING(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":305
+ *         if self._pos0 + nbytes <= self._len0:
+ *             result = cpython.PyBytes_AS_STRING(self._buf0)
+ *             result += self._pos0             # <<<<<<<<<<<<<<
+ *             self._pos0 += nbytes
+ *             self._length -= nbytes
+ */
+    __pyx_v_result = (__pyx_v_result + __pyx_v_self->_pos0);
+
+    /* "asyncpg/pgproto/buffer.pyx":306
+ *             result = cpython.PyBytes_AS_STRING(self._buf0)
+ *             result += self._pos0
+ *             self._pos0 += nbytes             # <<<<<<<<<<<<<<
+ *             self._length -= nbytes
+ *             if self._current_message_ready:
+ */
+    __pyx_v_self->_pos0 = (__pyx_v_self->_pos0 + __pyx_v_nbytes);
+
+    /* "asyncpg/pgproto/buffer.pyx":307
+ *             result += self._pos0
+ *             self._pos0 += nbytes
+ *             self._length -= nbytes             # <<<<<<<<<<<<<<
+ *             if self._current_message_ready:
+ *                 self._current_message_len_unread -= nbytes
+ */
+    __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nbytes);
+
+    /* "asyncpg/pgproto/buffer.pyx":308
+ *             self._pos0 += nbytes
+ *             self._length -= nbytes
+ *             if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *                 self._current_message_len_unread -= nbytes
+ *             return result
+ */
+    __pyx_t_1 = (__pyx_v_self->_current_message_ready != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":309
+ *             self._length -= nbytes
+ *             if self._current_message_ready:
+ *                 self._current_message_len_unread -= nbytes             # <<<<<<<<<<<<<<
+ *             return result
+ *         else:
+ */
+      __pyx_v_self->_current_message_len_unread = (__pyx_v_self->_current_message_len_unread - __pyx_v_nbytes);
+
+      /* "asyncpg/pgproto/buffer.pyx":308
+ *             self._pos0 += nbytes
+ *             self._length -= nbytes
+ *             if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *                 self._current_message_len_unread -= nbytes
+ *             return result
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":310
+ *             if self._current_message_ready:
+ *                 self._current_message_len_unread -= nbytes
+ *             return result             # <<<<<<<<<<<<<<
+ *         else:
+ *             return NULL
+ */
+    __pyx_r = __pyx_v_result;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":303
+ *                 return NULL
+ * 
+ *         if self._pos0 + nbytes <= self._len0:             # <<<<<<<<<<<<<<
+ *             result = cpython.PyBytes_AS_STRING(self._buf0)
+ *             result += self._pos0
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":312
+ *             return result
+ *         else:
+ *             return NULL             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _read_into(self, char *buf, ssize_t nbytes):
+ */
+  /*else*/ {
+    __pyx_r = NULL;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":283
+ *                     'debug: second buffer of ReadBuffer is empty')
+ * 
+ *     cdef inline const char* _try_read_bytes(self, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         # Try to read *nbytes* from the first buffer.
+ *         #
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":314
+ *             return NULL
+ * 
+ *     cdef inline _read_into(self, char *buf, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t nread
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_into(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, char *__pyx_v_buf, Py_ssize_t __pyx_v_nbytes) {
+  Py_ssize_t __pyx_v_nread;
+  char *__pyx_v_buf0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  Py_ssize_t __pyx_t_3;
+  __Pyx_RefNannySetupContext("_read_into", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":319
+ *             char *buf0
+ * 
+ *         while True:             # <<<<<<<<<<<<<<
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ * 
+ */
+  while (1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":320
+ * 
+ *         while True:
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)             # <<<<<<<<<<<<<<
+ * 
+ *             if self._pos0 + nbytes > self._len0:
+ */
+    __pyx_t_1 = __pyx_v_self->_buf0;
+    __Pyx_INCREF(__pyx_t_1);
+    __pyx_v_buf0 = PyBytes_AS_STRING(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":322
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ * 
+ *             if self._pos0 + nbytes > self._len0:             # <<<<<<<<<<<<<<
+ *                 nread = self._len0 - self._pos0
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nread)
+ */
+    __pyx_t_2 = (((__pyx_v_self->_pos0 + __pyx_v_nbytes) > __pyx_v_self->_len0) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/buffer.pyx":323
+ * 
+ *             if self._pos0 + nbytes > self._len0:
+ *                 nread = self._len0 - self._pos0             # <<<<<<<<<<<<<<
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nread)
+ *                 self._pos0 = self._len0
+ */
+      __pyx_v_nread = (__pyx_v_self->_len0 - __pyx_v_self->_pos0);
+
+      /* "asyncpg/pgproto/buffer.pyx":324
+ *             if self._pos0 + nbytes > self._len0:
+ *                 nread = self._len0 - self._pos0
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nread)             # <<<<<<<<<<<<<<
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread
+ */
+      (void)(memcpy(__pyx_v_buf, (__pyx_v_buf0 + __pyx_v_self->_pos0), ((size_t)__pyx_v_nread)));
+
+      /* "asyncpg/pgproto/buffer.pyx":325
+ *                 nread = self._len0 - self._pos0
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nread)
+ *                 self._pos0 = self._len0             # <<<<<<<<<<<<<<
+ *                 self._length -= nread
+ *                 nbytes -= nread
+ */
+      __pyx_t_3 = __pyx_v_self->_len0;
+      __pyx_v_self->_pos0 = __pyx_t_3;
+
+      /* "asyncpg/pgproto/buffer.pyx":326
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nread)
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread             # <<<<<<<<<<<<<<
+ *                 nbytes -= nread
+ *                 buf += nread
+ */
+      __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":327
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread
+ *                 nbytes -= nread             # <<<<<<<<<<<<<<
+ *                 buf += nread
+ *                 self._ensure_first_buf()
+ */
+      __pyx_v_nbytes = (__pyx_v_nbytes - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":328
+ *                 self._length -= nread
+ *                 nbytes -= nread
+ *                 buf += nread             # <<<<<<<<<<<<<<
+ *                 self._ensure_first_buf()
+ * 
+ */
+      __pyx_v_buf = (__pyx_v_buf + __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":329
+ *                 nbytes -= nread
+ *                 buf += nread
+ *                 self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ * 
+ *             else:
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 329, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":322
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ * 
+ *             if self._pos0 + nbytes > self._len0:             # <<<<<<<<<<<<<<
+ *                 nread = self._len0 - self._pos0
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nread)
+ */
+      goto __pyx_L5;
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":332
+ * 
+ *             else:
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nbytes)             # <<<<<<<<<<<<<<
+ *                 self._pos0 += nbytes
+ *                 self._length -= nbytes
+ */
+    /*else*/ {
+      (void)(memcpy(__pyx_v_buf, (__pyx_v_buf0 + __pyx_v_self->_pos0), ((size_t)__pyx_v_nbytes)));
+
+      /* "asyncpg/pgproto/buffer.pyx":333
+ *             else:
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nbytes)
+ *                 self._pos0 += nbytes             # <<<<<<<<<<<<<<
+ *                 self._length -= nbytes
+ *                 break
+ */
+      __pyx_v_self->_pos0 = (__pyx_v_self->_pos0 + __pyx_v_nbytes);
+
+      /* "asyncpg/pgproto/buffer.pyx":334
+ *                 memcpy(buf, buf0 + self._pos0, <size_t>nbytes)
+ *                 self._pos0 += nbytes
+ *                 self._length -= nbytes             # <<<<<<<<<<<<<<
+ *                 break
+ * 
+ */
+      __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nbytes);
+
+      /* "asyncpg/pgproto/buffer.pyx":335
+ *                 self._pos0 += nbytes
+ *                 self._length -= nbytes
+ *                 break             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _read_and_discard(self, ssize_t nbytes):
+ */
+      goto __pyx_L4_break;
+    }
+    __pyx_L5:;
+  }
+  __pyx_L4_break:;
+
+  /* "asyncpg/pgproto/buffer.pyx":314
+ *             return NULL
+ * 
+ *     cdef inline _read_into(self, char *buf, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t nread
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer._read_into", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":337
+ *                 break
+ * 
+ *     cdef inline _read_and_discard(self, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t nread
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_and_discard(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t __pyx_v_nbytes) {
+  Py_ssize_t __pyx_v_nread;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  Py_ssize_t __pyx_t_3;
+  __Pyx_RefNannySetupContext("_read_and_discard", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":341
+ *             ssize_t nread
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *         while True:
+ *             if self._pos0 + nbytes > self._len0:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 341, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":342
+ * 
+ *         self._ensure_first_buf()
+ *         while True:             # <<<<<<<<<<<<<<
+ *             if self._pos0 + nbytes > self._len0:
+ *                 nread = self._len0 - self._pos0
+ */
+  while (1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":343
+ *         self._ensure_first_buf()
+ *         while True:
+ *             if self._pos0 + nbytes > self._len0:             # <<<<<<<<<<<<<<
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0
+ */
+    __pyx_t_2 = (((__pyx_v_self->_pos0 + __pyx_v_nbytes) > __pyx_v_self->_len0) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/buffer.pyx":344
+ *         while True:
+ *             if self._pos0 + nbytes > self._len0:
+ *                 nread = self._len0 - self._pos0             # <<<<<<<<<<<<<<
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread
+ */
+      __pyx_v_nread = (__pyx_v_self->_len0 - __pyx_v_self->_pos0);
+
+      /* "asyncpg/pgproto/buffer.pyx":345
+ *             if self._pos0 + nbytes > self._len0:
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0             # <<<<<<<<<<<<<<
+ *                 self._length -= nread
+ *                 nbytes -= nread
+ */
+      __pyx_t_3 = __pyx_v_self->_len0;
+      __pyx_v_self->_pos0 = __pyx_t_3;
+
+      /* "asyncpg/pgproto/buffer.pyx":346
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread             # <<<<<<<<<<<<<<
+ *                 nbytes -= nread
+ *                 self._ensure_first_buf()
+ */
+      __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":347
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread
+ *                 nbytes -= nread             # <<<<<<<<<<<<<<
+ *                 self._ensure_first_buf()
+ * 
+ */
+      __pyx_v_nbytes = (__pyx_v_nbytes - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":348
+ *                 self._length -= nread
+ *                 nbytes -= nread
+ *                 self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ * 
+ *             else:
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 348, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":343
+ *         self._ensure_first_buf()
+ *         while True:
+ *             if self._pos0 + nbytes > self._len0:             # <<<<<<<<<<<<<<
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0
+ */
+      goto __pyx_L5;
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":351
+ * 
+ *             else:
+ *                 self._pos0 += nbytes             # <<<<<<<<<<<<<<
+ *                 self._length -= nbytes
+ *                 break
+ */
+    /*else*/ {
+      __pyx_v_self->_pos0 = (__pyx_v_self->_pos0 + __pyx_v_nbytes);
+
+      /* "asyncpg/pgproto/buffer.pyx":352
+ *             else:
+ *                 self._pos0 += nbytes
+ *                 self._length -= nbytes             # <<<<<<<<<<<<<<
+ *                 break
+ * 
+ */
+      __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nbytes);
+
+      /* "asyncpg/pgproto/buffer.pyx":353
+ *                 self._pos0 += nbytes
+ *                 self._length -= nbytes
+ *                 break             # <<<<<<<<<<<<<<
+ * 
+ *     cdef bytes read_bytes(self, ssize_t nbytes):
+ */
+      goto __pyx_L4_break;
+    }
+    __pyx_L5:;
+  }
+  __pyx_L4_break:;
+
+  /* "asyncpg/pgproto/buffer.pyx":337
+ *                 break
+ * 
+ *     cdef inline _read_and_discard(self, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t nread
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer._read_and_discard", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":355
+ *                 break
+ * 
+ *     cdef bytes read_bytes(self, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             bytes result
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t __pyx_v_nbytes) {
+  PyObject *__pyx_v_result = 0;
+  char const *__pyx_v_cbuf;
+  char *__pyx_v_buf;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("read_bytes", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":362
+ *             char *buf
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *         cbuf = self._try_read_bytes(nbytes)
+ *         if cbuf != NULL:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 362, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":363
+ * 
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(nbytes)             # <<<<<<<<<<<<<<
+ *         if cbuf != NULL:
+ *             return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
+ */
+  __pyx_v_cbuf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, __pyx_v_nbytes);
+
+  /* "asyncpg/pgproto/buffer.pyx":364
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(nbytes)
+ *         if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *             return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_cbuf != NULL) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/buffer.pyx":365
+ *         cbuf = self._try_read_bytes(nbytes)
+ *         if cbuf != NULL:
+ *             return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)             # <<<<<<<<<<<<<<
+ * 
+ *         if nbytes > self._length:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_1 = PyBytes_FromStringAndSize(__pyx_v_cbuf, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 365, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_r = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":364
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(nbytes)
+ *         if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *             return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":367
+ *             return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
+ * 
+ *         if nbytes > self._length:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'not enough data to read {} bytes'.format(nbytes))
+ */
+  __pyx_t_2 = ((__pyx_v_nbytes > __pyx_v_self->_length) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":368
+ * 
+ *         if nbytes > self._length:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'not enough data to read {} bytes'.format(nbytes))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 368, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 368, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":369
+ *         if nbytes > self._length:
+ *             raise exceptions.BufferError(
+ *                 'not enough data to read {} bytes'.format(nbytes))             # <<<<<<<<<<<<<<
+ * 
+ *         if self._current_message_ready:
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_not_enough_data_to_read_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 369, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 369, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_7)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 369, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 368, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(1, 368, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":367
+ *             return cpython.PyBytes_FromStringAndSize(cbuf, nbytes)
+ * 
+ *         if nbytes > self._length:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'not enough data to read {} bytes'.format(nbytes))
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":371
+ *                 'not enough data to read {} bytes'.format(nbytes))
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             self._current_message_len_unread -= nbytes
+ *             if self._current_message_len_unread < 0:
+ */
+  __pyx_t_2 = (__pyx_v_self->_current_message_ready != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/buffer.pyx":372
+ * 
+ *         if self._current_message_ready:
+ *             self._current_message_len_unread -= nbytes             # <<<<<<<<<<<<<<
+ *             if self._current_message_len_unread < 0:
+ *                 raise exceptions.BufferError('buffer overread')
+ */
+    __pyx_v_self->_current_message_len_unread = (__pyx_v_self->_current_message_len_unread - __pyx_v_nbytes);
+
+    /* "asyncpg/pgproto/buffer.pyx":373
+ *         if self._current_message_ready:
+ *             self._current_message_len_unread -= nbytes
+ *             if self._current_message_len_unread < 0:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError('buffer overread')
+ * 
+ */
+    __pyx_t_2 = ((__pyx_v_self->_current_message_len_unread < 0) != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/pgproto/buffer.pyx":374
+ *             self._current_message_len_unread -= nbytes
+ *             if self._current_message_len_unread < 0:
+ *                 raise exceptions.BufferError('buffer overread')             # <<<<<<<<<<<<<<
+ * 
+ *         result = cpython.PyBytes_FromStringAndSize(NULL, nbytes)
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 374, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 374, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_buffer_overread) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_buffer_overread);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 374, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(1, 374, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/buffer.pyx":373
+ *         if self._current_message_ready:
+ *             self._current_message_len_unread -= nbytes
+ *             if self._current_message_len_unread < 0:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError('buffer overread')
+ * 
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":371
+ *                 'not enough data to read {} bytes'.format(nbytes))
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             self._current_message_len_unread -= nbytes
+ *             if self._current_message_len_unread < 0:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":376
+ *                 raise exceptions.BufferError('buffer overread')
+ * 
+ *         result = cpython.PyBytes_FromStringAndSize(NULL, nbytes)             # <<<<<<<<<<<<<<
+ *         buf = cpython.PyBytes_AS_STRING(result)
+ *         self._read_into(buf, nbytes)
+ */
+  __pyx_t_1 = PyBytes_FromStringAndSize(NULL, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 376, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_result = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":377
+ * 
+ *         result = cpython.PyBytes_FromStringAndSize(NULL, nbytes)
+ *         buf = cpython.PyBytes_AS_STRING(result)             # <<<<<<<<<<<<<<
+ *         self._read_into(buf, nbytes)
+ *         return result
+ */
+  __pyx_v_buf = PyBytes_AS_STRING(__pyx_v_result);
+
+  /* "asyncpg/pgproto/buffer.pyx":378
+ *         result = cpython.PyBytes_FromStringAndSize(NULL, nbytes)
+ *         buf = cpython.PyBytes_AS_STRING(result)
+ *         self._read_into(buf, nbytes)             # <<<<<<<<<<<<<<
+ *         return result
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_into(__pyx_v_self, __pyx_v_buf, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 378, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":379
+ *         buf = cpython.PyBytes_AS_STRING(result)
+ *         self._read_into(buf, nbytes)
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline char read_byte(self) except? -1:
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":355
+ *                 break
+ * 
+ *     cdef bytes read_bytes(self, ssize_t nbytes):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             bytes result
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":381
+ *         return result
+ * 
+ *     cdef inline char read_byte(self) except? -1:             # <<<<<<<<<<<<<<
+ *         cdef const char *first_byte
+ * 
+ */
+
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_byte(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  char const *__pyx_v_first_byte;
+  char __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("read_byte", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":384
+ *         cdef const char *first_byte
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if not self._buf0:
+ *                 raise exceptions.BufferError(
+ */
+  __pyx_t_1 = (PG_DEBUG != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":385
+ * 
+ *         if PG_DEBUG:
+ *             if not self._buf0:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError(
+ *                     'debug: first buffer of ReadBuffer is empty')
+ */
+    __pyx_t_1 = (__pyx_v_self->_buf0 != Py_None)&&(PyBytes_GET_SIZE(__pyx_v_self->_buf0) != 0);
+    __pyx_t_2 = ((!__pyx_t_1) != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/pgproto/buffer.pyx":386
+ *         if PG_DEBUG:
+ *             if not self._buf0:
+ *                 raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                     'debug: first buffer of ReadBuffer is empty')
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 386, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 386, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_debug_first_buffer_of_ReadBuffer) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_debug_first_buffer_of_ReadBuffer);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 386, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(1, 386, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/buffer.pyx":385
+ * 
+ *         if PG_DEBUG:
+ *             if not self._buf0:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError(
+ *                     'debug: first buffer of ReadBuffer is empty')
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":384
+ *         cdef const char *first_byte
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if not self._buf0:
+ *                 raise exceptions.BufferError(
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":389
+ *                     'debug: first buffer of ReadBuffer is empty')
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *         first_byte = self._try_read_bytes(1)
+ *         if first_byte is NULL:
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 389, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":390
+ * 
+ *         self._ensure_first_buf()
+ *         first_byte = self._try_read_bytes(1)             # <<<<<<<<<<<<<<
+ *         if first_byte is NULL:
+ *             raise exceptions.BufferError('not enough data to read one byte')
+ */
+  __pyx_v_first_byte = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, 1);
+
+  /* "asyncpg/pgproto/buffer.pyx":391
+ *         self._ensure_first_buf()
+ *         first_byte = self._try_read_bytes(1)
+ *         if first_byte is NULL:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('not enough data to read one byte')
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_first_byte == NULL) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":392
+ *         first_byte = self._try_read_bytes(1)
+ *         if first_byte is NULL:
+ *             raise exceptions.BufferError('not enough data to read one byte')             # <<<<<<<<<<<<<<
+ * 
+ *         return first_byte[0]
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 392, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 392, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_kp_u_not_enough_data_to_read_one_byte) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_not_enough_data_to_read_one_byte);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 392, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(1, 392, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":391
+ *         self._ensure_first_buf()
+ *         first_byte = self._try_read_bytes(1)
+ *         if first_byte is NULL:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('not enough data to read one byte')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":394
+ *             raise exceptions.BufferError('not enough data to read one byte')
+ * 
+ *         return first_byte[0]             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline int32_t read_int32(self) except? -1:
+ */
+  __pyx_r = (__pyx_v_first_byte[0]);
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":381
+ *         return result
+ * 
+ *     cdef inline char read_byte(self) except? -1:             # <<<<<<<<<<<<<<
+ *         cdef const char *first_byte
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_byte", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":396
+ *         return first_byte[0]
+ * 
+ *     cdef inline int32_t read_int32(self) except? -1:             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             bytes mem
+ */
+
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int32(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_v_mem = 0;
+  char const *__pyx_v_cbuf;
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("read_int32", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":401
+ *             const char *cbuf
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *         cbuf = self._try_read_bytes(4)
+ *         if cbuf != NULL:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 401, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":402
+ * 
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(4)             # <<<<<<<<<<<<<<
+ *         if cbuf != NULL:
+ *             return hton.unpack_int32(cbuf)
+ */
+  __pyx_v_cbuf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, 4);
+
+  /* "asyncpg/pgproto/buffer.pyx":403
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(4)
+ *         if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *             return hton.unpack_int32(cbuf)
+ *         else:
+ */
+  __pyx_t_2 = ((__pyx_v_cbuf != NULL) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/buffer.pyx":404
+ *         cbuf = self._try_read_bytes(4)
+ *         if cbuf != NULL:
+ *             return hton.unpack_int32(cbuf)             # <<<<<<<<<<<<<<
+ *         else:
+ *             mem = self.read_bytes(4)
+ */
+    __pyx_r = unpack_int32(__pyx_v_cbuf);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":403
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(4)
+ *         if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *             return hton.unpack_int32(cbuf)
+ *         else:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":406
+ *             return hton.unpack_int32(cbuf)
+ *         else:
+ *             mem = self.read_bytes(4)             # <<<<<<<<<<<<<<
+ *             return hton.unpack_int32(cpython.PyBytes_AS_STRING(mem))
+ * 
+ */
+  /*else*/ {
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes(__pyx_v_self, 4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 406, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_v_mem = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":407
+ *         else:
+ *             mem = self.read_bytes(4)
+ *             return hton.unpack_int32(cpython.PyBytes_AS_STRING(mem))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline int16_t read_int16(self) except? -1:
+ */
+    __pyx_r = unpack_int32(PyBytes_AS_STRING(__pyx_v_mem));
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":396
+ *         return first_byte[0]
+ * 
+ *     cdef inline int32_t read_int32(self) except? -1:             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             bytes mem
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_int32", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_mem);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":409
+ *             return hton.unpack_int32(cpython.PyBytes_AS_STRING(mem))
+ * 
+ *     cdef inline int16_t read_int16(self) except? -1:             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             bytes mem
+ */
+
+static CYTHON_INLINE int16_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int16(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_v_mem = 0;
+  char const *__pyx_v_cbuf;
+  int16_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("read_int16", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":414
+ *             const char *cbuf
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *         cbuf = self._try_read_bytes(2)
+ *         if cbuf != NULL:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 414, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":415
+ * 
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(2)             # <<<<<<<<<<<<<<
+ *         if cbuf != NULL:
+ *             return hton.unpack_int16(cbuf)
+ */
+  __pyx_v_cbuf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, 2);
+
+  /* "asyncpg/pgproto/buffer.pyx":416
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(2)
+ *         if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *             return hton.unpack_int16(cbuf)
+ *         else:
+ */
+  __pyx_t_2 = ((__pyx_v_cbuf != NULL) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/buffer.pyx":417
+ *         cbuf = self._try_read_bytes(2)
+ *         if cbuf != NULL:
+ *             return hton.unpack_int16(cbuf)             # <<<<<<<<<<<<<<
+ *         else:
+ *             mem = self.read_bytes(2)
+ */
+    __pyx_r = unpack_int16(__pyx_v_cbuf);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":416
+ *         self._ensure_first_buf()
+ *         cbuf = self._try_read_bytes(2)
+ *         if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *             return hton.unpack_int16(cbuf)
+ *         else:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":419
+ *             return hton.unpack_int16(cbuf)
+ *         else:
+ *             mem = self.read_bytes(2)             # <<<<<<<<<<<<<<
+ *             return hton.unpack_int16(cpython.PyBytes_AS_STRING(mem))
+ * 
+ */
+  /*else*/ {
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes(__pyx_v_self, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 419, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_v_mem = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":420
+ *         else:
+ *             mem = self.read_bytes(2)
+ *             return hton.unpack_int16(cpython.PyBytes_AS_STRING(mem))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline read_cstr(self):
+ */
+    __pyx_r = unpack_int16(PyBytes_AS_STRING(__pyx_v_mem));
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":409
+ *             return hton.unpack_int32(cpython.PyBytes_AS_STRING(mem))
+ * 
+ *     cdef inline int16_t read_int16(self) except? -1:             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             bytes mem
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_int16", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_mem);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":422
+ *             return hton.unpack_int16(cpython.PyBytes_AS_STRING(mem))
+ * 
+ *     cdef inline read_cstr(self):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_cstr(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  Py_ssize_t __pyx_v_pos;
+  Py_ssize_t __pyx_v_nread;
+  PyObject *__pyx_v_result = 0;
+  char const *__pyx_v_buf;
+  char const *__pyx_v_buf_start;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  Py_ssize_t __pyx_t_8;
+  __Pyx_RefNannySetupContext("read_cstr", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":423
+ * 
+ *     cdef inline read_cstr(self):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'read_cstr only works when the message guaranteed '
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":424
+ *     cdef inline read_cstr(self):
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'read_cstr only works when the message guaranteed '
+ *                 'to be in the buffer')
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 424, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 424, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_read_cstr_only_works_when_the_me) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_read_cstr_only_works_when_the_me);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 424, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 424, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":423
+ * 
+ *     cdef inline read_cstr(self):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'read_cstr only works when the message guaranteed '
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":435
+ *             const char *buf_start
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ * 
+ *         buf_start = cpython.PyBytes_AS_STRING(self._buf0)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 435, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":437
+ *         self._ensure_first_buf()
+ * 
+ *         buf_start = cpython.PyBytes_AS_STRING(self._buf0)             # <<<<<<<<<<<<<<
+ *         buf = buf_start + self._pos0
+ *         while buf - buf_start < self._len0:
+ */
+  __pyx_t_2 = __pyx_v_self->_buf0;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_v_buf_start = PyBytes_AS_STRING(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":438
+ * 
+ *         buf_start = cpython.PyBytes_AS_STRING(self._buf0)
+ *         buf = buf_start + self._pos0             # <<<<<<<<<<<<<<
+ *         while buf - buf_start < self._len0:
+ *             if buf[0] == 0:
+ */
+  __pyx_v_buf = (__pyx_v_buf_start + __pyx_v_self->_pos0);
+
+  /* "asyncpg/pgproto/buffer.pyx":439
+ *         buf_start = cpython.PyBytes_AS_STRING(self._buf0)
+ *         buf = buf_start + self._pos0
+ *         while buf - buf_start < self._len0:             # <<<<<<<<<<<<<<
+ *             if buf[0] == 0:
+ *                 pos = buf - buf_start
+ */
+  while (1) {
+    __pyx_t_1 = (((__pyx_v_buf - __pyx_v_buf_start) < __pyx_v_self->_len0) != 0);
+    if (!__pyx_t_1) break;
+
+    /* "asyncpg/pgproto/buffer.pyx":440
+ *         buf = buf_start + self._pos0
+ *         while buf - buf_start < self._len0:
+ *             if buf[0] == 0:             # <<<<<<<<<<<<<<
+ *                 pos = buf - buf_start
+ *                 nread = pos - self._pos0
+ */
+    __pyx_t_1 = (((__pyx_v_buf[0]) == 0) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":441
+ *         while buf - buf_start < self._len0:
+ *             if buf[0] == 0:
+ *                 pos = buf - buf_start             # <<<<<<<<<<<<<<
+ *                 nread = pos - self._pos0
+ *                 buf = self._try_read_bytes(nread + 1)
+ */
+      __pyx_v_pos = (__pyx_v_buf - __pyx_v_buf_start);
+
+      /* "asyncpg/pgproto/buffer.pyx":442
+ *             if buf[0] == 0:
+ *                 pos = buf - buf_start
+ *                 nread = pos - self._pos0             # <<<<<<<<<<<<<<
+ *                 buf = self._try_read_bytes(nread + 1)
+ *                 if buf != NULL:
+ */
+      __pyx_v_nread = (__pyx_v_pos - __pyx_v_self->_pos0);
+
+      /* "asyncpg/pgproto/buffer.pyx":443
+ *                 pos = buf - buf_start
+ *                 nread = pos - self._pos0
+ *                 buf = self._try_read_bytes(nread + 1)             # <<<<<<<<<<<<<<
+ *                 if buf != NULL:
+ *                     return cpython.PyBytes_FromStringAndSize(buf, nread)
+ */
+      __pyx_v_buf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, (__pyx_v_nread + 1));
+
+      /* "asyncpg/pgproto/buffer.pyx":444
+ *                 nread = pos - self._pos0
+ *                 buf = self._try_read_bytes(nread + 1)
+ *                 if buf != NULL:             # <<<<<<<<<<<<<<
+ *                     return cpython.PyBytes_FromStringAndSize(buf, nread)
+ *                 else:
+ */
+      __pyx_t_1 = ((__pyx_v_buf != NULL) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/pgproto/buffer.pyx":445
+ *                 buf = self._try_read_bytes(nread + 1)
+ *                 if buf != NULL:
+ *                     return cpython.PyBytes_FromStringAndSize(buf, nread)             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     break
+ */
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_t_2 = PyBytes_FromStringAndSize(__pyx_v_buf, __pyx_v_nread); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 445, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __pyx_r = __pyx_t_2;
+        __pyx_t_2 = 0;
+        goto __pyx_L0;
+
+        /* "asyncpg/pgproto/buffer.pyx":444
+ *                 nread = pos - self._pos0
+ *                 buf = self._try_read_bytes(nread + 1)
+ *                 if buf != NULL:             # <<<<<<<<<<<<<<
+ *                     return cpython.PyBytes_FromStringAndSize(buf, nread)
+ *                 else:
+ */
+      }
+
+      /* "asyncpg/pgproto/buffer.pyx":447
+ *                     return cpython.PyBytes_FromStringAndSize(buf, nread)
+ *                 else:
+ *                     break             # <<<<<<<<<<<<<<
+ *             else:
+ *                 buf += 1
+ */
+      /*else*/ {
+        goto __pyx_L5_break;
+      }
+
+      /* "asyncpg/pgproto/buffer.pyx":440
+ *         buf = buf_start + self._pos0
+ *         while buf - buf_start < self._len0:
+ *             if buf[0] == 0:             # <<<<<<<<<<<<<<
+ *                 pos = buf - buf_start
+ *                 nread = pos - self._pos0
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":449
+ *                     break
+ *             else:
+ *                 buf += 1             # <<<<<<<<<<<<<<
+ * 
+ *         result = b''
+ */
+    /*else*/ {
+      __pyx_v_buf = (__pyx_v_buf + 1);
+    }
+  }
+  __pyx_L5_break:;
+
+  /* "asyncpg/pgproto/buffer.pyx":451
+ *                 buf += 1
+ * 
+ *         result = b''             # <<<<<<<<<<<<<<
+ *         while True:
+ *             pos = self._buf0.find(b'\x00', self._pos0)
+ */
+  __Pyx_INCREF(__pyx_kp_b__3);
+  __pyx_v_result = __pyx_kp_b__3;
+
+  /* "asyncpg/pgproto/buffer.pyx":452
+ * 
+ *         result = b''
+ *         while True:             # <<<<<<<<<<<<<<
+ *             pos = self._buf0.find(b'\x00', self._pos0)
+ *             if pos >= 0:
+ */
+  while (1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":453
+ *         result = b''
+ *         while True:
+ *             pos = self._buf0.find(b'\x00', self._pos0)             # <<<<<<<<<<<<<<
+ *             if pos >= 0:
+ *                 result += self._buf0[self._pos0 : pos]
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_buf0, __pyx_n_s_find); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 453, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_self->_pos0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 453, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = NULL;
+    __pyx_t_6 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+        __pyx_t_6 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_b__4, __pyx_t_3};
+      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 453, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_b__4, __pyx_t_3};
+      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 453, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 453, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      if (__pyx_t_5) {
+        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+      }
+      __Pyx_INCREF(__pyx_kp_b__4);
+      __Pyx_GIVEREF(__pyx_kp_b__4);
+      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_kp_b__4);
+      __Pyx_GIVEREF(__pyx_t_3);
+      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3);
+      __pyx_t_3 = 0;
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 453, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_8 = PyInt_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 453, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_v_pos = __pyx_t_8;
+
+    /* "asyncpg/pgproto/buffer.pyx":454
+ *         while True:
+ *             pos = self._buf0.find(b'\x00', self._pos0)
+ *             if pos >= 0:             # <<<<<<<<<<<<<<
+ *                 result += self._buf0[self._pos0 : pos]
+ *                 nread = pos - self._pos0 + 1
+ */
+    __pyx_t_1 = ((__pyx_v_pos >= 0) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":455
+ *             pos = self._buf0.find(b'\x00', self._pos0)
+ *             if pos >= 0:
+ *                 result += self._buf0[self._pos0 : pos]             # <<<<<<<<<<<<<<
+ *                 nread = pos - self._pos0 + 1
+ *                 self._pos0 = pos + 1
+ */
+      if (unlikely(__pyx_v_self->_buf0 == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(1, 455, __pyx_L1_error)
+      }
+      __pyx_t_2 = PySequence_GetSlice(__pyx_v_self->_buf0, __pyx_v_self->_pos0, __pyx_v_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 455, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_result, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 455, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_DECREF_SET(__pyx_v_result, ((PyObject*)__pyx_t_4));
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":456
+ *             if pos >= 0:
+ *                 result += self._buf0[self._pos0 : pos]
+ *                 nread = pos - self._pos0 + 1             # <<<<<<<<<<<<<<
+ *                 self._pos0 = pos + 1
+ *                 self._length -= nread
+ */
+      __pyx_v_nread = ((__pyx_v_pos - __pyx_v_self->_pos0) + 1);
+
+      /* "asyncpg/pgproto/buffer.pyx":457
+ *                 result += self._buf0[self._pos0 : pos]
+ *                 nread = pos - self._pos0 + 1
+ *                 self._pos0 = pos + 1             # <<<<<<<<<<<<<<
+ *                 self._length -= nread
+ * 
+ */
+      __pyx_v_self->_pos0 = (__pyx_v_pos + 1);
+
+      /* "asyncpg/pgproto/buffer.pyx":458
+ *                 nread = pos - self._pos0 + 1
+ *                 self._pos0 = pos + 1
+ *                 self._length -= nread             # <<<<<<<<<<<<<<
+ * 
+ *                 self._current_message_len_unread -= nread
+ */
+      __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":460
+ *                 self._length -= nread
+ * 
+ *                 self._current_message_len_unread -= nread             # <<<<<<<<<<<<<<
+ *                 if self._current_message_len_unread < 0:
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ */
+      __pyx_v_self->_current_message_len_unread = (__pyx_v_self->_current_message_len_unread - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":461
+ * 
+ *                 self._current_message_len_unread -= nread
+ *                 if self._current_message_len_unread < 0:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ * 
+ */
+      __pyx_t_1 = ((__pyx_v_self->_current_message_len_unread < 0) != 0);
+      if (unlikely(__pyx_t_1)) {
+
+        /* "asyncpg/pgproto/buffer.pyx":462
+ *                 self._current_message_len_unread -= nread
+ *                 if self._current_message_len_unread < 0:
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')             # <<<<<<<<<<<<<<
+ * 
+ *                 return result
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 462, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 462, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+        __pyx_t_2 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
+          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
+          if (likely(__pyx_t_2)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+            __Pyx_INCREF(__pyx_t_2);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_7, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_kp_u_read_cstr_buffer_overread) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_kp_u_read_cstr_buffer_overread);
+        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 462, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __PYX_ERR(1, 462, __pyx_L1_error)
+
+        /* "asyncpg/pgproto/buffer.pyx":461
+ * 
+ *                 self._current_message_len_unread -= nread
+ *                 if self._current_message_len_unread < 0:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ * 
+ */
+      }
+
+      /* "asyncpg/pgproto/buffer.pyx":464
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ * 
+ *                 return result             # <<<<<<<<<<<<<<
+ * 
+ *             else:
+ */
+      __Pyx_XDECREF(__pyx_r);
+      __Pyx_INCREF(__pyx_v_result);
+      __pyx_r = __pyx_v_result;
+      goto __pyx_L0;
+
+      /* "asyncpg/pgproto/buffer.pyx":454
+ *         while True:
+ *             pos = self._buf0.find(b'\x00', self._pos0)
+ *             if pos >= 0:             # <<<<<<<<<<<<<<
+ *                 result += self._buf0[self._pos0 : pos]
+ *                 nread = pos - self._pos0 + 1
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":467
+ * 
+ *             else:
+ *                 result += self._buf0[self._pos0:]             # <<<<<<<<<<<<<<
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0
+ */
+    /*else*/ {
+      if (unlikely(__pyx_v_self->_buf0 == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(1, 467, __pyx_L1_error)
+      }
+      __pyx_t_4 = PySequence_GetSlice(__pyx_v_self->_buf0, __pyx_v_self->_pos0, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 467, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_result, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 467, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF_SET(__pyx_v_result, ((PyObject*)__pyx_t_7));
+      __pyx_t_7 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":468
+ *             else:
+ *                 result += self._buf0[self._pos0:]
+ *                 nread = self._len0 - self._pos0             # <<<<<<<<<<<<<<
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread
+ */
+      __pyx_v_nread = (__pyx_v_self->_len0 - __pyx_v_self->_pos0);
+
+      /* "asyncpg/pgproto/buffer.pyx":469
+ *                 result += self._buf0[self._pos0:]
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0             # <<<<<<<<<<<<<<
+ *                 self._length -= nread
+ * 
+ */
+      __pyx_t_8 = __pyx_v_self->_len0;
+      __pyx_v_self->_pos0 = __pyx_t_8;
+
+      /* "asyncpg/pgproto/buffer.pyx":470
+ *                 nread = self._len0 - self._pos0
+ *                 self._pos0 = self._len0
+ *                 self._length -= nread             # <<<<<<<<<<<<<<
+ * 
+ *                 self._current_message_len_unread -= nread
+ */
+      __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":472
+ *                 self._length -= nread
+ * 
+ *                 self._current_message_len_unread -= nread             # <<<<<<<<<<<<<<
+ *                 if self._current_message_len_unread < 0:
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ */
+      __pyx_v_self->_current_message_len_unread = (__pyx_v_self->_current_message_len_unread - __pyx_v_nread);
+
+      /* "asyncpg/pgproto/buffer.pyx":473
+ * 
+ *                 self._current_message_len_unread -= nread
+ *                 if self._current_message_len_unread < 0:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ * 
+ */
+      __pyx_t_1 = ((__pyx_v_self->_current_message_len_unread < 0) != 0);
+      if (unlikely(__pyx_t_1)) {
+
+        /* "asyncpg/pgproto/buffer.pyx":474
+ *                 self._current_message_len_unread -= nread
+ *                 if self._current_message_len_unread < 0:
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')             # <<<<<<<<<<<<<<
+ * 
+ *                 self._ensure_first_buf()
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 474, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 474, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __pyx_t_4 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+          if (likely(__pyx_t_4)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+            __Pyx_INCREF(__pyx_t_4);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_2, function);
+          }
+        }
+        __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_kp_u_read_cstr_buffer_overread) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_kp_u_read_cstr_buffer_overread);
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 474, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __PYX_ERR(1, 474, __pyx_L1_error)
+
+        /* "asyncpg/pgproto/buffer.pyx":473
+ * 
+ *                 self._current_message_len_unread -= nread
+ *                 if self._current_message_len_unread < 0:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ * 
+ */
+      }
+
+      /* "asyncpg/pgproto/buffer.pyx":476
+ *                     raise exceptions.BufferError('read_cstr: buffer overread')
+ * 
+ *                 self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef int32_t take_message(self) except -1:
+ */
+      __pyx_t_7 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 476, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    }
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":422
+ *             return hton.unpack_int16(cpython.PyBytes_AS_STRING(mem))
+ * 
+ *     cdef inline read_cstr(self):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_cstr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":478
+ *                 self._ensure_first_buf()
+ * 
+ *     cdef int32_t take_message(self) except -1:             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             const char *cbuf
+ */
+
+static int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  char const *__pyx_v_cbuf;
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  int32_t __pyx_t_5;
+  __Pyx_RefNannySetupContext("take_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":482
+ *             const char *cbuf
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             return 1
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_self->_current_message_ready != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":483
+ * 
+ *         if self._current_message_ready:
+ *             return 1             # <<<<<<<<<<<<<<
+ * 
+ *         if self._current_message_type == 0:
+ */
+    __pyx_r = 1;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":482
+ *             const char *cbuf
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             return 1
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":485
+ *             return 1
+ * 
+ *         if self._current_message_type == 0:             # <<<<<<<<<<<<<<
+ *             if self._length < 1:
+ *                 return 0
+ */
+  __pyx_t_1 = ((__pyx_v_self->_current_message_type == 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":486
+ * 
+ *         if self._current_message_type == 0:
+ *             if self._length < 1:             # <<<<<<<<<<<<<<
+ *                 return 0
+ *             self._ensure_first_buf()
+ */
+    __pyx_t_1 = ((__pyx_v_self->_length < 1) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":487
+ *         if self._current_message_type == 0:
+ *             if self._length < 1:
+ *                 return 0             # <<<<<<<<<<<<<<
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(1)
+ */
+      __pyx_r = 0;
+      goto __pyx_L0;
+
+      /* "asyncpg/pgproto/buffer.pyx":486
+ * 
+ *         if self._current_message_type == 0:
+ *             if self._length < 1:             # <<<<<<<<<<<<<<
+ *                 return 0
+ *             self._ensure_first_buf()
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":488
+ *             if self._length < 1:
+ *                 return 0
+ *             self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *             cbuf = self._try_read_bytes(1)
+ *             if cbuf == NULL:
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 488, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":489
+ *                 return 0
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(1)             # <<<<<<<<<<<<<<
+ *             if cbuf == NULL:
+ *                 raise exceptions.BufferError(
+ */
+    __pyx_v_cbuf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, 1);
+
+    /* "asyncpg/pgproto/buffer.pyx":490
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(1)
+ *             if cbuf == NULL:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError(
+ *                     'failed to read one byte on a non-empty buffer')
+ */
+    __pyx_t_1 = ((__pyx_v_cbuf == NULL) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/pgproto/buffer.pyx":491
+ *             cbuf = self._try_read_bytes(1)
+ *             if cbuf == NULL:
+ *                 raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                     'failed to read one byte on a non-empty buffer')
+ *             self._current_message_type = cbuf[0]
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 491, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 491, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __pyx_t_3 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_3)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_3);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_failed_to_read_one_byte_on_a_non) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_failed_to_read_one_byte_on_a_non);
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 491, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __PYX_ERR(1, 491, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/buffer.pyx":490
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(1)
+ *             if cbuf == NULL:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.BufferError(
+ *                     'failed to read one byte on a non-empty buffer')
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":493
+ *                 raise exceptions.BufferError(
+ *                     'failed to read one byte on a non-empty buffer')
+ *             self._current_message_type = cbuf[0]             # <<<<<<<<<<<<<<
+ * 
+ *         if self._current_message_len == 0:
+ */
+    __pyx_v_self->_current_message_type = (__pyx_v_cbuf[0]);
+
+    /* "asyncpg/pgproto/buffer.pyx":485
+ *             return 1
+ * 
+ *         if self._current_message_type == 0:             # <<<<<<<<<<<<<<
+ *             if self._length < 1:
+ *                 return 0
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":495
+ *             self._current_message_type = cbuf[0]
+ * 
+ *         if self._current_message_len == 0:             # <<<<<<<<<<<<<<
+ *             if self._length < 4:
+ *                 return 0
+ */
+  __pyx_t_1 = ((__pyx_v_self->_current_message_len == 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":496
+ * 
+ *         if self._current_message_len == 0:
+ *             if self._length < 4:             # <<<<<<<<<<<<<<
+ *                 return 0
+ * 
+ */
+    __pyx_t_1 = ((__pyx_v_self->_length < 4) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":497
+ *         if self._current_message_len == 0:
+ *             if self._length < 4:
+ *                 return 0             # <<<<<<<<<<<<<<
+ * 
+ *             self._ensure_first_buf()
+ */
+      __pyx_r = 0;
+      goto __pyx_L0;
+
+      /* "asyncpg/pgproto/buffer.pyx":496
+ * 
+ *         if self._current_message_len == 0:
+ *             if self._length < 4:             # <<<<<<<<<<<<<<
+ *                 return 0
+ * 
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":499
+ *                 return 0
+ * 
+ *             self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *             cbuf = self._try_read_bytes(4)
+ *             if cbuf != NULL:
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 499, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":500
+ * 
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(4)             # <<<<<<<<<<<<<<
+ *             if cbuf != NULL:
+ *                 self._current_message_len = hton.unpack_int32(cbuf)
+ */
+    __pyx_v_cbuf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, 4);
+
+    /* "asyncpg/pgproto/buffer.pyx":501
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(4)
+ *             if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *                 self._current_message_len = hton.unpack_int32(cbuf)
+ *             else:
+ */
+    __pyx_t_1 = ((__pyx_v_cbuf != NULL) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":502
+ *             cbuf = self._try_read_bytes(4)
+ *             if cbuf != NULL:
+ *                 self._current_message_len = hton.unpack_int32(cbuf)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 self._current_message_len = self.read_int32()
+ */
+      __pyx_v_self->_current_message_len = unpack_int32(__pyx_v_cbuf);
+
+      /* "asyncpg/pgproto/buffer.pyx":501
+ *             self._ensure_first_buf()
+ *             cbuf = self._try_read_bytes(4)
+ *             if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *                 self._current_message_len = hton.unpack_int32(cbuf)
+ *             else:
+ */
+      goto __pyx_L9;
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":504
+ *                 self._current_message_len = hton.unpack_int32(cbuf)
+ *             else:
+ *                 self._current_message_len = self.read_int32()             # <<<<<<<<<<<<<<
+ * 
+ *             self._current_message_len_unread = self._current_message_len - 4
+ */
+    /*else*/ {
+      __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int32(__pyx_v_self); if (unlikely(__pyx_t_5 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 504, __pyx_L1_error)
+      __pyx_v_self->_current_message_len = __pyx_t_5;
+    }
+    __pyx_L9:;
+
+    /* "asyncpg/pgproto/buffer.pyx":506
+ *                 self._current_message_len = self.read_int32()
+ * 
+ *             self._current_message_len_unread = self._current_message_len - 4             # <<<<<<<<<<<<<<
+ * 
+ *         if self._length < self._current_message_len_unread:
+ */
+    __pyx_v_self->_current_message_len_unread = (__pyx_v_self->_current_message_len - 4);
+
+    /* "asyncpg/pgproto/buffer.pyx":495
+ *             self._current_message_type = cbuf[0]
+ * 
+ *         if self._current_message_len == 0:             # <<<<<<<<<<<<<<
+ *             if self._length < 4:
+ *                 return 0
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":508
+ *             self._current_message_len_unread = self._current_message_len - 4
+ * 
+ *         if self._length < self._current_message_len_unread:             # <<<<<<<<<<<<<<
+ *             return 0
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_self->_length < __pyx_v_self->_current_message_len_unread) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":509
+ * 
+ *         if self._length < self._current_message_len_unread:
+ *             return 0             # <<<<<<<<<<<<<<
+ * 
+ *         self._current_message_ready = 1
+ */
+    __pyx_r = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":508
+ *             self._current_message_len_unread = self._current_message_len - 4
+ * 
+ *         if self._length < self._current_message_len_unread:             # <<<<<<<<<<<<<<
+ *             return 0
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":511
+ *             return 0
+ * 
+ *         self._current_message_ready = 1             # <<<<<<<<<<<<<<
+ *         return 1
+ * 
+ */
+  __pyx_v_self->_current_message_ready = 1;
+
+  /* "asyncpg/pgproto/buffer.pyx":512
+ * 
+ *         self._current_message_ready = 1
+ *         return 1             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline int32_t take_message_type(self, char mtype) except -1:
+ */
+  __pyx_r = 1;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":478
+ *                 self._ensure_first_buf()
+ * 
+ *     cdef int32_t take_message(self) except -1:             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             const char *cbuf
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.take_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":514
+ *         return 1
+ * 
+ *     cdef inline int32_t take_message_type(self, char mtype) except -1:             # <<<<<<<<<<<<<<
+ *         cdef const char *buf0
+ * 
+ */
+
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, char __pyx_v_mtype) {
+  char const *__pyx_v_buf0;
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  int32_t __pyx_t_3;
+  int32_t __pyx_t_4;
+  __Pyx_RefNannySetupContext("take_message_type", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":517
+ *         cdef const char *buf0
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             return self._current_message_type == mtype
+ *         elif self._length >= 1:
+ */
+  __pyx_t_1 = (__pyx_v_self->_current_message_ready != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":518
+ * 
+ *         if self._current_message_ready:
+ *             return self._current_message_type == mtype             # <<<<<<<<<<<<<<
+ *         elif self._length >= 1:
+ *             self._ensure_first_buf()
+ */
+    __pyx_r = (__pyx_v_self->_current_message_type == __pyx_v_mtype);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":517
+ *         cdef const char *buf0
+ * 
+ *         if self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             return self._current_message_type == mtype
+ *         elif self._length >= 1:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":519
+ *         if self._current_message_ready:
+ *             return self._current_message_type == mtype
+ *         elif self._length >= 1:             # <<<<<<<<<<<<<<
+ *             self._ensure_first_buf()
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ */
+  __pyx_t_1 = ((__pyx_v_self->_length >= 1) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":520
+ *             return self._current_message_type == mtype
+ *         elif self._length >= 1:
+ *             self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ * 
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 520, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":521
+ *         elif self._length >= 1:
+ *             self._ensure_first_buf()
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)             # <<<<<<<<<<<<<<
+ * 
+ *             return buf0[self._pos0] == mtype and self.take_message()
+ */
+    __pyx_t_2 = __pyx_v_self->_buf0;
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_v_buf0 = PyBytes_AS_STRING(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":523
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ * 
+ *             return buf0[self._pos0] == mtype and self.take_message()             # <<<<<<<<<<<<<<
+ *         else:
+ *             return 0
+ */
+    __pyx_t_1 = ((__pyx_v_buf0[__pyx_v_self->_pos0]) == __pyx_v_mtype);
+    if (__pyx_t_1) {
+    } else {
+      __pyx_t_3 = __pyx_t_1;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message(__pyx_v_self); if (unlikely(__pyx_t_4 == ((int32_t)-1))) __PYX_ERR(1, 523, __pyx_L1_error)
+    __pyx_t_3 = __pyx_t_4;
+    __pyx_L4_bool_binop_done:;
+    __pyx_r = __pyx_t_3;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":519
+ *         if self._current_message_ready:
+ *             return self._current_message_type == mtype
+ *         elif self._length >= 1:             # <<<<<<<<<<<<<<
+ *             self._ensure_first_buf()
+ *             buf0 = cpython.PyBytes_AS_STRING(self._buf0)
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":525
+ *             return buf0[self._pos0] == mtype and self.take_message()
+ *         else:
+ *             return 0             # <<<<<<<<<<<<<<
+ * 
+ *     cdef int32_t put_message(self) except -1:
+ */
+  /*else*/ {
+    __pyx_r = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":514
+ *         return 1
+ * 
+ *     cdef inline int32_t take_message_type(self, char mtype) except -1:             # <<<<<<<<<<<<<<
+ *         cdef const char *buf0
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.take_message_type", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":527
+ *             return 0
+ * 
+ *     cdef int32_t put_message(self) except -1:             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(
+ */
+
+static int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_put_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("put_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":528
+ * 
+ *     cdef int32_t put_message(self) except -1:
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'cannot put message: no message taken')
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":529
+ *     cdef int32_t put_message(self) except -1:
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'cannot put message: no message taken')
+ *         self._current_message_ready = False
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 529, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 529, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_cannot_put_message_no_message_ta) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_cannot_put_message_no_message_ta);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 529, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 529, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":528
+ * 
+ *     cdef int32_t put_message(self) except -1:
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'cannot put message: no message taken')
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":531
+ *             raise exceptions.BufferError(
+ *                 'cannot put message: no message taken')
+ *         self._current_message_ready = False             # <<<<<<<<<<<<<<
+ *         return 0
+ * 
+ */
+  __pyx_v_self->_current_message_ready = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":532
+ *                 'cannot put message: no message taken')
+ *         self._current_message_ready = False
+ *         return 0             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline const char* try_consume_message(self, ssize_t* len):
+ */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":527
+ *             return 0
+ * 
+ *     cdef int32_t put_message(self) except -1:             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.put_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":534
+ *         return 0
+ * 
+ *     cdef inline const char* try_consume_message(self, ssize_t* len):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t buf_len
+ */
+
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_try_consume_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, Py_ssize_t *__pyx_v_len) {
+  Py_ssize_t __pyx_v_buf_len;
+  char const *__pyx_v_buf;
+  char const *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  __Pyx_RefNannySetupContext("try_consume_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":539
+ *             const char *buf
+ * 
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             return NULL
+ * 
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":540
+ * 
+ *         if not self._current_message_ready:
+ *             return NULL             # <<<<<<<<<<<<<<
+ * 
+ *         self._ensure_first_buf()
+ */
+    __pyx_r = NULL;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":539
+ *             const char *buf
+ * 
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             return NULL
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":542
+ *             return NULL
+ * 
+ *         self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *         buf_len = self._current_message_len_unread
+ *         buf = self._try_read_bytes(buf_len)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 542, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":543
+ * 
+ *         self._ensure_first_buf()
+ *         buf_len = self._current_message_len_unread             # <<<<<<<<<<<<<<
+ *         buf = self._try_read_bytes(buf_len)
+ *         if buf != NULL:
+ */
+  __pyx_t_3 = __pyx_v_self->_current_message_len_unread;
+  __pyx_v_buf_len = __pyx_t_3;
+
+  /* "asyncpg/pgproto/buffer.pyx":544
+ *         self._ensure_first_buf()
+ *         buf_len = self._current_message_len_unread
+ *         buf = self._try_read_bytes(buf_len)             # <<<<<<<<<<<<<<
+ *         if buf != NULL:
+ *             len[0] = buf_len
+ */
+  __pyx_v_buf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes(__pyx_v_self, __pyx_v_buf_len);
+
+  /* "asyncpg/pgproto/buffer.pyx":545
+ *         buf_len = self._current_message_len_unread
+ *         buf = self._try_read_bytes(buf_len)
+ *         if buf != NULL:             # <<<<<<<<<<<<<<
+ *             len[0] = buf_len
+ *             self._finish_message()
+ */
+  __pyx_t_1 = ((__pyx_v_buf != NULL) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":546
+ *         buf = self._try_read_bytes(buf_len)
+ *         if buf != NULL:
+ *             len[0] = buf_len             # <<<<<<<<<<<<<<
+ *             self._finish_message()
+ *         return buf
+ */
+    (__pyx_v_len[0]) = __pyx_v_buf_len;
+
+    /* "asyncpg/pgproto/buffer.pyx":547
+ *         if buf != NULL:
+ *             len[0] = buf_len
+ *             self._finish_message()             # <<<<<<<<<<<<<<
+ *         return buf
+ * 
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 547, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":545
+ *         buf_len = self._current_message_len_unread
+ *         buf = self._try_read_bytes(buf_len)
+ *         if buf != NULL:             # <<<<<<<<<<<<<<
+ *             len[0] = buf_len
+ *             self._finish_message()
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":548
+ *             len[0] = buf_len
+ *             self._finish_message()
+ *         return buf             # <<<<<<<<<<<<<<
+ * 
+ *     cdef discard_message(self):
+ */
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":534
+ *         return 0
+ * 
+ *     cdef inline const char* try_consume_message(self, ssize_t* len):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ssize_t buf_len
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_WriteUnraisable("asyncpg.pgproto.pgproto.ReadBuffer.try_consume_message", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":550
+ *         return buf
+ * 
+ *     cdef discard_message(self):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to discard')
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_discard_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("discard_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":551
+ * 
+ *     cdef discard_message(self):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('no message to discard')
+ *         if self._current_message_len_unread > 0:
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":552
+ *     cdef discard_message(self):
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to discard')             # <<<<<<<<<<<<<<
+ *         if self._current_message_len_unread > 0:
+ *             self._read_and_discard(self._current_message_len_unread)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 552, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 552, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_no_message_to_discard) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_no_message_to_discard);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 552, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 552, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":551
+ * 
+ *     cdef discard_message(self):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('no message to discard')
+ *         if self._current_message_len_unread > 0:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":553
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to discard')
+ *         if self._current_message_len_unread > 0:             # <<<<<<<<<<<<<<
+ *             self._read_and_discard(self._current_message_len_unread)
+ *             self._current_message_len_unread = 0
+ */
+  __pyx_t_1 = ((__pyx_v_self->_current_message_len_unread > 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":554
+ *             raise exceptions.BufferError('no message to discard')
+ *         if self._current_message_len_unread > 0:
+ *             self._read_and_discard(self._current_message_len_unread)             # <<<<<<<<<<<<<<
+ *             self._current_message_len_unread = 0
+ *         self._finish_message()
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_and_discard(__pyx_v_self, __pyx_v_self->_current_message_len_unread); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 554, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":555
+ *         if self._current_message_len_unread > 0:
+ *             self._read_and_discard(self._current_message_len_unread)
+ *             self._current_message_len_unread = 0             # <<<<<<<<<<<<<<
+ *         self._finish_message()
+ * 
+ */
+    __pyx_v_self->_current_message_len_unread = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":553
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to discard')
+ *         if self._current_message_len_unread > 0:             # <<<<<<<<<<<<<<
+ *             self._read_and_discard(self._current_message_len_unread)
+ *             self._current_message_len_unread = 0
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":556
+ *             self._read_and_discard(self._current_message_len_unread)
+ *             self._current_message_len_unread = 0
+ *         self._finish_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef bytes consume_message(self):
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 556, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":550
+ *         return buf
+ * 
+ *     cdef discard_message(self):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to discard')
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.discard_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":558
+ *         self._finish_message()
+ * 
+ *     cdef bytes consume_message(self):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to consume')
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_v_mem = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("consume_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":559
+ * 
+ *     cdef bytes consume_message(self):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('no message to consume')
+ *         if self._current_message_len_unread > 0:
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":560
+ *     cdef bytes consume_message(self):
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to consume')             # <<<<<<<<<<<<<<
+ *         if self._current_message_len_unread > 0:
+ *             mem = self.read_bytes(self._current_message_len_unread)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 560, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 560, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_no_message_to_consume) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_no_message_to_consume);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 560, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 560, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":559
+ * 
+ *     cdef bytes consume_message(self):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError('no message to consume')
+ *         if self._current_message_len_unread > 0:
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":561
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to consume')
+ *         if self._current_message_len_unread > 0:             # <<<<<<<<<<<<<<
+ *             mem = self.read_bytes(self._current_message_len_unread)
+ *         else:
+ */
+  __pyx_t_1 = ((__pyx_v_self->_current_message_len_unread > 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":562
+ *             raise exceptions.BufferError('no message to consume')
+ *         if self._current_message_len_unread > 0:
+ *             mem = self.read_bytes(self._current_message_len_unread)             # <<<<<<<<<<<<<<
+ *         else:
+ *             mem = b''
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes(__pyx_v_self, __pyx_v_self->_current_message_len_unread); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 562, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_v_mem = ((PyObject*)__pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":561
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to consume')
+ *         if self._current_message_len_unread > 0:             # <<<<<<<<<<<<<<
+ *             mem = self.read_bytes(self._current_message_len_unread)
+ *         else:
+ */
+    goto __pyx_L4;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":564
+ *             mem = self.read_bytes(self._current_message_len_unread)
+ *         else:
+ *             mem = b''             # <<<<<<<<<<<<<<
+ *         self._finish_message()
+ *         return mem
+ */
+  /*else*/ {
+    __Pyx_INCREF(__pyx_kp_b__3);
+    __pyx_v_mem = __pyx_kp_b__3;
+  }
+  __pyx_L4:;
+
+  /* "asyncpg/pgproto/buffer.pyx":565
+ *         else:
+ *             mem = b''
+ *         self._finish_message()             # <<<<<<<<<<<<<<
+ *         return mem
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 565, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":566
+ *             mem = b''
+ *         self._finish_message()
+ *         return mem             # <<<<<<<<<<<<<<
+ * 
+ *     cdef redirect_messages(self, WriteBuffer buf, char mtype):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_mem);
+  __pyx_r = __pyx_v_mem;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":558
+ *         self._finish_message()
+ * 
+ *     cdef bytes consume_message(self):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError('no message to consume')
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.consume_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_mem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":568
+ *         return mem
+ * 
+ *     cdef redirect_messages(self, WriteBuffer buf, char mtype):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_redirect_messages(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, char __pyx_v_mtype) {
+  char const *__pyx_v_cbuf;
+  Py_ssize_t __pyx_v_cbuf_len;
+  int32_t __pyx_v_msg_len;
+  Py_ssize_t __pyx_v_new_pos0;
+  Py_ssize_t __pyx_v_pos_delta;
+  int32_t __pyx_v_done;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  Py_ssize_t __pyx_t_5;
+  int32_t __pyx_t_6;
+  __Pyx_RefNannySetupContext("redirect_messages", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":569
+ * 
+ *     cdef redirect_messages(self, WriteBuffer buf, char mtype):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called on a buffer without a '
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":570
+ *     cdef redirect_messages(self, WriteBuffer buf, char mtype):
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'consume_full_messages called on a buffer without a '
+ *                 'complete first message')
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 570, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 570, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_consume_full_messages_called_on) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_consume_full_messages_called_on);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 570, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 570, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":569
+ * 
+ *     cdef redirect_messages(self, WriteBuffer buf, char mtype):
+ *         if not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called on a buffer without a '
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":573
+ *                 'consume_full_messages called on a buffer without a '
+ *                 'complete first message')
+ *         if mtype != self._current_message_type:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called with a wrong mtype')
+ */
+  __pyx_t_1 = ((__pyx_v_mtype != __pyx_v_self->_current_message_type) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":574
+ *                 'complete first message')
+ *         if mtype != self._current_message_type:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'consume_full_messages called with a wrong mtype')
+ *         if self._current_message_len_unread != self._current_message_len - 4:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 574, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 574, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_consume_full_messages_called_wit) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_consume_full_messages_called_wit);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 574, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 574, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":573
+ *                 'consume_full_messages called on a buffer without a '
+ *                 'complete first message')
+ *         if mtype != self._current_message_type:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called with a wrong mtype')
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":576
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called with a wrong mtype')
+ *         if self._current_message_len_unread != self._current_message_len - 4:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called on a partially read message')
+ */
+  __pyx_t_1 = ((__pyx_v_self->_current_message_len_unread != (__pyx_v_self->_current_message_len - 4)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/buffer.pyx":577
+ *                 'consume_full_messages called with a wrong mtype')
+ *         if self._current_message_len_unread != self._current_message_len - 4:
+ *             raise exceptions.BufferError(             # <<<<<<<<<<<<<<
+ *                 'consume_full_messages called on a partially read message')
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 577, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_BufferError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 577, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_consume_full_messages_called_on_2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_consume_full_messages_called_on_2);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 577, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 577, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/buffer.pyx":576
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called with a wrong mtype')
+ *         if self._current_message_len_unread != self._current_message_len - 4:             # <<<<<<<<<<<<<<
+ *             raise exceptions.BufferError(
+ *                 'consume_full_messages called on a partially read message')
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":588
+ *             int32_t done
+ * 
+ *         while True:             # <<<<<<<<<<<<<<
+ *             buf.write_byte(mtype)
+ *             buf.write_int32(self._current_message_len)
+ */
+  while (1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":589
+ * 
+ *         while True:
+ *             buf.write_byte(mtype)             # <<<<<<<<<<<<<<
+ *             buf.write_int32(self._current_message_len)
+ * 
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, __pyx_v_mtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 589, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":590
+ *         while True:
+ *             buf.write_byte(mtype)
+ *             buf.write_int32(self._current_message_len)             # <<<<<<<<<<<<<<
+ * 
+ *             cbuf = self.try_consume_message(&cbuf_len)
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_self->_current_message_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 590, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":592
+ *             buf.write_int32(self._current_message_len)
+ * 
+ *             cbuf = self.try_consume_message(&cbuf_len)             # <<<<<<<<<<<<<<
+ *             if cbuf != NULL:
+ *                 buf.write_cstr(cbuf, cbuf_len)
+ */
+    __pyx_v_cbuf = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_try_consume_message(__pyx_v_self, (&__pyx_v_cbuf_len));
+
+    /* "asyncpg/pgproto/buffer.pyx":593
+ * 
+ *             cbuf = self.try_consume_message(&cbuf_len)
+ *             if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *                 buf.write_cstr(cbuf, cbuf_len)
+ *             else:
+ */
+    __pyx_t_1 = ((__pyx_v_cbuf != NULL) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":594
+ *             cbuf = self.try_consume_message(&cbuf_len)
+ *             if cbuf != NULL:
+ *                 buf.write_cstr(cbuf, cbuf_len)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 buf.write_bytes(self.consume_message())
+ */
+      __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_buf, __pyx_v_cbuf, __pyx_v_cbuf_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 594, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":593
+ * 
+ *             cbuf = self.try_consume_message(&cbuf_len)
+ *             if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *                 buf.write_cstr(cbuf, cbuf_len)
+ *             else:
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":596
+ *                 buf.write_cstr(cbuf, cbuf_len)
+ *             else:
+ *                 buf.write_bytes(self.consume_message())             # <<<<<<<<<<<<<<
+ * 
+ *             # Fast path: exhaust buf0 as efficiently as possible.
+ */
+    /*else*/ {
+      __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_message(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 596, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytes(__pyx_v_buf, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 596, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    }
+    __pyx_L8:;
+
+    /* "asyncpg/pgproto/buffer.pyx":599
+ * 
+ *             # Fast path: exhaust buf0 as efficiently as possible.
+ *             self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *             if self._pos0 + 5 <= self._len0:
+ *                 cbuf = cpython.PyBytes_AS_STRING(self._buf0)
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 599, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":600
+ *             # Fast path: exhaust buf0 as efficiently as possible.
+ *             self._ensure_first_buf()
+ *             if self._pos0 + 5 <= self._len0:             # <<<<<<<<<<<<<<
+ *                 cbuf = cpython.PyBytes_AS_STRING(self._buf0)
+ *                 new_pos0 = self._pos0
+ */
+    __pyx_t_1 = (((__pyx_v_self->_pos0 + 5) <= __pyx_v_self->_len0) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":601
+ *             self._ensure_first_buf()
+ *             if self._pos0 + 5 <= self._len0:
+ *                 cbuf = cpython.PyBytes_AS_STRING(self._buf0)             # <<<<<<<<<<<<<<
+ *                 new_pos0 = self._pos0
+ *                 cbuf_len = self._len0
+ */
+      __pyx_t_4 = __pyx_v_self->_buf0;
+      __Pyx_INCREF(__pyx_t_4);
+      __pyx_v_cbuf = PyBytes_AS_STRING(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":602
+ *             if self._pos0 + 5 <= self._len0:
+ *                 cbuf = cpython.PyBytes_AS_STRING(self._buf0)
+ *                 new_pos0 = self._pos0             # <<<<<<<<<<<<<<
+ *                 cbuf_len = self._len0
+ * 
+ */
+      __pyx_t_5 = __pyx_v_self->_pos0;
+      __pyx_v_new_pos0 = __pyx_t_5;
+
+      /* "asyncpg/pgproto/buffer.pyx":603
+ *                 cbuf = cpython.PyBytes_AS_STRING(self._buf0)
+ *                 new_pos0 = self._pos0
+ *                 cbuf_len = self._len0             # <<<<<<<<<<<<<<
+ * 
+ *                 done = 0
+ */
+      __pyx_t_5 = __pyx_v_self->_len0;
+      __pyx_v_cbuf_len = __pyx_t_5;
+
+      /* "asyncpg/pgproto/buffer.pyx":605
+ *                 cbuf_len = self._len0
+ * 
+ *                 done = 0             # <<<<<<<<<<<<<<
+ *                 # Scan the first buffer and find the position of the
+ *                 # end of the last "mtype" message.
+ */
+      __pyx_v_done = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":608
+ *                 # Scan the first buffer and find the position of the
+ *                 # end of the last "mtype" message.
+ *                 while new_pos0 + 5 <= cbuf_len:             # <<<<<<<<<<<<<<
+ *                     if (cbuf + new_pos0)[0] != mtype:
+ *                         done = 1
+ */
+      while (1) {
+        __pyx_t_1 = (((__pyx_v_new_pos0 + 5) <= __pyx_v_cbuf_len) != 0);
+        if (!__pyx_t_1) break;
+
+        /* "asyncpg/pgproto/buffer.pyx":609
+ *                 # end of the last "mtype" message.
+ *                 while new_pos0 + 5 <= cbuf_len:
+ *                     if (cbuf + new_pos0)[0] != mtype:             # <<<<<<<<<<<<<<
+ *                         done = 1
+ *                         break
+ */
+        __pyx_t_1 = ((((__pyx_v_cbuf + __pyx_v_new_pos0)[0]) != __pyx_v_mtype) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/pgproto/buffer.pyx":610
+ *                 while new_pos0 + 5 <= cbuf_len:
+ *                     if (cbuf + new_pos0)[0] != mtype:
+ *                         done = 1             # <<<<<<<<<<<<<<
+ *                         break
+ *                     msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1
+ */
+          __pyx_v_done = 1;
+
+          /* "asyncpg/pgproto/buffer.pyx":611
+ *                     if (cbuf + new_pos0)[0] != mtype:
+ *                         done = 1
+ *                         break             # <<<<<<<<<<<<<<
+ *                     msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1
+ *                     if new_pos0 + msg_len > cbuf_len:
+ */
+          goto __pyx_L11_break;
+
+          /* "asyncpg/pgproto/buffer.pyx":609
+ *                 # end of the last "mtype" message.
+ *                 while new_pos0 + 5 <= cbuf_len:
+ *                     if (cbuf + new_pos0)[0] != mtype:             # <<<<<<<<<<<<<<
+ *                         done = 1
+ *                         break
+ */
+        }
+
+        /* "asyncpg/pgproto/buffer.pyx":612
+ *                         done = 1
+ *                         break
+ *                     msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1             # <<<<<<<<<<<<<<
+ *                     if new_pos0 + msg_len > cbuf_len:
+ *                         break
+ */
+        __pyx_v_msg_len = (unpack_int32(((__pyx_v_cbuf + __pyx_v_new_pos0) + 1)) + 1);
+
+        /* "asyncpg/pgproto/buffer.pyx":613
+ *                         break
+ *                     msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1
+ *                     if new_pos0 + msg_len > cbuf_len:             # <<<<<<<<<<<<<<
+ *                         break
+ *                     new_pos0 += msg_len
+ */
+        __pyx_t_1 = (((__pyx_v_new_pos0 + __pyx_v_msg_len) > __pyx_v_cbuf_len) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/pgproto/buffer.pyx":614
+ *                     msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1
+ *                     if new_pos0 + msg_len > cbuf_len:
+ *                         break             # <<<<<<<<<<<<<<
+ *                     new_pos0 += msg_len
+ * 
+ */
+          goto __pyx_L11_break;
+
+          /* "asyncpg/pgproto/buffer.pyx":613
+ *                         break
+ *                     msg_len = hton.unpack_int32(cbuf + new_pos0 + 1) + 1
+ *                     if new_pos0 + msg_len > cbuf_len:             # <<<<<<<<<<<<<<
+ *                         break
+ *                     new_pos0 += msg_len
+ */
+        }
+
+        /* "asyncpg/pgproto/buffer.pyx":615
+ *                     if new_pos0 + msg_len > cbuf_len:
+ *                         break
+ *                     new_pos0 += msg_len             # <<<<<<<<<<<<<<
+ * 
+ *                 if new_pos0 != self._pos0:
+ */
+        __pyx_v_new_pos0 = (__pyx_v_new_pos0 + __pyx_v_msg_len);
+      }
+      __pyx_L11_break:;
+
+      /* "asyncpg/pgproto/buffer.pyx":617
+ *                     new_pos0 += msg_len
+ * 
+ *                 if new_pos0 != self._pos0:             # <<<<<<<<<<<<<<
+ *                     if PG_DEBUG:
+ *                         assert self._pos0 < new_pos0 <= self._len0
+ */
+      __pyx_t_1 = ((__pyx_v_new_pos0 != __pyx_v_self->_pos0) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/pgproto/buffer.pyx":618
+ * 
+ *                 if new_pos0 != self._pos0:
+ *                     if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                         assert self._pos0 < new_pos0 <= self._len0
+ * 
+ */
+        __pyx_t_1 = (PG_DEBUG != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/pgproto/buffer.pyx":619
+ *                 if new_pos0 != self._pos0:
+ *                     if PG_DEBUG:
+ *                         assert self._pos0 < new_pos0 <= self._len0             # <<<<<<<<<<<<<<
+ * 
+ *                     pos_delta = new_pos0 - self._pos0
+ */
+          #ifndef CYTHON_WITHOUT_ASSERTIONS
+          if (unlikely(!Py_OptimizeFlag)) {
+            __pyx_t_1 = (__pyx_v_self->_pos0 < __pyx_v_new_pos0);
+            if (__pyx_t_1) {
+              __pyx_t_1 = (__pyx_v_new_pos0 <= __pyx_v_self->_len0);
+            }
+            if (unlikely(!(__pyx_t_1 != 0))) {
+              PyErr_SetNone(PyExc_AssertionError);
+              __PYX_ERR(1, 619, __pyx_L1_error)
+            }
+          }
+          #endif
+
+          /* "asyncpg/pgproto/buffer.pyx":618
+ * 
+ *                 if new_pos0 != self._pos0:
+ *                     if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                         assert self._pos0 < new_pos0 <= self._len0
+ * 
+ */
+        }
+
+        /* "asyncpg/pgproto/buffer.pyx":621
+ *                         assert self._pos0 < new_pos0 <= self._len0
+ * 
+ *                     pos_delta = new_pos0 - self._pos0             # <<<<<<<<<<<<<<
+ *                     buf.write_cstr(
+ *                         cbuf + self._pos0,
+ */
+        __pyx_v_pos_delta = (__pyx_v_new_pos0 - __pyx_v_self->_pos0);
+
+        /* "asyncpg/pgproto/buffer.pyx":622
+ * 
+ *                     pos_delta = new_pos0 - self._pos0
+ *                     buf.write_cstr(             # <<<<<<<<<<<<<<
+ *                         cbuf + self._pos0,
+ *                         pos_delta)
+ */
+        __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_buf, (__pyx_v_cbuf + __pyx_v_self->_pos0), __pyx_v_pos_delta); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 622, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/pgproto/buffer.pyx":626
+ *                         pos_delta)
+ * 
+ *                     self._pos0 = new_pos0             # <<<<<<<<<<<<<<
+ *                     self._length -= pos_delta
+ * 
+ */
+        __pyx_v_self->_pos0 = __pyx_v_new_pos0;
+
+        /* "asyncpg/pgproto/buffer.pyx":627
+ * 
+ *                     self._pos0 = new_pos0
+ *                     self._length -= pos_delta             # <<<<<<<<<<<<<<
+ * 
+ *                     if PG_DEBUG:
+ */
+        __pyx_v_self->_length = (__pyx_v_self->_length - __pyx_v_pos_delta);
+
+        /* "asyncpg/pgproto/buffer.pyx":629
+ *                     self._length -= pos_delta
+ * 
+ *                     if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                         assert self._length >= 0
+ * 
+ */
+        __pyx_t_1 = (PG_DEBUG != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/pgproto/buffer.pyx":630
+ * 
+ *                     if PG_DEBUG:
+ *                         assert self._length >= 0             # <<<<<<<<<<<<<<
+ * 
+ *                 if done:
+ */
+          #ifndef CYTHON_WITHOUT_ASSERTIONS
+          if (unlikely(!Py_OptimizeFlag)) {
+            if (unlikely(!((__pyx_v_self->_length >= 0) != 0))) {
+              PyErr_SetNone(PyExc_AssertionError);
+              __PYX_ERR(1, 630, __pyx_L1_error)
+            }
+          }
+          #endif
+
+          /* "asyncpg/pgproto/buffer.pyx":629
+ *                     self._length -= pos_delta
+ * 
+ *                     if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                         assert self._length >= 0
+ * 
+ */
+        }
+
+        /* "asyncpg/pgproto/buffer.pyx":617
+ *                     new_pos0 += msg_len
+ * 
+ *                 if new_pos0 != self._pos0:             # <<<<<<<<<<<<<<
+ *                     if PG_DEBUG:
+ *                         assert self._pos0 < new_pos0 <= self._len0
+ */
+      }
+
+      /* "asyncpg/pgproto/buffer.pyx":632
+ *                         assert self._length >= 0
+ * 
+ *                 if done:             # <<<<<<<<<<<<<<
+ *                     # The next message is of a different type.
+ *                     return
+ */
+      __pyx_t_1 = (__pyx_v_done != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/pgproto/buffer.pyx":634
+ *                 if done:
+ *                     # The next message is of a different type.
+ *                     return             # <<<<<<<<<<<<<<
+ * 
+ *             # Back to slow path.
+ */
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+        goto __pyx_L0;
+
+        /* "asyncpg/pgproto/buffer.pyx":632
+ *                         assert self._length >= 0
+ * 
+ *                 if done:             # <<<<<<<<<<<<<<
+ *                     # The next message is of a different type.
+ *                     return
+ */
+      }
+
+      /* "asyncpg/pgproto/buffer.pyx":600
+ *             # Fast path: exhaust buf0 as efficiently as possible.
+ *             self._ensure_first_buf()
+ *             if self._pos0 + 5 <= self._len0:             # <<<<<<<<<<<<<<
+ *                 cbuf = cpython.PyBytes_AS_STRING(self._buf0)
+ *                 new_pos0 = self._pos0
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":637
+ * 
+ *             # Back to slow path.
+ *             if not self.take_message_type(mtype):             # <<<<<<<<<<<<<<
+ *                 return
+ * 
+ */
+    __pyx_t_6 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type(__pyx_v_self, __pyx_v_mtype); if (unlikely(__pyx_t_6 == ((int32_t)-1))) __PYX_ERR(1, 637, __pyx_L1_error)
+    __pyx_t_1 = ((!(__pyx_t_6 != 0)) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":638
+ *             # Back to slow path.
+ *             if not self.take_message_type(mtype):
+ *                 return             # <<<<<<<<<<<<<<
+ * 
+ *     cdef bytearray consume_messages(self, char mtype):
+ */
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+      goto __pyx_L0;
+
+      /* "asyncpg/pgproto/buffer.pyx":637
+ * 
+ *             # Back to slow path.
+ *             if not self.take_message_type(mtype):             # <<<<<<<<<<<<<<
+ *                 return
+ * 
+ */
+    }
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":568
+ *         return mem
+ * 
+ *     cdef redirect_messages(self, WriteBuffer buf, char mtype):             # <<<<<<<<<<<<<<
+ *         if not self._current_message_ready:
+ *             raise exceptions.BufferError(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.redirect_messages", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":640
+ *                 return
+ * 
+ *     cdef bytearray consume_messages(self, char mtype):             # <<<<<<<<<<<<<<
+ *         """Consume consecutive messages of the same type."""
+ *         cdef:
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_messages(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, char __pyx_v_mtype) {
+  char *__pyx_v_buf;
+  Py_ssize_t __pyx_v_nbytes;
+  Py_ssize_t __pyx_v_total_bytes;
+  PyObject *__pyx_v_result = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int32_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  Py_ssize_t __pyx_t_4;
+  int __pyx_t_5;
+  __Pyx_RefNannySetupContext("consume_messages", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":645
+ *             char *buf
+ *             ssize_t nbytes
+ *             ssize_t total_bytes = 0             # <<<<<<<<<<<<<<
+ *             bytearray result
+ * 
+ */
+  __pyx_v_total_bytes = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":648
+ *             bytearray result
+ * 
+ *         if not self.take_message_type(mtype):             # <<<<<<<<<<<<<<
+ *             return None
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type(__pyx_v_self, __pyx_v_mtype); if (unlikely(__pyx_t_1 == ((int32_t)-1))) __PYX_ERR(1, 648, __pyx_L1_error)
+  __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/buffer.pyx":649
+ * 
+ *         if not self.take_message_type(mtype):
+ *             return None             # <<<<<<<<<<<<<<
+ * 
+ *         # consume_messages is a volume-oriented method, so
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":648
+ *             bytearray result
+ * 
+ *         if not self.take_message_type(mtype):             # <<<<<<<<<<<<<<
+ *             return None
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":654
+ *         # we assume that the remainder of the buffer will contain
+ *         # messages of the requested type.
+ *         result = cpythonx.PyByteArray_FromStringAndSize(NULL, self._length)             # <<<<<<<<<<<<<<
+ *         buf = cpythonx.PyByteArray_AsString(result)
+ * 
+ */
+  __pyx_t_3 = PyByteArray_FromStringAndSize(NULL, __pyx_v_self->_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 654, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  if (!(likely(PyByteArray_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 654, __pyx_L1_error)
+  __pyx_v_result = ((PyObject*)__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":655
+ *         # messages of the requested type.
+ *         result = cpythonx.PyByteArray_FromStringAndSize(NULL, self._length)
+ *         buf = cpythonx.PyByteArray_AsString(result)             # <<<<<<<<<<<<<<
+ * 
+ *         while self.take_message_type(mtype):
+ */
+  __pyx_v_buf = PyByteArray_AsString(__pyx_v_result);
+
+  /* "asyncpg/pgproto/buffer.pyx":657
+ *         buf = cpythonx.PyByteArray_AsString(result)
+ * 
+ *         while self.take_message_type(mtype):             # <<<<<<<<<<<<<<
+ *             self._ensure_first_buf()
+ *             nbytes = self._current_message_len_unread
+ */
+  while (1) {
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type(__pyx_v_self, __pyx_v_mtype); if (unlikely(__pyx_t_1 == ((int32_t)-1))) __PYX_ERR(1, 657, __pyx_L1_error)
+    __pyx_t_2 = (__pyx_t_1 != 0);
+    if (!__pyx_t_2) break;
+
+    /* "asyncpg/pgproto/buffer.pyx":658
+ * 
+ *         while self.take_message_type(mtype):
+ *             self._ensure_first_buf()             # <<<<<<<<<<<<<<
+ *             nbytes = self._current_message_len_unread
+ *             self._read_into(buf, nbytes)
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 658, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":659
+ *         while self.take_message_type(mtype):
+ *             self._ensure_first_buf()
+ *             nbytes = self._current_message_len_unread             # <<<<<<<<<<<<<<
+ *             self._read_into(buf, nbytes)
+ *             buf += nbytes
+ */
+    __pyx_t_4 = __pyx_v_self->_current_message_len_unread;
+    __pyx_v_nbytes = __pyx_t_4;
+
+    /* "asyncpg/pgproto/buffer.pyx":660
+ *             self._ensure_first_buf()
+ *             nbytes = self._current_message_len_unread
+ *             self._read_into(buf, nbytes)             # <<<<<<<<<<<<<<
+ *             buf += nbytes
+ *             total_bytes += nbytes
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_into(__pyx_v_self, __pyx_v_buf, __pyx_v_nbytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 660, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":661
+ *             nbytes = self._current_message_len_unread
+ *             self._read_into(buf, nbytes)
+ *             buf += nbytes             # <<<<<<<<<<<<<<
+ *             total_bytes += nbytes
+ *             self._finish_message()
+ */
+    __pyx_v_buf = (__pyx_v_buf + __pyx_v_nbytes);
+
+    /* "asyncpg/pgproto/buffer.pyx":662
+ *             self._read_into(buf, nbytes)
+ *             buf += nbytes
+ *             total_bytes += nbytes             # <<<<<<<<<<<<<<
+ *             self._finish_message()
+ * 
+ */
+    __pyx_v_total_bytes = (__pyx_v_total_bytes + __pyx_v_nbytes);
+
+    /* "asyncpg/pgproto/buffer.pyx":663
+ *             buf += nbytes
+ *             total_bytes += nbytes
+ *             self._finish_message()             # <<<<<<<<<<<<<<
+ * 
+ *         # Clamp the result to an actual size read.
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 663, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":666
+ * 
+ *         # Clamp the result to an actual size read.
+ *         cpythonx.PyByteArray_Resize(result, total_bytes)             # <<<<<<<<<<<<<<
+ * 
+ *         return result
+ */
+  __pyx_t_5 = PyByteArray_Resize(__pyx_v_result, __pyx_v_total_bytes); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 666, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/buffer.pyx":668
+ *         cpythonx.PyByteArray_Resize(result, total_bytes)
+ * 
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     cdef finish_message(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":640
+ *                 return
+ * 
+ *     cdef bytearray consume_messages(self, char mtype):             # <<<<<<<<<<<<<<
+ *         """Consume consecutive messages of the same type."""
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.consume_messages", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":670
+ *         return result
+ * 
+ *     cdef finish_message(self):             # <<<<<<<<<<<<<<
+ *         if self._current_message_type == 0 or not self._current_message_ready:
+ *             # The message has already been finished (e.g by consume_message()),
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_finish_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_v_mtype = NULL;
+  PyObject *__pyx_v_discarded = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("finish_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":671
+ * 
+ *     cdef finish_message(self):
+ *         if self._current_message_type == 0 or not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             # The message has already been finished (e.g by consume_message()),
+ *             # or has been put back by put_message().
+ */
+  __pyx_t_2 = ((__pyx_v_self->_current_message_type == 0) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = ((!(__pyx_v_self->_current_message_ready != 0)) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":674
+ *             # The message has already been finished (e.g by consume_message()),
+ *             # or has been put back by put_message().
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         if self._current_message_len_unread:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/buffer.pyx":671
+ * 
+ *     cdef finish_message(self):
+ *         if self._current_message_type == 0 or not self._current_message_ready:             # <<<<<<<<<<<<<<
+ *             # The message has already been finished (e.g by consume_message()),
+ *             # or has been put back by put_message().
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":676
+ *             return
+ * 
+ *         if self._current_message_len_unread:             # <<<<<<<<<<<<<<
+ *             if PG_DEBUG:
+ *                 mtype = chr(self._current_message_type)
+ */
+  __pyx_t_1 = (__pyx_v_self->_current_message_len_unread != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/buffer.pyx":677
+ * 
+ *         if self._current_message_len_unread:
+ *             if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                 mtype = chr(self._current_message_type)
+ * 
+ */
+    __pyx_t_1 = (PG_DEBUG != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":678
+ *         if self._current_message_len_unread:
+ *             if PG_DEBUG:
+ *                 mtype = chr(self._current_message_type)             # <<<<<<<<<<<<<<
+ * 
+ *             discarded = self.consume_message()
+ */
+      __pyx_t_3 = __Pyx_PyInt_From_char(__pyx_v_self->_current_message_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 678, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 678, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __pyx_v_mtype = __pyx_t_4;
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":677
+ * 
+ *         if self._current_message_len_unread:
+ *             if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                 mtype = chr(self._current_message_type)
+ * 
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":680
+ *                 mtype = chr(self._current_message_type)
+ * 
+ *             discarded = self.consume_message()             # <<<<<<<<<<<<<<
+ * 
+ *             if PG_DEBUG:
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_message(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 680, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_v_discarded = ((PyObject*)__pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/buffer.pyx":682
+ *             discarded = self.consume_message()
+ * 
+ *             if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                 print('!!! discarding message {!r} unread data: {!r}'.format(
+ *                     mtype,
+ */
+    __pyx_t_1 = (PG_DEBUG != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/pgproto/buffer.pyx":683
+ * 
+ *             if PG_DEBUG:
+ *                 print('!!! discarding message {!r} unread data: {!r}'.format(             # <<<<<<<<<<<<<<
+ *                     mtype,
+ *                     discarded))
+ */
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_discarding_message_r_unread_dat, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 683, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+
+      /* "asyncpg/pgproto/buffer.pyx":684
+ *             if PG_DEBUG:
+ *                 print('!!! discarding message {!r} unread data: {!r}'.format(
+ *                     mtype,             # <<<<<<<<<<<<<<
+ *                     discarded))
+ * 
+ */
+      if (unlikely(!__pyx_v_mtype)) { __Pyx_RaiseUnboundLocalError("mtype"); __PYX_ERR(1, 684, __pyx_L1_error) }
+
+      /* "asyncpg/pgproto/buffer.pyx":685
+ *                 print('!!! discarding message {!r} unread data: {!r}'.format(
+ *                     mtype,
+ *                     discarded))             # <<<<<<<<<<<<<<
+ * 
+ *         self._finish_message()
+ */
+      __pyx_t_5 = NULL;
+      __pyx_t_6 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_5)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_5);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+          __pyx_t_6 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_3)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_mtype, __pyx_v_discarded};
+        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 683, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_GOTREF(__pyx_t_4);
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_mtype, __pyx_v_discarded};
+        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 683, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_GOTREF(__pyx_t_4);
+      } else
+      #endif
+      {
+        __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 683, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        if (__pyx_t_5) {
+          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+        }
+        __Pyx_INCREF(__pyx_v_mtype);
+        __Pyx_GIVEREF(__pyx_v_mtype);
+        PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_mtype);
+        __Pyx_INCREF(__pyx_v_discarded);
+        __Pyx_GIVEREF(__pyx_v_discarded);
+        PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_discarded);
+        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 683, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":683
+ * 
+ *             if PG_DEBUG:
+ *                 print('!!! discarding message {!r} unread data: {!r}'.format(             # <<<<<<<<<<<<<<
+ *                     mtype,
+ *                     discarded))
+ */
+      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 683, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/pgproto/buffer.pyx":682
+ *             discarded = self.consume_message()
+ * 
+ *             if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *                 print('!!! discarding message {!r} unread data: {!r}'.format(
+ *                     mtype,
+ */
+    }
+
+    /* "asyncpg/pgproto/buffer.pyx":676
+ *             return
+ * 
+ *         if self._current_message_len_unread:             # <<<<<<<<<<<<<<
+ *             if PG_DEBUG:
+ *                 mtype = chr(self._current_message_type)
+ */
+  }
+
+  /* "asyncpg/pgproto/buffer.pyx":687
+ *                     discarded))
+ * 
+ *         self._finish_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _finish_message(self):
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 687, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":670
+ *         return result
+ * 
+ *     cdef finish_message(self):             # <<<<<<<<<<<<<<
+ *         if self._current_message_type == 0 or not self._current_message_ready:
+ *             # The message has already been finished (e.g by consume_message()),
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.finish_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_mtype);
+  __Pyx_XDECREF(__pyx_v_discarded);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":689
+ *         self._finish_message()
+ * 
+ *     cdef inline _finish_message(self):             # <<<<<<<<<<<<<<
+ *         self._current_message_type = 0
+ *         self._current_message_len = 0
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_finish_message", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":690
+ * 
+ *     cdef inline _finish_message(self):
+ *         self._current_message_type = 0             # <<<<<<<<<<<<<<
+ *         self._current_message_len = 0
+ *         self._current_message_ready = 0
+ */
+  __pyx_v_self->_current_message_type = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":691
+ *     cdef inline _finish_message(self):
+ *         self._current_message_type = 0
+ *         self._current_message_len = 0             # <<<<<<<<<<<<<<
+ *         self._current_message_ready = 0
+ *         self._current_message_len_unread = 0
+ */
+  __pyx_v_self->_current_message_len = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":692
+ *         self._current_message_type = 0
+ *         self._current_message_len = 0
+ *         self._current_message_ready = 0             # <<<<<<<<<<<<<<
+ *         self._current_message_len_unread = 0
+ * 
+ */
+  __pyx_v_self->_current_message_ready = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":693
+ *         self._current_message_len = 0
+ *         self._current_message_ready = 0
+ *         self._current_message_len_unread = 0             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __pyx_v_self->_current_message_len_unread = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":689
+ *         self._finish_message()
+ * 
+ *     cdef inline _finish_message(self):             # <<<<<<<<<<<<<<
+ *         self._current_message_type = 0
+ *         self._current_message_len = 0
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pyx":696
+ * 
+ *     @staticmethod
+ *     cdef ReadBuffer new_message_parser(object data):             # <<<<<<<<<<<<<<
+ *         cdef ReadBuffer buf
+ * 
+ */
+
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_new_message_parser(PyObject *__pyx_v_data) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_buf = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  __Pyx_RefNannySetupContext("new_message_parser", 0);
+
+  /* "asyncpg/pgproto/buffer.pyx":699
+ *         cdef ReadBuffer buf
+ * 
+ *         buf = ReadBuffer.__new__(ReadBuffer)             # <<<<<<<<<<<<<<
+ *         buf.feed_data(data)
+ * 
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_tp_new_7asyncpg_7pgproto_7pgproto_ReadBuffer(((PyTypeObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 699, __pyx_L1_error)
+  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":700
+ * 
+ *         buf = ReadBuffer.__new__(ReadBuffer)
+ *         buf.feed_data(data)             # <<<<<<<<<<<<<<
+ * 
+ *         buf._current_message_ready = 1
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_feed_data(__pyx_v_buf, __pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 700, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":702
+ *         buf.feed_data(data)
+ * 
+ *         buf._current_message_ready = 1             # <<<<<<<<<<<<<<
+ *         buf._current_message_len_unread = buf._len0
+ * 
+ */
+  __pyx_v_buf->_current_message_ready = 1;
+
+  /* "asyncpg/pgproto/buffer.pyx":703
+ * 
+ *         buf._current_message_ready = 1
+ *         buf._current_message_len_unread = buf._len0             # <<<<<<<<<<<<<<
+ * 
+ *         return buf
+ */
+  __pyx_t_2 = __pyx_v_buf->_len0;
+  __pyx_v_buf->_current_message_len_unread = __pyx_t_2;
+
+  /* "asyncpg/pgproto/buffer.pyx":705
+ *         buf._current_message_len_unread = buf._len0
+ * 
+ *         return buf             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_buf));
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pyx":696
+ * 
+ *     @staticmethod
+ *     cdef ReadBuffer new_message_parser(object data):             # <<<<<<<<<<<<<<
+ *         cdef ReadBuffer buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.new_message_parser", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer_2__reduce_cython__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer_2__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 2, __pyx_L1_error)
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer_4__setstate_cython__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_10ReadBuffer_4__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 4, __pyx_L1_error)
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/context.pyx":10
+ * cdef class CodecContext:
+ * 
+ *     cpdef get_text_codec(self):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ * 
+ */
+
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_1get_text_codec(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self, int __pyx_skip_dispatch) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("get_text_codec", 0);
+  /* Check if called by wrapper */
+  if (unlikely(__pyx_skip_dispatch)) ;
+  /* Check if overridden in Python */
+  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
+    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP
+    static PY_UINT64_T tp_dict_version = 0, obj_dict_version = 0;
+    if (likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict && tp_dict_version == __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) && (!Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset || obj_dict_version == __PYX_GET_DICT_VERSION(_PyObject_GetDictPtr(((PyObject *)__pyx_v_self))))));
+    else {
+      PY_UINT64_T type_dict_guard = (likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict)) ? __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) : 0;
+      #endif
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_text_codec); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 10, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_1get_text_codec)) {
+        __Pyx_XDECREF(__pyx_r);
+        __Pyx_INCREF(__pyx_t_1);
+        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+          if (likely(__pyx_t_4)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+            __Pyx_INCREF(__pyx_t_4);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_3, function);
+          }
+        }
+        __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 10, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __pyx_r = __pyx_t_2;
+        __pyx_t_2 = 0;
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+        goto __pyx_L0;
+      }
+      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP
+      tp_dict_version = likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) ? __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) : 0;
+      obj_dict_version = likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset) ? __PYX_GET_DICT_VERSION(_PyObject_GetDictPtr(((PyObject *)__pyx_v_self))) : 0;
+      if (unlikely(type_dict_guard != tp_dict_version)) {
+        tp_dict_version = obj_dict_version = 0;
+      }
+      #endif
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP
+    }
+    #endif
+  }
+
+  /* "asyncpg/pgproto/codecs/context.pyx":11
+ * 
+ *     cpdef get_text_codec(self):
+ *         raise NotImplementedError             # <<<<<<<<<<<<<<
+ * 
+ *     cdef is_encoding_utf8(self):
+ */
+  __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
+  __PYX_ERR(3, 11, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/codecs/context.pyx":10
+ * cdef class CodecContext:
+ * 
+ *     cpdef get_text_codec(self):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.CodecContext.get_text_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_1get_text_codec(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_1get_text_codec(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_text_codec (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("get_text_codec", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.CodecContext.get_text_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/context.pyx":13
+ *         raise NotImplementedError
+ * 
+ *     cdef is_encoding_utf8(self):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_is_encoding_utf8(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("is_encoding_utf8", 0);
+
+  /* "asyncpg/pgproto/codecs/context.pyx":14
+ * 
+ *     cdef is_encoding_utf8(self):
+ *         raise NotImplementedError             # <<<<<<<<<<<<<<
+ */
+  __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
+  __PYX_ERR(3, 14, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/codecs/context.pyx":13
+ *         raise NotImplementedError
+ * 
+ *     cdef is_encoding_utf8(self):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.CodecContext.is_encoding_utf8", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = ()
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_2__reduce_cython__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_2__reduce_cython__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self) {
+  int __pyx_v_use_setstate;
+  PyObject *__pyx_v_state = NULL;
+  PyObject *__pyx_v__dict = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     cdef bint use_setstate
+ *     state = ()             # <<<<<<<<<<<<<<
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ */
+  __Pyx_INCREF(__pyx_empty_tuple);
+  __pyx_v_state = __pyx_empty_tuple;
+
+  /* "(tree fragment)":4
+ *     cdef bint use_setstate
+ *     state = ()
+ *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
+ *     if _dict is not None:
+ *         state += (_dict,)
+ */
+  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v__dict = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "(tree fragment)":5
+ *     state = ()
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+  __pyx_t_2 = (__pyx_v__dict != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "(tree fragment)":6
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ *         state += (_dict,)             # <<<<<<<<<<<<<<
+ *         use_setstate = True
+ *     else:
+ */
+    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_INCREF(__pyx_v__dict);
+    __Pyx_GIVEREF(__pyx_v__dict);
+    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict);
+    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4));
+    __pyx_t_4 = 0;
+
+    /* "(tree fragment)":7
+ *     if _dict is not None:
+ *         state += (_dict,)
+ *         use_setstate = True             # <<<<<<<<<<<<<<
+ *     else:
+ *         use_setstate = False
+ */
+    __pyx_v_use_setstate = 1;
+
+    /* "(tree fragment)":5
+ *     state = ()
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+    goto __pyx_L3;
+  }
+
+  /* "(tree fragment)":9
+ *         use_setstate = True
+ *     else:
+ *         use_setstate = False             # <<<<<<<<<<<<<<
+ *     if use_setstate:
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, None), state
+ */
+  /*else*/ {
+    __pyx_v_use_setstate = 0;
+  }
+  __pyx_L3:;
+
+  /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = False
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, None), state
+ *     else:
+ */
+  __pyx_t_3 = (__pyx_v_use_setstate != 0);
+  if (__pyx_t_3) {
+
+    /* "(tree fragment)":11
+ *         use_setstate = False
+ *     if use_setstate:
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, None), state             # <<<<<<<<<<<<<<
+ *     else:
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, state)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_CodecContext); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_222419149);
+    __Pyx_GIVEREF(__pyx_int_222419149);
+    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_222419149);
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
+    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
+    __pyx_t_4 = 0;
+    __pyx_t_1 = 0;
+    __pyx_r = __pyx_t_5;
+    __pyx_t_5 = 0;
+    goto __pyx_L0;
+
+    /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = False
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, None), state
+ *     else:
+ */
+  }
+
+  /* "(tree fragment)":13
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, None), state
+ *     else:
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, state)             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_CodecContext__set_state(self, __pyx_state)
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_CodecContext); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_222419149);
+    __Pyx_GIVEREF(__pyx_int_222419149);
+    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_222419149);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state);
+    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
+    __pyx_t_5 = 0;
+    __pyx_t_1 = 0;
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = ()
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.CodecContext.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_state);
+  __Pyx_XDECREF(__pyx_v__dict);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_CodecContext__set_state(self, __pyx_state)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_4__setstate_cython__(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto_12CodecContext_4__setstate_cython__(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":15
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, state)
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_CodecContext__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
+ */
+  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error)
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_CodecContext, (type(self), 0xd41d8cd, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_CodecContext__set_state(self, __pyx_state)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.CodecContext.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/bytea.pyx":8
+ * 
+ * 
+ * cdef bytea_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         Py_buffer pybuf
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  Py_buffer __pyx_v_pybuf;
+  int __pyx_v_pybuf_used;
+  char *__pyx_v_buf;
+  Py_ssize_t __pyx_v_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  Py_ssize_t __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  char const *__pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  __Pyx_RefNannySetupContext("bytea_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":11
+ *     cdef:
+ *         Py_buffer pybuf
+ *         bint pybuf_used = False             # <<<<<<<<<<<<<<
+ *         char *buf
+ *         ssize_t len
+ */
+  __pyx_v_pybuf_used = 0;
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":15
+ *         ssize_t len
+ * 
+ *     if cpython.PyBytes_CheckExact(obj):             # <<<<<<<<<<<<<<
+ *         buf = cpython.PyBytes_AS_STRING(obj)
+ *         len = cpython.Py_SIZE(obj)
+ */
+  __pyx_t_1 = (PyBytes_CheckExact(__pyx_v_obj) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":16
+ * 
+ *     if cpython.PyBytes_CheckExact(obj):
+ *         buf = cpython.PyBytes_AS_STRING(obj)             # <<<<<<<<<<<<<<
+ *         len = cpython.Py_SIZE(obj)
+ *     else:
+ */
+    __pyx_v_buf = PyBytes_AS_STRING(__pyx_v_obj);
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":17
+ *     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)
+ */
+    __pyx_v_len = Py_SIZE(__pyx_v_obj);
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":15
+ *         ssize_t len
+ * 
+ *     if cpython.PyBytes_CheckExact(obj):             # <<<<<<<<<<<<<<
+ *         buf = cpython.PyBytes_AS_STRING(obj)
+ *         len = cpython.Py_SIZE(obj)
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":19
+ *         len = cpython.Py_SIZE(obj)
+ *     else:
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)             # <<<<<<<<<<<<<<
+ *         pybuf_used = True
+ *         buf = <char*>pybuf.buf
+ */
+  /*else*/ {
+    __pyx_t_2 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_pybuf), PyBUF_SIMPLE); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(7, 19, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":20
+ *     else:
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+ *         pybuf_used = True             # <<<<<<<<<<<<<<
+ *         buf = <char*>pybuf.buf
+ *         len = pybuf.len
+ */
+    __pyx_v_pybuf_used = 1;
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":21
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+ *         pybuf_used = True
+ *         buf = <char*>pybuf.buf             # <<<<<<<<<<<<<<
+ *         len = pybuf.len
+ * 
+ */
+    __pyx_v_buf = ((char *)__pyx_v_pybuf.buf);
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":22
+ *         pybuf_used = True
+ *         buf = <char*>pybuf.buf
+ *         len = pybuf.len             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+    __pyx_t_3 = __pyx_v_pybuf.len;
+    __pyx_v_len = __pyx_t_3;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":24
+ *         len = pybuf.len
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         wbuf.write_int32(<int32_t>len)
+ *         wbuf.write_cstr(buf, len)
+ */
+  /*try:*/ {
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":25
+ * 
+ *     try:
+ *         wbuf.write_int32(<int32_t>len)             # <<<<<<<<<<<<<<
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, ((int32_t)__pyx_v_len)); if (unlikely(!__pyx_t_4)) __PYX_ERR(7, 25, __pyx_L5_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/bytea.pyx":26
+ *     try:
+ *         wbuf.write_int32(<int32_t>len)
+ *         wbuf.write_cstr(buf, len)             # <<<<<<<<<<<<<<
+ *     finally:
+ *         if pybuf_used:
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_wbuf, __pyx_v_buf, __pyx_v_len); if (unlikely(!__pyx_t_4)) __PYX_ERR(7, 26, __pyx_L5_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  }
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":28
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ *         if pybuf_used:             # <<<<<<<<<<<<<<
+ *             cpython.PyBuffer_Release(&pybuf)
+ * 
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __pyx_t_1 = (__pyx_v_pybuf_used != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/pgproto/codecs/bytea.pyx":29
+ *     finally:
+ *         if pybuf_used:
+ *             cpython.PyBuffer_Release(&pybuf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+        PyBuffer_Release((&__pyx_v_pybuf));
+
+        /* "asyncpg/pgproto/codecs/bytea.pyx":28
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ *         if pybuf_used:             # <<<<<<<<<<<<<<
+ *             cpython.PyBuffer_Release(&pybuf)
+ * 
+ */
+      }
+      goto __pyx_L6;
+    }
+    __pyx_L5_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __Pyx_XGOTREF(__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_12);
+      __pyx_t_2 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename;
+      {
+        __pyx_t_1 = (__pyx_v_pybuf_used != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/pgproto/codecs/bytea.pyx":29
+ *     finally:
+ *         if pybuf_used:
+ *             cpython.PyBuffer_Release(&pybuf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+          PyBuffer_Release((&__pyx_v_pybuf));
+
+          /* "asyncpg/pgproto/codecs/bytea.pyx":28
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ *         if pybuf_used:             # <<<<<<<<<<<<<<
+ *             cpython.PyBuffer_Release(&pybuf)
+ * 
+ */
+        }
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_XGIVEREF(__pyx_t_11);
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+      }
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_XGIVEREF(__pyx_t_9);
+      __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+      __pyx_lineno = __pyx_t_2; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6;
+      goto __pyx_L1_error;
+    }
+    __pyx_L6:;
+  }
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":8
+ * 
+ * 
+ * cdef bytea_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         Py_buffer pybuf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.bytea_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/bytea.pyx":32
+ * 
+ * 
+ * cdef bytea_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef ssize_t buf_len = buf.len
+ *     return cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  Py_ssize_t __pyx_v_buf_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("bytea_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":33
+ * 
+ * cdef bytea_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef ssize_t buf_len = buf.len             # <<<<<<<<<<<<<<
+ *     return cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)
+ */
+  __pyx_t_1 = __pyx_v_buf->len;
+  __pyx_v_buf_len = __pyx_t_1;
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":34
+ * cdef bytea_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef ssize_t buf_len = buf.len
+ *     return cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = PyBytes_FromStringAndSize(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(__pyx_v_buf), __pyx_v_buf_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(7, 34, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/bytea.pyx":32
+ * 
+ * 
+ * cdef bytea_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef ssize_t buf_len = buf.len
+ *     return cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.bytea_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/text.pyx":8
+ * 
+ * 
+ * cdef inline as_pg_string_and_size(             # <<<<<<<<<<<<<<
+ *         CodecContext settings, obj, char **cstr, ssize_t *size):
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, PyObject *__pyx_v_obj, char **__pyx_v_cstr, Py_ssize_t *__pyx_v_size) {
+  PyObject *__pyx_v_encoded = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  char *__pyx_t_6;
+  int __pyx_t_7;
+  __Pyx_RefNannySetupContext("as_pg_string_and_size", 0);
+
+  /* "asyncpg/pgproto/codecs/text.pyx":11
+ *         CodecContext settings, obj, char **cstr, ssize_t *size):
+ * 
+ *     if not cpython.PyUnicode_Check(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError('expected str, got {}'.format(type(obj).__name__))
+ * 
+ */
+  __pyx_t_1 = ((!(PyUnicode_Check(__pyx_v_obj) != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/codecs/text.pyx":12
+ * 
+ *     if not cpython.PyUnicode_Check(obj):
+ *         raise TypeError('expected str, got {}'.format(type(obj).__name__))             # <<<<<<<<<<<<<<
+ * 
+ *     if settings.is_encoding_utf8():
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_expected_str_got, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_obj)), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(4, 12, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/text.pyx":11
+ *         CodecContext settings, obj, char **cstr, ssize_t *size):
+ * 
+ *     if not cpython.PyUnicode_Check(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError('expected str, got {}'.format(type(obj).__name__))
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/text.pyx":14
+ *         raise TypeError('expected str, got {}'.format(type(obj).__name__))
+ * 
+ *     if settings.is_encoding_utf8():             # <<<<<<<<<<<<<<
+ *         cstr[0] = cpythonx.PyUnicode_AsUTF8AndSize(obj, size)
+ *     else:
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings->__pyx_vtab)->is_encoding_utf8(__pyx_v_settings); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(4, 14, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/text.pyx":15
+ * 
+ *     if settings.is_encoding_utf8():
+ *         cstr[0] = cpythonx.PyUnicode_AsUTF8AndSize(obj, size)             # <<<<<<<<<<<<<<
+ *     else:
+ *         encoded = settings.get_text_codec().encode(obj)
+ */
+    __pyx_t_6 = PyUnicode_AsUTF8AndSize(__pyx_v_obj, __pyx_v_size); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(4, 15, __pyx_L1_error)
+    (__pyx_v_cstr[0]) = __pyx_t_6;
+
+    /* "asyncpg/pgproto/codecs/text.pyx":14
+ *         raise TypeError('expected str, got {}'.format(type(obj).__name__))
+ * 
+ *     if settings.is_encoding_utf8():             # <<<<<<<<<<<<<<
+ *         cstr[0] = cpythonx.PyUnicode_AsUTF8AndSize(obj, size)
+ *     else:
+ */
+    goto __pyx_L4;
+  }
+
+  /* "asyncpg/pgproto/codecs/text.pyx":17
+ *         cstr[0] = cpythonx.PyUnicode_AsUTF8AndSize(obj, size)
+ *     else:
+ *         encoded = settings.get_text_codec().encode(obj)             # <<<<<<<<<<<<<<
+ *         cpython.PyBytes_AsStringAndSize(encoded, cstr, size)
+ * 
+ */
+  /*else*/ {
+    __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings->__pyx_vtab)->get_text_codec(__pyx_v_settings, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 17, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 17, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_2)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_2);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_2, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_obj);
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 17, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_v_encoded = __pyx_t_3;
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/text.pyx":18
+ *     else:
+ *         encoded = settings.get_text_codec().encode(obj)
+ *         cpython.PyBytes_AsStringAndSize(encoded, cstr, size)             # <<<<<<<<<<<<<<
+ * 
+ *     if size[0] > 0x7fffffff:
+ */
+    __pyx_t_7 = PyBytes_AsStringAndSize(__pyx_v_encoded, __pyx_v_cstr, ((Py_ssize_t *)__pyx_v_size)); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(4, 18, __pyx_L1_error)
+  }
+  __pyx_L4:;
+
+  /* "asyncpg/pgproto/codecs/text.pyx":20
+ *         cpython.PyBytes_AsStringAndSize(encoded, cstr, size)
+ * 
+ *     if size[0] > 0x7fffffff:             # <<<<<<<<<<<<<<
+ *         raise ValueError('string too long')
+ * 
+ */
+  __pyx_t_1 = (((__pyx_v_size[0]) > 0x7fffffff) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/codecs/text.pyx":21
+ * 
+ *     if size[0] > 0x7fffffff:
+ *         raise ValueError('string too long')             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 21, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(4, 21, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/text.pyx":20
+ *         cpython.PyBytes_AsStringAndSize(encoded, cstr, size)
+ * 
+ *     if size[0] > 0x7fffffff:             # <<<<<<<<<<<<<<
+ *         raise ValueError('string too long')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/text.pyx":8
+ * 
+ * 
+ * cdef inline as_pg_string_and_size(             # <<<<<<<<<<<<<<
+ *         CodecContext settings, obj, char **cstr, ssize_t *size):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.as_pg_string_and_size", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_encoded);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/text.pyx":24
+ * 
+ * 
+ * cdef text_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         char *str
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  char *__pyx_v_str;
+  Py_ssize_t __pyx_v_size;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("text_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/text.pyx":29
+ *         ssize_t size
+ * 
+ *     as_pg_string_and_size(settings, obj, &str, &size)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(<int32_t>size)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(__pyx_v_settings, __pyx_v_obj, (&__pyx_v_str), (&__pyx_v_size)); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 29, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/text.pyx":31
+ *     as_pg_string_and_size(settings, obj, &str, &size)
+ * 
+ *     buf.write_int32(<int32_t>size)             # <<<<<<<<<<<<<<
+ *     buf.write_cstr(str, size)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, ((int32_t)__pyx_v_size)); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 31, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/text.pyx":32
+ * 
+ *     buf.write_int32(<int32_t>size)
+ *     buf.write_cstr(str, size)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_buf, __pyx_v_str, __pyx_v_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 32, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/text.pyx":24
+ * 
+ * 
+ * cdef text_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         char *str
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.text_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/text.pyx":35
+ * 
+ * 
+ * cdef inline decode_pg_string(CodecContext settings, const char* data,             # <<<<<<<<<<<<<<
+ *                              ssize_t len):
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_decode_pg_string(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, char const *__pyx_v_data, Py_ssize_t __pyx_v_len) {
+  PyObject *__pyx_v_bytes = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("decode_pg_string", 0);
+
+  /* "asyncpg/pgproto/codecs/text.pyx":38
+ *                              ssize_t len):
+ * 
+ *     if settings.is_encoding_utf8():             # <<<<<<<<<<<<<<
+ *         # decode UTF-8 in strict mode
+ *         return cpython.PyUnicode_DecodeUTF8(data, len, NULL)
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings->__pyx_vtab)->is_encoding_utf8(__pyx_v_settings); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(4, 38, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/text.pyx":40
+ *     if settings.is_encoding_utf8():
+ *         # decode UTF-8 in strict mode
+ *         return cpython.PyUnicode_DecodeUTF8(data, len, NULL)             # <<<<<<<<<<<<<<
+ *     else:
+ *         bytes = cpython.PyBytes_FromStringAndSize(data, len)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_1 = PyUnicode_DecodeUTF8(__pyx_v_data, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 40, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_r = __pyx_t_1;
+    __pyx_t_1 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/text.pyx":38
+ *                              ssize_t len):
+ * 
+ *     if settings.is_encoding_utf8():             # <<<<<<<<<<<<<<
+ *         # decode UTF-8 in strict mode
+ *         return cpython.PyUnicode_DecodeUTF8(data, len, NULL)
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/text.pyx":42
+ *         return cpython.PyUnicode_DecodeUTF8(data, len, NULL)
+ *     else:
+ *         bytes = cpython.PyBytes_FromStringAndSize(data, len)             # <<<<<<<<<<<<<<
+ *         return settings.get_text_codec().decode(bytes)
+ * 
+ */
+  /*else*/ {
+    __pyx_t_1 = PyBytes_FromStringAndSize(__pyx_v_data, __pyx_v_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 42, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_v_bytes = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/codecs/text.pyx":43
+ *     else:
+ *         bytes = cpython.PyBytes_FromStringAndSize(data, len)
+ *         return settings.get_text_codec().decode(bytes)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings->__pyx_vtab)->get_text_codec(__pyx_v_settings, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 43, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 43, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_bytes) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_bytes);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 43, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_1;
+    __pyx_t_1 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/text.pyx":35
+ * 
+ * 
+ * cdef inline decode_pg_string(CodecContext settings, const char* data,             # <<<<<<<<<<<<<<
+ *                              ssize_t len):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.decode_pg_string", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_bytes);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/text.pyx":46
+ * 
+ * 
+ * cdef text_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef ssize_t buf_len = buf.len
+ *     return decode_pg_string(settings, frb_read_all(buf), buf_len)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  Py_ssize_t __pyx_v_buf_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("text_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/text.pyx":47
+ * 
+ * cdef text_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef ssize_t buf_len = buf.len             # <<<<<<<<<<<<<<
+ *     return decode_pg_string(settings, frb_read_all(buf), buf_len)
+ */
+  __pyx_t_1 = __pyx_v_buf->len;
+  __pyx_v_buf_len = __pyx_t_1;
+
+  /* "asyncpg/pgproto/codecs/text.pyx":48
+ * cdef text_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef ssize_t buf_len = buf.len
+ *     return decode_pg_string(settings, frb_read_all(buf), buf_len)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_decode_pg_string(__pyx_v_settings, __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(__pyx_v_buf), __pyx_v_buf_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 48, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/text.pyx":46
+ * 
+ * 
+ * cdef text_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef ssize_t buf_len = buf.len
+ *     return decode_pg_string(settings, frb_read_all(buf), buf_len)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.text_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":62
+ * 
+ * 
+ * cdef inline _local_timezone():             # <<<<<<<<<<<<<<
+ *     d = datetime.datetime.now(datetime.timezone.utc).astimezone()
+ *     return datetime.timezone(d.utcoffset())
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__local_timezone(void) {
+  PyObject *__pyx_v_d = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_local_timezone", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":63
+ * 
+ * cdef inline _local_timezone():
+ *     d = datetime.datetime.now(datetime.timezone.utc).astimezone()             # <<<<<<<<<<<<<<
+ *     return datetime.timezone(d.utcoffset())
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_now); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_timezone); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_utc); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_astimezone); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_v_d = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":64
+ * cdef inline _local_timezone():
+ *     d = datetime.datetime.now(datetime.timezone.utc).astimezone()
+ *     return datetime.timezone(d.utcoffset())             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 64, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_timezone); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 64, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_d, __pyx_n_s_utcoffset); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 64, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 64, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 64, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":62
+ * 
+ * 
+ * cdef inline _local_timezone():             # <<<<<<<<<<<<<<
+ *     d = datetime.datetime.now(datetime.timezone.utc).astimezone()
+ *     return datetime.timezone(d.utcoffset())
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto._local_timezone", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_d);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":67
+ * 
+ * 
+ * cdef inline _encode_time(WriteBuffer buf, int64_t seconds,             # <<<<<<<<<<<<<<
+ *                          int32_t microseconds):
+ *     # XXX: add support for double timestamps
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, int64_t __pyx_v_seconds, int32_t __pyx_v_microseconds) {
+  int64_t __pyx_v_ts;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_encode_time", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":71
+ *     # XXX: add support for double timestamps
+ *     # int64 timestamps,
+ *     cdef int64_t ts = seconds * 1000000 + microseconds             # <<<<<<<<<<<<<<
+ * 
+ *     if ts == infinity_datetime_ts:
+ */
+  __pyx_v_ts = ((__pyx_v_seconds * 0xF4240) + __pyx_v_microseconds);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":73
+ *     cdef int64_t ts = seconds * 1000000 + microseconds
+ * 
+ *     if ts == infinity_datetime_ts:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_infinity)
+ *     elif ts == negative_infinity_datetime_ts:
+ */
+  __pyx_t_1 = ((__pyx_v_ts == __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_datetime_ts) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":74
+ * 
+ *     if ts == infinity_datetime_ts:
+ *         buf.write_int64(pg_time64_infinity)             # <<<<<<<<<<<<<<
+ *     elif ts == negative_infinity_datetime_ts:
+ *         buf.write_int64(pg_time64_negative_infinity)
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_infinity); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 74, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":73
+ *     cdef int64_t ts = seconds * 1000000 + microseconds
+ * 
+ *     if ts == infinity_datetime_ts:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_infinity)
+ *     elif ts == negative_infinity_datetime_ts:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":75
+ *     if ts == infinity_datetime_ts:
+ *         buf.write_int64(pg_time64_infinity)
+ *     elif ts == negative_infinity_datetime_ts:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_negative_infinity)
+ *     else:
+ */
+  __pyx_t_1 = ((__pyx_v_ts == __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_datetime_ts) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":76
+ *         buf.write_int64(pg_time64_infinity)
+ *     elif ts == negative_infinity_datetime_ts:
+ *         buf.write_int64(pg_time64_negative_infinity)             # <<<<<<<<<<<<<<
+ *     else:
+ *         buf.write_int64(ts)
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_negative_infinity); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 76, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":75
+ *     if ts == infinity_datetime_ts:
+ *         buf.write_int64(pg_time64_infinity)
+ *     elif ts == negative_infinity_datetime_ts:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_negative_infinity)
+ *     else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":78
+ *         buf.write_int64(pg_time64_negative_infinity)
+ *     else:
+ *         buf.write_int64(ts)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_ts); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 78, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":67
+ * 
+ * 
+ * cdef inline _encode_time(WriteBuffer buf, int64_t seconds,             # <<<<<<<<<<<<<<
+ *                          int32_t microseconds):
+ *     # XXX: add support for double timestamps
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto._encode_time", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":81
+ * 
+ * 
+ * cdef inline int32_t _decode_time(FRBuffer *buf, int64_t *seconds,             # <<<<<<<<<<<<<<
+ *                                  int32_t *microseconds):
+ *     cdef int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto__decode_time(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, int64_t *__pyx_v_seconds, int32_t *__pyx_v_microseconds) {
+  int64_t __pyx_v_ts;
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("_decode_time", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":83
+ * cdef inline int32_t _decode_time(FRBuffer *buf, int64_t *seconds,
+ *                                  int32_t *microseconds):
+ *     cdef int64_t ts = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     if ts == pg_time64_infinity:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 83, __pyx_L1_error)
+  __pyx_v_ts = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":85
+ *     cdef int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ * 
+ *     if ts == pg_time64_infinity:             # <<<<<<<<<<<<<<
+ *         return 1
+ *     elif ts == pg_time64_negative_infinity:
+ */
+  __pyx_t_2 = ((__pyx_v_ts == __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_infinity) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":86
+ * 
+ *     if ts == pg_time64_infinity:
+ *         return 1             # <<<<<<<<<<<<<<
+ *     elif ts == pg_time64_negative_infinity:
+ *         return -1
+ */
+    __pyx_r = 1;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":85
+ *     cdef int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ * 
+ *     if ts == pg_time64_infinity:             # <<<<<<<<<<<<<<
+ *         return 1
+ *     elif ts == pg_time64_negative_infinity:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":87
+ *     if ts == pg_time64_infinity:
+ *         return 1
+ *     elif ts == pg_time64_negative_infinity:             # <<<<<<<<<<<<<<
+ *         return -1
+ *     else:
+ */
+  __pyx_t_2 = ((__pyx_v_ts == __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_negative_infinity) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":88
+ *         return 1
+ *     elif ts == pg_time64_negative_infinity:
+ *         return -1             # <<<<<<<<<<<<<<
+ *     else:
+ *         seconds[0] = ts // 1000000
+ */
+    __pyx_r = -1;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":87
+ *     if ts == pg_time64_infinity:
+ *         return 1
+ *     elif ts == pg_time64_negative_infinity:             # <<<<<<<<<<<<<<
+ *         return -1
+ *     else:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":90
+ *         return -1
+ *     else:
+ *         seconds[0] = ts // 1000000             # <<<<<<<<<<<<<<
+ *         microseconds[0] = <int32_t>(ts % 1000000)
+ *         return 0
+ */
+  /*else*/ {
+    (__pyx_v_seconds[0]) = __Pyx_div_int64_t(__pyx_v_ts, 0xF4240);
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":91
+ *     else:
+ *         seconds[0] = ts // 1000000
+ *         microseconds[0] = <int32_t>(ts % 1000000)             # <<<<<<<<<<<<<<
+ *         return 0
+ * 
+ */
+    (__pyx_v_microseconds[0]) = ((int32_t)__Pyx_mod_int64_t(__pyx_v_ts, 0xF4240));
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":92
+ *         seconds[0] = ts // 1000000
+ *         microseconds[0] = <int32_t>(ts % 1000000)
+ *         return 0             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_r = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":81
+ * 
+ * 
+ * cdef inline int32_t _decode_time(FRBuffer *buf, int64_t *seconds,             # <<<<<<<<<<<<<<
+ *                                  int32_t *microseconds):
+ *     cdef int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_WriteUnraisable("asyncpg.pgproto.pgproto._decode_time", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":95
+ * 
+ * 
+ * cdef date_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t ordinal = <int32_t>cpython.PyLong_AsLong(obj.toordinal())
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int32_t __pyx_v_ordinal;
+  int32_t __pyx_v_pg_ordinal;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  long __pyx_t_4;
+  int __pyx_t_5;
+  __Pyx_RefNannySetupContext("date_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":97
+ * cdef date_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef:
+ *         int32_t ordinal = <int32_t>cpython.PyLong_AsLong(obj.toordinal())             # <<<<<<<<<<<<<<
+ *         int32_t pg_ordinal
+ * 
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_toordinal); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 97, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 97, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_4 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 97, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_ordinal = ((int32_t)__pyx_t_4);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":100
+ *         int32_t pg_ordinal
+ * 
+ *     if ordinal == infinity_date_ord:             # <<<<<<<<<<<<<<
+ *         pg_ordinal = pg_date_infinity
+ *     elif ordinal == negative_infinity_date_ord:
+ */
+  __pyx_t_5 = ((__pyx_v_ordinal == __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_date_ord) != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":101
+ * 
+ *     if ordinal == infinity_date_ord:
+ *         pg_ordinal = pg_date_infinity             # <<<<<<<<<<<<<<
+ *     elif ordinal == negative_infinity_date_ord:
+ *         pg_ordinal = pg_date_negative_infinity
+ */
+    __pyx_v_pg_ordinal = __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_infinity;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":100
+ *         int32_t pg_ordinal
+ * 
+ *     if ordinal == infinity_date_ord:             # <<<<<<<<<<<<<<
+ *         pg_ordinal = pg_date_infinity
+ *     elif ordinal == negative_infinity_date_ord:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":102
+ *     if ordinal == infinity_date_ord:
+ *         pg_ordinal = pg_date_infinity
+ *     elif ordinal == negative_infinity_date_ord:             # <<<<<<<<<<<<<<
+ *         pg_ordinal = pg_date_negative_infinity
+ *     else:
+ */
+  __pyx_t_5 = ((__pyx_v_ordinal == __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_date_ord) != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":103
+ *         pg_ordinal = pg_date_infinity
+ *     elif ordinal == negative_infinity_date_ord:
+ *         pg_ordinal = pg_date_negative_infinity             # <<<<<<<<<<<<<<
+ *     else:
+ *         pg_ordinal = ordinal - pg_date_offset_ord
+ */
+    __pyx_v_pg_ordinal = __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_negative_infinity;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":102
+ *     if ordinal == infinity_date_ord:
+ *         pg_ordinal = pg_date_infinity
+ *     elif ordinal == negative_infinity_date_ord:             # <<<<<<<<<<<<<<
+ *         pg_ordinal = pg_date_negative_infinity
+ *     else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":105
+ *         pg_ordinal = pg_date_negative_infinity
+ *     else:
+ *         pg_ordinal = ordinal - pg_date_offset_ord             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+  /*else*/ {
+    __pyx_v_pg_ordinal = (__pyx_v_ordinal - __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_offset_ord);
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":107
+ *         pg_ordinal = ordinal - pg_date_offset_ord
+ * 
+ *     buf.write_int32(4)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(pg_ordinal)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 4); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 107, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":108
+ * 
+ *     buf.write_int32(4)
+ *     buf.write_int32(pg_ordinal)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_pg_ordinal); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 108, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":95
+ * 
+ * 
+ * cdef date_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t ordinal = <int32_t>cpython.PyLong_AsLong(obj.toordinal())
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.date_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":111
+ * 
+ * 
+ * cdef date_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t pg_ordinal
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int32_t __pyx_v_pg_ordinal;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int32_t __pyx_t_7;
+  __Pyx_RefNannySetupContext("date_encode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":115
+ *         int32_t pg_ordinal
+ * 
+ *     if len(obj) != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'date tuple encoder: expecting 1 element '
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 115, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_1 != 1) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":118
+ *         raise ValueError(
+ *             'date tuple encoder: expecting 1 element '
+ *             'in tuple, got {}'.format(len(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     pg_ordinal = obj[0]
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_date_tuple_encoder_expecting_1_e, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 118, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 118, __pyx_L1_error)
+    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 118, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 118, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":116
+ * 
+ *     if len(obj) != 1:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'date tuple encoder: expecting 1 element '
+ *             'in tuple, got {}'.format(len(obj)))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 116, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(8, 116, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":115
+ *         int32_t pg_ordinal
+ * 
+ *     if len(obj) != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'date tuple encoder: expecting 1 element '
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":120
+ *             'in tuple, got {}'.format(len(obj)))
+ * 
+ *     pg_ordinal = obj[0]             # <<<<<<<<<<<<<<
+ *     buf.write_int32(4)
+ *     buf.write_int32(pg_ordinal)
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 120, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 120, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_pg_ordinal = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":121
+ * 
+ *     pg_ordinal = obj[0]
+ *     buf.write_int32(4)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(pg_ordinal)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 4); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 121, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":122
+ *     pg_ordinal = obj[0]
+ *     buf.write_int32(4)
+ *     buf.write_int32(pg_ordinal)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_pg_ordinal); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 122, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":111
+ * 
+ * 
+ * cdef date_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t pg_ordinal
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.date_encode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":125
+ * 
+ * 
+ * cdef date_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_pg_ordinal;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("date_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":126
+ * 
+ * cdef date_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *     if pg_ordinal == pg_date_infinity:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 126, __pyx_L1_error)
+  __pyx_v_pg_ordinal = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":128
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     if pg_ordinal == pg_date_infinity:             # <<<<<<<<<<<<<<
+ *         return infinity_date
+ *     elif pg_ordinal == pg_date_negative_infinity:
+ */
+  __pyx_t_2 = ((__pyx_v_pg_ordinal == __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_infinity) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":129
+ * 
+ *     if pg_ordinal == pg_date_infinity:
+ *         return infinity_date             # <<<<<<<<<<<<<<
+ *     elif pg_ordinal == pg_date_negative_infinity:
+ *         return negative_infinity_date
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_infinity_date); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 129, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":128
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     if pg_ordinal == pg_date_infinity:             # <<<<<<<<<<<<<<
+ *         return infinity_date
+ *     elif pg_ordinal == pg_date_negative_infinity:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":130
+ *     if pg_ordinal == pg_date_infinity:
+ *         return infinity_date
+ *     elif pg_ordinal == pg_date_negative_infinity:             # <<<<<<<<<<<<<<
+ *         return negative_infinity_date
+ *     else:
+ */
+  __pyx_t_2 = ((__pyx_v_pg_ordinal == __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_negative_infinity) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":131
+ *         return infinity_date
+ *     elif pg_ordinal == pg_date_negative_infinity:
+ *         return negative_infinity_date             # <<<<<<<<<<<<<<
+ *     else:
+ *         return date_from_ordinal(pg_ordinal + pg_date_offset_ord)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_negative_infinity_date); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 131, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":130
+ *     if pg_ordinal == pg_date_infinity:
+ *         return infinity_date
+ *     elif pg_ordinal == pg_date_negative_infinity:             # <<<<<<<<<<<<<<
+ *         return negative_infinity_date
+ *     else:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":133
+ *         return negative_infinity_date
+ *     else:
+ *         return date_from_ordinal(pg_ordinal + pg_date_offset_ord)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_date_from_ordinal); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 133, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyInt_From_int32_t((__pyx_v_pg_ordinal + __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_offset_ord)); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 133, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 133, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":125
+ * 
+ * 
+ * cdef date_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.date_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":136
+ * 
+ * 
+ * cdef date_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_pg_ordinal;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("date_decode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":137
+ * 
+ * cdef date_decode_tuple(CodecContext settings, FRBuffer *buf):
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *     return (pg_ordinal,)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 137, __pyx_L1_error)
+  __pyx_v_pg_ordinal = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":139
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     return (pg_ordinal,)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_pg_ordinal); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 139, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 139, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+  __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":136
+ * 
+ * 
+ * cdef date_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef int32_t pg_ordinal = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.date_decode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":142
+ * 
+ * 
+ * cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_delta = NULL;
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PY_LONG_LONG __pyx_t_10;
+  long __pyx_t_11;
+  __Pyx_RefNannySetupContext("timestamp_encode", 0);
+  __Pyx_INCREF(__pyx_v_obj);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":143
+ * 
+ * cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):             # <<<<<<<<<<<<<<
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)
+ */
+  __pyx_t_1 = ((!(PyDateTime_Check(__pyx_v_obj) != 0)) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":144
+ * cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):             # <<<<<<<<<<<<<<
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)
+ *         else:
+ */
+    __pyx_t_1 = (PyDate_Check(__pyx_v_obj) != 0);
+    if (likely(__pyx_t_1)) {
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":145
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise TypeError(
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 145, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 145, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_year); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 145, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_month); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 145, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_day); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 145, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_7 = NULL;
+      __pyx_t_8 = 0;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_7)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_7);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+          __pyx_t_8 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_4)) {
+        PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_t_3, __pyx_t_5, __pyx_t_6};
+        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 145, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+        PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_t_3, __pyx_t_5, __pyx_t_6};
+        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 145, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_9 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(8, 145, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        if (__pyx_t_7) {
+          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+        }
+        __Pyx_GIVEREF(__pyx_t_3);
+        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_5);
+        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_5);
+        __Pyx_GIVEREF(__pyx_t_6);
+        PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_t_6);
+        __pyx_t_3 = 0;
+        __pyx_t_5 = 0;
+        __pyx_t_6 = 0;
+        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 145, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_2);
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":144
+ * cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):             # <<<<<<<<<<<<<<
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)
+ *         else:
+ */
+      goto __pyx_L4;
+    }
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":147
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)
+ *         else:
+ *             raise TypeError(             # <<<<<<<<<<<<<<
+ *                 'expected a datetime.date or datetime.datetime instance, '
+ *                 'got {!r}'.format(type(obj).__name__)
+ */
+    /*else*/ {
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":149
+ *             raise TypeError(
+ *                 'expected a datetime.date or datetime.datetime instance, '
+ *                 'got {!r}'.format(type(obj).__name__)             # <<<<<<<<<<<<<<
+ *             )
+ * 
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_expected_a_datetime_date_or_date, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 149, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_obj)), __pyx_n_s_name); if (unlikely(!__pyx_t_9)) __PYX_ERR(8, 149, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_9);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 149, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":147
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)
+ *         else:
+ *             raise TypeError(             # <<<<<<<<<<<<<<
+ *                 'expected a datetime.date or datetime.datetime instance, '
+ *                 'got {!r}'.format(type(obj).__name__)
+ */
+      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 147, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __PYX_ERR(8, 147, __pyx_L1_error)
+    }
+    __pyx_L4:;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":143
+ * 
+ * cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):             # <<<<<<<<<<<<<<
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day)
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":152
+ *             )
+ * 
+ *     delta = obj - pg_epoch_datetime             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pg_epoch_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_2 = PyNumber_Subtract(__pyx_v_obj, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_delta = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":154
+ *     delta = obj - pg_epoch_datetime
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \             # <<<<<<<<<<<<<<
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_delta, __pyx_n_s_days); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 154, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_10 = PyLong_AsLongLong(__pyx_t_2); if (unlikely(__pyx_t_10 == ((PY_LONG_LONG)-1LL) && PyErr_Occurred())) __PYX_ERR(8, 154, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":155
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+ *                                 cpython.PyLong_AsLong(delta.seconds)             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ *                                     delta.microseconds)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_delta, __pyx_n_s_seconds); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 155, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_11 = PyLong_AsLong(__pyx_t_2); if (unlikely(__pyx_t_11 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 155, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":154
+ *     delta = obj - pg_epoch_datetime
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \             # <<<<<<<<<<<<<<
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ */
+  __pyx_v_seconds = ((__pyx_t_10 * 0x15180) + __pyx_t_11);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":157
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ *                                     delta.microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(8)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_delta, __pyx_n_s_microseconds); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 157, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":156
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(             # <<<<<<<<<<<<<<
+ *                                     delta.microseconds)
+ * 
+ */
+  __pyx_t_11 = PyLong_AsLong(__pyx_t_2); if (unlikely(__pyx_t_11 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 156, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_microseconds = ((int32_t)__pyx_t_11);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":159
+ *                                     delta.microseconds)
+ * 
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ *     _encode_time(buf, seconds, microseconds)
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 159, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":160
+ * 
+ *     buf.write_int32(8)
+ *     _encode_time(buf, seconds, microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(__pyx_v_buf, __pyx_v_seconds, __pyx_v_microseconds); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 160, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":142
+ * 
+ * 
+ * cdef timestamp_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamp_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_delta);
+  __Pyx_XDECREF(__pyx_v_obj);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":163
+ * 
+ * 
+ * cdef timestamp_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int64_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int64_t __pyx_t_7;
+  __Pyx_RefNannySetupContext("timestamp_encode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":167
+ *         int64_t microseconds
+ * 
+ *     if len(obj) != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'timestamp tuple encoder: expecting 1 element '
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 167, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_1 != 1) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":170
+ *         raise ValueError(
+ *             'timestamp tuple encoder: expecting 1 element '
+ *             'in tuple, got {}'.format(len(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     microseconds = obj[0]
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_timestamp_tuple_encoder_expectin, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 170, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 170, __pyx_L1_error)
+    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 170, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 170, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":168
+ * 
+ *     if len(obj) != 1:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'timestamp tuple encoder: expecting 1 element '
+ *             'in tuple, got {}'.format(len(obj)))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 168, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(8, 168, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":167
+ *         int64_t microseconds
+ * 
+ *     if len(obj) != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'timestamp tuple encoder: expecting 1 element '
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":172
+ *             'in tuple, got {}'.format(len(obj)))
+ * 
+ *     microseconds = obj[0]             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(8)
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 172, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 172, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_microseconds = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":174
+ *     microseconds = obj[0]
+ * 
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ *     buf.write_int64(microseconds)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 174, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":175
+ * 
+ *     buf.write_int32(8)
+ *     buf.write_int64(microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 175, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":163
+ * 
+ * 
+ * cdef timestamp_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamp_encode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":178
+ * 
+ * 
+ * cdef timestamp_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = 0
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  int32_t __pyx_v_inf;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  __Pyx_RefNannySetupContext("timestamp_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":180
+ * cdef timestamp_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int64_t seconds = 0             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = 0
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ */
+  __pyx_v_seconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":181
+ *     cdef:
+ *         int64_t seconds = 0
+ *         int32_t microseconds = 0             # <<<<<<<<<<<<<<
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ * 
+ */
+  __pyx_v_microseconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":182
+ *         int64_t seconds = 0
+ *         int32_t microseconds = 0
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     if inf > 0:
+ */
+  __pyx_v_inf = __pyx_f_7asyncpg_7pgproto_7pgproto__decode_time(__pyx_v_buf, (&__pyx_v_seconds), (&__pyx_v_microseconds));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":184
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ * 
+ *     if inf > 0:             # <<<<<<<<<<<<<<
+ *         # positive infinity
+ *         return infinity_datetime
+ */
+  __pyx_t_1 = ((__pyx_v_inf > 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":186
+ *     if inf > 0:
+ *         # positive infinity
+ *         return infinity_datetime             # <<<<<<<<<<<<<<
+ *     elif inf < 0:
+ *         # negative infinity
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_infinity_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 186, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_r = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":184
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ * 
+ *     if inf > 0:             # <<<<<<<<<<<<<<
+ *         # positive infinity
+ *         return infinity_datetime
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":187
+ *         # positive infinity
+ *         return infinity_datetime
+ *     elif inf < 0:             # <<<<<<<<<<<<<<
+ *         # negative infinity
+ *         return negative_infinity_datetime
+ */
+  __pyx_t_1 = ((__pyx_v_inf < 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":189
+ *     elif inf < 0:
+ *         # negative infinity
+ *         return negative_infinity_datetime             # <<<<<<<<<<<<<<
+ *     else:
+ *         return pg_epoch_datetime.__add__(
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_negative_infinity_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 189, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_r = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":187
+ *         # positive infinity
+ *         return infinity_datetime
+ *     elif inf < 0:             # <<<<<<<<<<<<<<
+ *         # negative infinity
+ *         return negative_infinity_datetime
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":191
+ *         return negative_infinity_datetime
+ *     else:
+ *         return pg_epoch_datetime.__add__(             # <<<<<<<<<<<<<<
+ *             timedelta(0, seconds, microseconds))
+ * 
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pg_epoch_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 191, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 191, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":192
+ *     else:
+ *         return pg_epoch_datetime.__add__(
+ *             timedelta(0, seconds, microseconds))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_timedelta); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 192, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyInt_From_int64_t(__pyx_v_seconds); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 192, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_microseconds); if (unlikely(!__pyx_t_7)) __PYX_ERR(8, 192, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = NULL;
+    __pyx_t_9 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+        __pyx_t_9 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_int_0, __pyx_t_6, __pyx_t_7};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 192, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_int_0, __pyx_t_6, __pyx_t_7};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 192, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_10 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(8, 192, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_10);
+      if (__pyx_t_8) {
+        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
+      }
+      __Pyx_INCREF(__pyx_int_0);
+      __Pyx_GIVEREF(__pyx_int_0);
+      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_int_0);
+      __Pyx_GIVEREF(__pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6);
+      __Pyx_GIVEREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_t_7);
+      __pyx_t_6 = 0;
+      __pyx_t_7 = 0;
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 192, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 191, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":178
+ * 
+ * 
+ * cdef timestamp_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = 0
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamp_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":195
+ * 
+ * 
+ * cdef timestamp_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int64_t __pyx_v_ts;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("timestamp_decode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":197
+ * cdef timestamp_decode_tuple(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return (ts,)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 197, __pyx_L1_error)
+  __pyx_v_ts = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":199
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ * 
+ *     return (ts,)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_ts); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 199, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 199, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+  __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":195
+ * 
+ * 
+ * cdef timestamp_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamp_decode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":202
+ * 
+ * 
+ * cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_utc_dt = NULL;
+  PyObject *__pyx_v_delta = NULL;
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PY_LONG_LONG __pyx_t_13;
+  long __pyx_t_14;
+  __Pyx_RefNannySetupContext("timestamptz_encode", 0);
+  __Pyx_INCREF(__pyx_v_obj);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":203
+ * 
+ * cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):             # <<<<<<<<<<<<<<
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,
+ */
+  __pyx_t_1 = ((!(PyDateTime_Check(__pyx_v_obj) != 0)) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":204
+ * cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):             # <<<<<<<<<<<<<<
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,
+ *                                     tzinfo=_local_timezone())
+ */
+    __pyx_t_1 = (PyDate_Check(__pyx_v_obj) != 0);
+    if (likely(__pyx_t_1)) {
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":205
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,             # <<<<<<<<<<<<<<
+ *                                     tzinfo=_local_timezone())
+ *         else:
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_year); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_month); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_day); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GIVEREF(__pyx_t_2);
+      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
+      __Pyx_GIVEREF(__pyx_t_4);
+      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
+      __Pyx_GIVEREF(__pyx_t_5);
+      PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_5);
+      __pyx_t_2 = 0;
+      __pyx_t_4 = 0;
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":206
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,
+ *                                     tzinfo=_local_timezone())             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise TypeError(
+ */
+      __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 206, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto__local_timezone(); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 206, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tzinfo, __pyx_t_4) < 0) __PYX_ERR(8, 206, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":205
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,             # <<<<<<<<<<<<<<
+ *                                     tzinfo=_local_timezone())
+ *         else:
+ */
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 205, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_4);
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":204
+ * cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):             # <<<<<<<<<<<<<<
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,
+ *                                     tzinfo=_local_timezone())
+ */
+      goto __pyx_L4;
+    }
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":208
+ *                                     tzinfo=_local_timezone())
+ *         else:
+ *             raise TypeError(             # <<<<<<<<<<<<<<
+ *                 'expected a datetime.date or datetime.datetime instance, '
+ *                 'got {!r}'.format(type(obj).__name__)
+ */
+    /*else*/ {
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":210
+ *             raise TypeError(
+ *                 'expected a datetime.date or datetime.datetime instance, '
+ *                 'got {!r}'.format(type(obj).__name__)             # <<<<<<<<<<<<<<
+ *             )
+ * 
+ */
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_expected_a_datetime_date_or_date, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 210, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_obj)), __pyx_n_s_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 210, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_3 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_3)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_3);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 210, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":208
+ *                                     tzinfo=_local_timezone())
+ *         else:
+ *             raise TypeError(             # <<<<<<<<<<<<<<
+ *                 'expected a datetime.date or datetime.datetime instance, '
+ *                 'got {!r}'.format(type(obj).__name__)
+ */
+      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 208, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __PYX_ERR(8, 208, __pyx_L1_error)
+    }
+    __pyx_L4:;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":203
+ * 
+ * cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.datetime.PyDateTime_Check(obj):             # <<<<<<<<<<<<<<
+ *         if cpython.datetime.PyDate_Check(obj):
+ *             obj = datetime.datetime(obj.year, obj.month, obj.day,
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":213
+ *             )
+ * 
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ * 
+ *     if obj == infinity_datetime:
+ */
+  __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 213, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":215
+ *     buf.write_int32(8)
+ * 
+ *     if obj == infinity_datetime:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_infinity)
+ *         return
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_infinity_datetime); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 215, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_4 = PyObject_RichCompare(__pyx_v_obj, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 215, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(8, 215, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":216
+ * 
+ *     if obj == infinity_datetime:
+ *         buf.write_int64(pg_time64_infinity)             # <<<<<<<<<<<<<<
+ *         return
+ *     elif obj == negative_infinity_datetime:
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_infinity); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 216, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":217
+ *     if obj == infinity_datetime:
+ *         buf.write_int64(pg_time64_infinity)
+ *         return             # <<<<<<<<<<<<<<
+ *     elif obj == negative_infinity_datetime:
+ *         buf.write_int64(pg_time64_negative_infinity)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":215
+ *     buf.write_int32(8)
+ * 
+ *     if obj == infinity_datetime:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_infinity)
+ *         return
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":218
+ *         buf.write_int64(pg_time64_infinity)
+ *         return
+ *     elif obj == negative_infinity_datetime:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_negative_infinity)
+ *         return
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_negative_infinity_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 218, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = PyObject_RichCompare(__pyx_v_obj, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 218, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(8, 218, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":219
+ *         return
+ *     elif obj == negative_infinity_datetime:
+ *         buf.write_int64(pg_time64_negative_infinity)             # <<<<<<<<<<<<<<
+ *         return
+ * 
+ */
+    __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_negative_infinity); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 219, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":220
+ *     elif obj == negative_infinity_datetime:
+ *         buf.write_int64(pg_time64_negative_infinity)
+ *         return             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":218
+ *         buf.write_int64(pg_time64_infinity)
+ *         return
+ *     elif obj == negative_infinity_datetime:             # <<<<<<<<<<<<<<
+ *         buf.write_int64(pg_time64_negative_infinity)
+ *         return
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":222
+ *         return
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         utc_dt = obj.astimezone(utc)
+ *     except ValueError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+    __Pyx_XGOTREF(__pyx_t_7);
+    __Pyx_XGOTREF(__pyx_t_8);
+    __Pyx_XGOTREF(__pyx_t_9);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":223
+ * 
+ *     try:
+ *         utc_dt = obj.astimezone(utc)             # <<<<<<<<<<<<<<
+ *     except ValueError:
+ *         # Python 3.5 doesn't like it when we call astimezone()
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_astimezone); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 223, __pyx_L6_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_utc); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 223, __pyx_L6_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_3 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_3)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_3);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 223, __pyx_L6_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_v_utc_dt = __pyx_t_5;
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":222
+ *         return
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         utc_dt = obj.astimezone(utc)
+ *     except ValueError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+    goto __pyx_L11_try_end;
+    __pyx_L6_error:;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":224
+ *     try:
+ *         utc_dt = obj.astimezone(utc)
+ *     except ValueError:             # <<<<<<<<<<<<<<
+ *         # Python 3.5 doesn't like it when we call astimezone()
+ *         # on naive datetime objects, so make it aware.
+ */
+    __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
+    if (__pyx_t_10) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamptz_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(8, 224, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_GOTREF(__pyx_t_6);
+
+      /* "asyncpg/pgproto/codecs/datetime.pyx":227
+ *         # Python 3.5 doesn't like it when we call astimezone()
+ *         # on naive datetime objects, so make it aware.
+ *         utc_dt = obj.replace(tzinfo=_local_timezone()).astimezone(utc)             # <<<<<<<<<<<<<<
+ * 
+ *     delta = utc_dt - pg_epoch_datetime_utc
+ */
+      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_replace); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __pyx_t_12 = __pyx_f_7asyncpg_7pgproto_7pgproto__local_timezone(); if (unlikely(!__pyx_t_12)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_12);
+      if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_tzinfo, __pyx_t_12) < 0) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_12);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_astimezone); if (unlikely(!__pyx_t_11)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_utc); if (unlikely(!__pyx_t_12)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_12);
+      __pyx_t_2 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_11);
+        if (likely(__pyx_t_2)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+          __Pyx_INCREF(__pyx_t_2);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_11, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_2, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_12);
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 227, __pyx_L8_except_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_utc_dt, __pyx_t_3);
+      __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L7_exception_handled;
+    }
+    goto __pyx_L8_except_error;
+    __pyx_L8_except_error:;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":222
+ *         return
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         utc_dt = obj.astimezone(utc)
+ *     except ValueError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+    goto __pyx_L1_error;
+    __pyx_L7_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+    __pyx_L11_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":229
+ *         utc_dt = obj.replace(tzinfo=_local_timezone()).astimezone(utc)
+ * 
+ *     delta = utc_dt - pg_epoch_datetime_utc             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pg_epoch_datetime_utc); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 229, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_4 = PyNumber_Subtract(__pyx_v_utc_dt, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 229, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  __pyx_v_delta = __pyx_t_4;
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":231
+ *     delta = utc_dt - pg_epoch_datetime_utc
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \             # <<<<<<<<<<<<<<
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_delta, __pyx_n_s_days); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 231, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_13 = PyLong_AsLongLong(__pyx_t_4); if (unlikely(__pyx_t_13 == ((PY_LONG_LONG)-1LL) && PyErr_Occurred())) __PYX_ERR(8, 231, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":232
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+ *                                 cpython.PyLong_AsLong(delta.seconds)             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ *                                     delta.microseconds)
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_delta, __pyx_n_s_seconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 232, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_14 = PyLong_AsLong(__pyx_t_4); if (unlikely(__pyx_t_14 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 232, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":231
+ *     delta = utc_dt - pg_epoch_datetime_utc
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \             # <<<<<<<<<<<<<<
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ */
+  __pyx_v_seconds = ((__pyx_t_13 * 0x15180) + __pyx_t_14);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":234
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(
+ *                                     delta.microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     _encode_time(buf, seconds, microseconds)
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_delta, __pyx_n_s_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 234, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":233
+ *         int64_t seconds = cpython.PyLong_AsLongLong(delta.days) * 86400 + \
+ *                                 cpython.PyLong_AsLong(delta.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(             # <<<<<<<<<<<<<<
+ *                                     delta.microseconds)
+ * 
+ */
+  __pyx_t_14 = PyLong_AsLong(__pyx_t_4); if (unlikely(__pyx_t_14 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 233, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_microseconds = ((int32_t)__pyx_t_14);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":236
+ *                                     delta.microseconds)
+ * 
+ *     _encode_time(buf, seconds, microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(__pyx_v_buf, __pyx_v_seconds, __pyx_v_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 236, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":202
+ * 
+ * 
+ * cdef timestamptz_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     if not cpython.datetime.PyDateTime_Check(obj):
+ *         if cpython.datetime.PyDate_Check(obj):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamptz_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_utc_dt);
+  __Pyx_XDECREF(__pyx_v_delta);
+  __Pyx_XDECREF(__pyx_v_obj);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":239
+ * 
+ * 
+ * cdef timestamptz_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = 0
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  int32_t __pyx_v_inf;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  __Pyx_RefNannySetupContext("timestamptz_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":241
+ * cdef timestamptz_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int64_t seconds = 0             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = 0
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ */
+  __pyx_v_seconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":242
+ *     cdef:
+ *         int64_t seconds = 0
+ *         int32_t microseconds = 0             # <<<<<<<<<<<<<<
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ * 
+ */
+  __pyx_v_microseconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":243
+ *         int64_t seconds = 0
+ *         int32_t microseconds = 0
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     if inf > 0:
+ */
+  __pyx_v_inf = __pyx_f_7asyncpg_7pgproto_7pgproto__decode_time(__pyx_v_buf, (&__pyx_v_seconds), (&__pyx_v_microseconds));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":245
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ * 
+ *     if inf > 0:             # <<<<<<<<<<<<<<
+ *         # positive infinity
+ *         return infinity_datetime
+ */
+  __pyx_t_1 = ((__pyx_v_inf > 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":247
+ *     if inf > 0:
+ *         # positive infinity
+ *         return infinity_datetime             # <<<<<<<<<<<<<<
+ *     elif inf < 0:
+ *         # negative infinity
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_infinity_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 247, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_r = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":245
+ *         int32_t inf = _decode_time(buf, &seconds, &microseconds)
+ * 
+ *     if inf > 0:             # <<<<<<<<<<<<<<
+ *         # positive infinity
+ *         return infinity_datetime
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":248
+ *         # positive infinity
+ *         return infinity_datetime
+ *     elif inf < 0:             # <<<<<<<<<<<<<<
+ *         # negative infinity
+ *         return negative_infinity_datetime
+ */
+  __pyx_t_1 = ((__pyx_v_inf < 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":250
+ *     elif inf < 0:
+ *         # negative infinity
+ *         return negative_infinity_datetime             # <<<<<<<<<<<<<<
+ *     else:
+ *         return pg_epoch_datetime_utc.__add__(
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_negative_infinity_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 250, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_r = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":248
+ *         # positive infinity
+ *         return infinity_datetime
+ *     elif inf < 0:             # <<<<<<<<<<<<<<
+ *         # negative infinity
+ *         return negative_infinity_datetime
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":252
+ *         return negative_infinity_datetime
+ *     else:
+ *         return pg_epoch_datetime_utc.__add__(             # <<<<<<<<<<<<<<
+ *             timedelta(0, seconds, microseconds))
+ * 
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pg_epoch_datetime_utc); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 252, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 252, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":253
+ *     else:
+ *         return pg_epoch_datetime_utc.__add__(
+ *             timedelta(0, seconds, microseconds))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_timedelta); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 253, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyInt_From_int64_t(__pyx_v_seconds); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 253, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_microseconds); if (unlikely(!__pyx_t_7)) __PYX_ERR(8, 253, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = NULL;
+    __pyx_t_9 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+        __pyx_t_9 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_int_0, __pyx_t_6, __pyx_t_7};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 253, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_int_0, __pyx_t_6, __pyx_t_7};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 253, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_10 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(8, 253, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_10);
+      if (__pyx_t_8) {
+        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
+      }
+      __Pyx_INCREF(__pyx_int_0);
+      __Pyx_GIVEREF(__pyx_int_0);
+      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_int_0);
+      __Pyx_GIVEREF(__pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6);
+      __Pyx_GIVEREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_t_7);
+      __pyx_t_6 = 0;
+      __pyx_t_7 = 0;
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 253, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 252, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":239
+ * 
+ * 
+ * cdef timestamptz_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = 0
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timestamptz_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":256
+ * 
+ * 
+ * cdef time_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  long __pyx_t_2;
+  long __pyx_t_3;
+  long __pyx_t_4;
+  __Pyx_RefNannySetupContext("time_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":258
+ * cdef time_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \             # <<<<<<<<<<<<<<
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \
+ *                             cpython.PyLong_AsLong(obj.second)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_hour); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 258, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_2 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 258, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":259
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \             # <<<<<<<<<<<<<<
+ *                             cpython.PyLong_AsLong(obj.second)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_minute); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 259, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 259, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":260
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \
+ *                             cpython.PyLong_AsLong(obj.second)             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_second); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 260, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 260, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":259
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \             # <<<<<<<<<<<<<<
+ *                             cpython.PyLong_AsLong(obj.second)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+ */
+  __pyx_v_seconds = (((__pyx_t_2 * 0xE10) + (__pyx_t_3 * 60)) + __pyx_t_4);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":261
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \
+ *                             cpython.PyLong_AsLong(obj.second)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(8)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_microsecond); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 261, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 261, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_microseconds = ((int32_t)__pyx_t_4);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":263
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+ * 
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ *     _encode_time(buf, seconds, microseconds)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 263, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":264
+ * 
+ *     buf.write_int32(8)
+ *     _encode_time(buf, seconds, microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(__pyx_v_buf, __pyx_v_seconds, __pyx_v_microseconds); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 264, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":256
+ * 
+ * 
+ * cdef time_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.time_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":267
+ * 
+ * 
+ * cdef time_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int64_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int64_t __pyx_t_7;
+  __Pyx_RefNannySetupContext("time_encode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":271
+ *         int64_t microseconds
+ * 
+ *     if len(obj) != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'time tuple encoder: expecting 1 element '
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 271, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_1 != 1) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":274
+ *         raise ValueError(
+ *             'time tuple encoder: expecting 1 element '
+ *             'in tuple, got {}'.format(len(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     microseconds = obj[0]
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_time_tuple_encoder_expecting_1_e, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 274, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 274, __pyx_L1_error)
+    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 274, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 274, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":272
+ * 
+ *     if len(obj) != 1:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'time tuple encoder: expecting 1 element '
+ *             'in tuple, got {}'.format(len(obj)))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 272, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(8, 272, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":271
+ *         int64_t microseconds
+ * 
+ *     if len(obj) != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'time tuple encoder: expecting 1 element '
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":276
+ *             'in tuple, got {}'.format(len(obj)))
+ * 
+ *     microseconds = obj[0]             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(8)
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 276, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 276, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_microseconds = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":278
+ *     microseconds = obj[0]
+ * 
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ *     buf.write_int64(microseconds)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 278, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":279
+ * 
+ *     buf.write_int32(8)
+ *     buf.write_int64(microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 279, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":267
+ * 
+ * 
+ * cdef time_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.time_encode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":282
+ * 
+ * 
+ * cdef time_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = 0
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  int64_t __pyx_v_minutes;
+  int64_t __pyx_v_sec;
+  int64_t __pyx_v_hours;
+  int64_t __pyx_v_min;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("time_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":284
+ * cdef time_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int64_t seconds = 0             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = 0
+ * 
+ */
+  __pyx_v_seconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":285
+ *     cdef:
+ *         int64_t seconds = 0
+ *         int32_t microseconds = 0             # <<<<<<<<<<<<<<
+ * 
+ *     _decode_time(buf, &seconds, &microseconds)
+ */
+  __pyx_v_microseconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":287
+ *         int32_t microseconds = 0
+ * 
+ *     _decode_time(buf, &seconds, &microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+  (void)(__pyx_f_7asyncpg_7pgproto_7pgproto__decode_time(__pyx_v_buf, (&__pyx_v_seconds), (&__pyx_v_microseconds)));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":290
+ * 
+ *     cdef:
+ *         int64_t minutes = <int64_t>(seconds / 60)             # <<<<<<<<<<<<<<
+ *         int64_t sec = seconds % 60
+ *         int64_t hours = <int64_t>(minutes / 60)
+ */
+  __pyx_v_minutes = ((int64_t)(((double)__pyx_v_seconds) / 60.0));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":291
+ *     cdef:
+ *         int64_t minutes = <int64_t>(seconds / 60)
+ *         int64_t sec = seconds % 60             # <<<<<<<<<<<<<<
+ *         int64_t hours = <int64_t>(minutes / 60)
+ *         int64_t min = minutes % 60
+ */
+  __pyx_v_sec = __Pyx_mod_int64_t(__pyx_v_seconds, 60);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":292
+ *         int64_t minutes = <int64_t>(seconds / 60)
+ *         int64_t sec = seconds % 60
+ *         int64_t hours = <int64_t>(minutes / 60)             # <<<<<<<<<<<<<<
+ *         int64_t min = minutes % 60
+ * 
+ */
+  __pyx_v_hours = ((int64_t)(((double)__pyx_v_minutes) / 60.0));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":293
+ *         int64_t sec = seconds % 60
+ *         int64_t hours = <int64_t>(minutes / 60)
+ *         int64_t min = minutes % 60             # <<<<<<<<<<<<<<
+ * 
+ *     return datetime.time(hours, min, sec, microseconds)
+ */
+  __pyx_v_min = __Pyx_mod_int64_t(__pyx_v_minutes, 60);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":295
+ *         int64_t min = minutes % 60
+ * 
+ *     return datetime.time(hours, min, sec, microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 295, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 295, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_hours); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 295, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyInt_From_int64_t(__pyx_v_min); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 295, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = __Pyx_PyInt_From_int64_t(__pyx_v_sec); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 295, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = __Pyx_PyInt_From_int32_t(__pyx_v_microseconds); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 295, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = NULL;
+  __pyx_t_8 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+      __pyx_t_8 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_3)) {
+    PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_t_2, __pyx_t_4, __pyx_t_5, __pyx_t_6};
+    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 295, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+    PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_t_2, __pyx_t_4, __pyx_t_5, __pyx_t_6};
+    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 295, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_9 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(8, 295, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    if (__pyx_t_7) {
+      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_2);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_8, __pyx_t_6);
+    __pyx_t_2 = 0;
+    __pyx_t_4 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_6 = 0;
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 295, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":282
+ * 
+ * 
+ * cdef time_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t seconds = 0
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.time_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":298
+ * 
+ * 
+ * cdef time_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int64_t __pyx_v_ts;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("time_decode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":300
+ * cdef time_decode_tuple(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return (ts,)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 300, __pyx_L1_error)
+  __pyx_v_ts = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":302
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ * 
+ *     return (ts,)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_ts); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 302, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 302, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
+  __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":298
+ * 
+ * 
+ * cdef time_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t ts = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.time_decode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":305
+ * 
+ * 
+ * cdef timetz_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     offset = obj.tzinfo.utcoffset(None)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_offset = NULL;
+  int32_t __pyx_v_offset_sec;
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  long __pyx_t_4;
+  long __pyx_t_5;
+  long __pyx_t_6;
+  __Pyx_RefNannySetupContext("timetz_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":306
+ * 
+ * cdef timetz_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     offset = obj.tzinfo.utcoffset(None)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_tzinfo); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 306, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_utcoffset); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 306, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, Py_None) : __Pyx_PyObject_CallOneArg(__pyx_t_3, Py_None);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 306, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_v_offset = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":310
+ *     cdef:
+ *         int32_t offset_sec = \
+ *             <int32_t>cpython.PyLong_AsLong(offset.days) * 24 * 60 * 60 + \             # <<<<<<<<<<<<<<
+ *             <int32_t>cpython.PyLong_AsLong(offset.seconds)
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_offset, __pyx_n_s_days); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 310, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 310, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":311
+ *         int32_t offset_sec = \
+ *             <int32_t>cpython.PyLong_AsLong(offset.days) * 24 * 60 * 60 + \
+ *             <int32_t>cpython.PyLong_AsLong(offset.seconds)             # <<<<<<<<<<<<<<
+ * 
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_offset, __pyx_n_s_seconds); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 311, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_5 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_5 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 311, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":310
+ *     cdef:
+ *         int32_t offset_sec = \
+ *             <int32_t>cpython.PyLong_AsLong(offset.days) * 24 * 60 * 60 + \             # <<<<<<<<<<<<<<
+ *             <int32_t>cpython.PyLong_AsLong(offset.seconds)
+ * 
+ */
+  __pyx_v_offset_sec = ((((((int32_t)__pyx_t_4) * 24) * 60) * 60) + ((int32_t)__pyx_t_5));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":313
+ *             <int32_t>cpython.PyLong_AsLong(offset.seconds)
+ * 
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \             # <<<<<<<<<<<<<<
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \
+ *                             cpython.PyLong_AsLong(obj.second)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_hour); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 313, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_5 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_5 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 313, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":314
+ * 
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \             # <<<<<<<<<<<<<<
+ *                             cpython.PyLong_AsLong(obj.second)
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_minute); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 314, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 314, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":315
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \
+ *                             cpython.PyLong_AsLong(obj.second)             # <<<<<<<<<<<<<<
+ * 
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_second); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 315, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_6 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_6 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 315, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":314
+ * 
+ *         int64_t seconds = cpython.PyLong_AsLong(obj.hour) * 3600 + \
+ *                             cpython.PyLong_AsLong(obj.minute) * 60 + \             # <<<<<<<<<<<<<<
+ *                             cpython.PyLong_AsLong(obj.second)
+ * 
+ */
+  __pyx_v_seconds = (((__pyx_t_5 * 0xE10) + (__pyx_t_4 * 60)) + __pyx_t_6);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":317
+ *                             cpython.PyLong_AsLong(obj.second)
+ * 
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(12)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_microsecond); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 317, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_6 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_6 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 317, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_microseconds = ((int32_t)__pyx_t_6);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":319
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microsecond)
+ * 
+ *     buf.write_int32(12)             # <<<<<<<<<<<<<<
+ *     _encode_time(buf, seconds, microseconds)
+ *     # In Python utcoffset() is the difference between the local time
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 12); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 319, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":320
+ * 
+ *     buf.write_int32(12)
+ *     _encode_time(buf, seconds, microseconds)             # <<<<<<<<<<<<<<
+ *     # In Python utcoffset() is the difference between the local time
+ *     # and the UTC, whereas in PostgreSQL it's the opposite,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(__pyx_v_buf, __pyx_v_seconds, __pyx_v_microseconds); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 320, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":324
+ *     # and the UTC, whereas in PostgreSQL it's the opposite,
+ *     # so we need to flip the sign.
+ *     buf.write_int32(-offset_sec)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, (-__pyx_v_offset_sec)); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 324, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":305
+ * 
+ * 
+ * cdef timetz_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     offset = obj.tzinfo.utcoffset(None)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timetz_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_offset);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":327
+ * 
+ * 
+ * cdef timetz_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int64_t __pyx_v_microseconds;
+  int32_t __pyx_v_offset_sec;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int64_t __pyx_t_7;
+  int32_t __pyx_t_8;
+  __Pyx_RefNannySetupContext("timetz_encode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":332
+ *         int32_t offset_sec
+ * 
+ *     if len(obj) != 2:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'time tuple encoder: expecting 2 elements2 '
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 332, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_1 != 2) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":335
+ *         raise ValueError(
+ *             'time tuple encoder: expecting 2 elements2 '
+ *             'in tuple, got {}'.format(len(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     microseconds = obj[0]
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_time_tuple_encoder_expecting_2_e, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 335, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 335, __pyx_L1_error)
+    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 335, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 335, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":333
+ * 
+ *     if len(obj) != 2:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'time tuple encoder: expecting 2 elements2 '
+ *             'in tuple, got {}'.format(len(obj)))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 333, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(8, 333, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":332
+ *         int32_t offset_sec
+ * 
+ *     if len(obj) != 2:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'time tuple encoder: expecting 2 elements2 '
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":337
+ *             'in tuple, got {}'.format(len(obj)))
+ * 
+ *     microseconds = obj[0]             # <<<<<<<<<<<<<<
+ *     offset_sec = obj[1]
+ * 
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 337, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 337, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_microseconds = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":338
+ * 
+ *     microseconds = obj[0]
+ *     offset_sec = obj[1]             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(12)
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 338, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_8 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_8 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 338, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_offset_sec = __pyx_t_8;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":340
+ *     offset_sec = obj[1]
+ * 
+ *     buf.write_int32(12)             # <<<<<<<<<<<<<<
+ *     buf.write_int64(microseconds)
+ *     buf.write_int32(offset_sec)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 12); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 340, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":341
+ * 
+ *     buf.write_int32(12)
+ *     buf.write_int64(microseconds)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(offset_sec)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 341, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":342
+ *     buf.write_int32(12)
+ *     buf.write_int64(microseconds)
+ *     buf.write_int32(offset_sec)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_offset_sec); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 342, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":327
+ * 
+ * 
+ * cdef timetz_encode_tuple(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timetz_encode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":345
+ * 
+ * 
+ * cdef timetz_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     time = time_decode(settings, buf)
+ *     cdef int32_t offset = <int32_t>(hton.unpack_int32(frb_read(buf, 4)) / 60)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_v_time = NULL;
+  int32_t __pyx_v_offset;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  char const *__pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("timetz_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":346
+ * 
+ * cdef timetz_decode(CodecContext settings, FRBuffer *buf):
+ *     time = time_decode(settings, buf)             # <<<<<<<<<<<<<<
+ *     cdef int32_t offset = <int32_t>(hton.unpack_int32(frb_read(buf, 4)) / 60)
+ *     # See the comment in the `timetz_encode` method.
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_time_decode(__pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 346, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_time = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":347
+ * cdef timetz_decode(CodecContext settings, FRBuffer *buf):
+ *     time = time_decode(settings, buf)
+ *     cdef int32_t offset = <int32_t>(hton.unpack_int32(frb_read(buf, 4)) / 60)             # <<<<<<<<<<<<<<
+ *     # See the comment in the `timetz_encode` method.
+ *     return time.replace(tzinfo=datetime.timezone(timedelta(minutes=-offset)))
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(8, 347, __pyx_L1_error)
+  __pyx_v_offset = ((int32_t)(((double)unpack_int32(__pyx_t_2)) / 60.0));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":349
+ *     cdef int32_t offset = <int32_t>(hton.unpack_int32(frb_read(buf, 4)) / 60)
+ *     # See the comment in the `timetz_encode` method.
+ *     return time.replace(tzinfo=datetime.timezone(timedelta(minutes=-offset)))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_time, __pyx_n_s_replace); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_datetime); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_timezone); if (unlikely(!__pyx_t_6)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_timedelta); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __pyx_t_8 = __Pyx_PyInt_From_int32_t((-__pyx_v_offset)); if (unlikely(!__pyx_t_8)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_minutes, __pyx_t_8) < 0) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __pyx_t_7 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_6, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_tzinfo, __pyx_t_4) < 0) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 349, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_4;
+  __pyx_t_4 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":345
+ * 
+ * 
+ * cdef timetz_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     time = time_decode(settings, buf)
+ *     cdef int32_t offset = <int32_t>(hton.unpack_int32(frb_read(buf, 4)) / 60)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timetz_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_time);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":352
+ * 
+ * 
+ * cdef timetz_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int64_t __pyx_v_microseconds;
+  int32_t __pyx_v_offset_sec;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("timetz_decode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":354
+ * cdef timetz_decode_tuple(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int64_t microseconds = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         int32_t offset_sec = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 354, __pyx_L1_error)
+  __pyx_v_microseconds = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":355
+ *     cdef:
+ *         int64_t microseconds = hton.unpack_int64(frb_read(buf, 8))
+ *         int32_t offset_sec = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *     return (microseconds, offset_sec)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 355, __pyx_L1_error)
+  __pyx_v_offset_sec = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":357
+ *         int32_t offset_sec = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     return (microseconds, offset_sec)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_microseconds); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 357, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_offset_sec); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 357, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 357, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
+  __pyx_t_2 = 0;
+  __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_4;
+  __pyx_t_4 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":352
+ * 
+ * 
+ * cdef timetz_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t microseconds = hton.unpack_int64(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.timetz_decode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":360
+ * 
+ * 
+ * cdef interval_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t days = <int32_t>cpython.PyLong_AsLong(obj.days)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int32_t __pyx_v_days;
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  long __pyx_t_2;
+  PY_LONG_LONG __pyx_t_3;
+  __Pyx_RefNannySetupContext("interval_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":362
+ * cdef interval_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef:
+ *         int32_t days = <int32_t>cpython.PyLong_AsLong(obj.days)             # <<<<<<<<<<<<<<
+ *         int64_t seconds = cpython.PyLong_AsLongLong(obj.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microseconds)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_days); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 362, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_2 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 362, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_days = ((int32_t)__pyx_t_2);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":363
+ *     cdef:
+ *         int32_t days = <int32_t>cpython.PyLong_AsLong(obj.days)
+ *         int64_t seconds = cpython.PyLong_AsLongLong(obj.seconds)             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microseconds)
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_seconds); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 363, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = PyLong_AsLongLong(__pyx_t_1); if (unlikely(__pyx_t_3 == ((PY_LONG_LONG)-1LL) && PyErr_Occurred())) __PYX_ERR(8, 363, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_seconds = __pyx_t_3;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":364
+ *         int32_t days = <int32_t>cpython.PyLong_AsLong(obj.days)
+ *         int64_t seconds = cpython.PyLong_AsLongLong(obj.seconds)
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(16)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_microseconds); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 364, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_2 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 364, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_microseconds = ((int32_t)__pyx_t_2);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":366
+ *         int32_t microseconds = <int32_t>cpython.PyLong_AsLong(obj.microseconds)
+ * 
+ *     buf.write_int32(16)             # <<<<<<<<<<<<<<
+ *     _encode_time(buf, seconds, microseconds)
+ *     buf.write_int32(days)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 16); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 366, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":367
+ * 
+ *     buf.write_int32(16)
+ *     _encode_time(buf, seconds, microseconds)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(days)
+ *     buf.write_int32(0) # Months
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_time(__pyx_v_buf, __pyx_v_seconds, __pyx_v_microseconds); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 367, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":368
+ *     buf.write_int32(16)
+ *     _encode_time(buf, seconds, microseconds)
+ *     buf.write_int32(days)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(0) # Months
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_days); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 368, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":369
+ *     _encode_time(buf, seconds, microseconds)
+ *     buf.write_int32(days)
+ *     buf.write_int32(0) # Months             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 369, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":360
+ * 
+ * 
+ * cdef interval_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t days = <int32_t>cpython.PyLong_AsLong(obj.days)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.interval_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":372
+ * 
+ * 
+ * cdef interval_encode_tuple(CodecContext settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                            tuple obj):
+ *     cdef:
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int32_t __pyx_v_months;
+  int32_t __pyx_v_days;
+  int64_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int32_t __pyx_t_7;
+  int64_t __pyx_t_8;
+  __Pyx_RefNannySetupContext("interval_encode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":379
+ *         int64_t microseconds
+ * 
+ *     if len(obj) != 3:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'interval tuple encoder: expecting 3 elements '
+ */
+  if (unlikely(__pyx_v_obj == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(8, 379, __pyx_L1_error)
+  }
+  __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 379, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_1 != 3) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":382
+ *         raise ValueError(
+ *             'interval tuple encoder: expecting 3 elements '
+ *             'in tuple, got {}'.format(len(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     months = obj[0]
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_interval_tuple_encoder_expecting, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 382, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    if (unlikely(__pyx_v_obj == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+      __PYX_ERR(8, 382, __pyx_L1_error)
+    }
+    __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(8, 382, __pyx_L1_error)
+    __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 382, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 382, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":380
+ * 
+ *     if len(obj) != 3:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'interval tuple encoder: expecting 3 elements '
+ *             'in tuple, got {}'.format(len(obj)))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 380, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(8, 380, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":379
+ *         int64_t microseconds
+ * 
+ *     if len(obj) != 3:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'interval tuple encoder: expecting 3 elements '
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":384
+ *             'in tuple, got {}'.format(len(obj)))
+ * 
+ *     months = obj[0]             # <<<<<<<<<<<<<<
+ *     days = obj[1]
+ *     microseconds = obj[2]
+ */
+  if (unlikely(__pyx_v_obj == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(8, 384, __pyx_L1_error)
+  }
+  __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 384, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 384, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_months = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":385
+ * 
+ *     months = obj[0]
+ *     days = obj[1]             # <<<<<<<<<<<<<<
+ *     microseconds = obj[2]
+ * 
+ */
+  if (unlikely(__pyx_v_obj == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(8, 385, __pyx_L1_error)
+  }
+  __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 385, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 385, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_days = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":386
+ *     months = obj[0]
+ *     days = obj[1]
+ *     microseconds = obj[2]             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(16)
+ */
+  if (unlikely(__pyx_v_obj == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(8, 386, __pyx_L1_error)
+  }
+  __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_obj, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 386, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_8 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_8 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 386, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_microseconds = __pyx_t_8;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":388
+ *     microseconds = obj[2]
+ * 
+ *     buf.write_int32(16)             # <<<<<<<<<<<<<<
+ *     buf.write_int64(microseconds)
+ *     buf.write_int32(days)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 16); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 388, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":389
+ * 
+ *     buf.write_int32(16)
+ *     buf.write_int64(microseconds)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(days)
+ *     buf.write_int32(months)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_v_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 389, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":390
+ *     buf.write_int32(16)
+ *     buf.write_int64(microseconds)
+ *     buf.write_int32(days)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(months)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_days); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 390, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":391
+ *     buf.write_int64(microseconds)
+ *     buf.write_int32(days)
+ *     buf.write_int32(months)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_v_months); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 391, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":372
+ * 
+ * 
+ * cdef interval_encode_tuple(CodecContext settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                            tuple obj):
+ *     cdef:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.interval_encode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":394
+ * 
+ * 
+ * cdef interval_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t days
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_days;
+  int32_t __pyx_v_months;
+  int32_t __pyx_v_years;
+  int64_t __pyx_v_seconds;
+  int32_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("interval_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":399
+ *         int32_t months
+ *         int32_t years
+ *         int64_t seconds = 0             # <<<<<<<<<<<<<<
+ *         int32_t microseconds = 0
+ * 
+ */
+  __pyx_v_seconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":400
+ *         int32_t years
+ *         int64_t seconds = 0
+ *         int32_t microseconds = 0             # <<<<<<<<<<<<<<
+ * 
+ *     _decode_time(buf, &seconds, &microseconds)
+ */
+  __pyx_v_microseconds = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":402
+ *         int32_t microseconds = 0
+ * 
+ *     _decode_time(buf, &seconds, &microseconds)             # <<<<<<<<<<<<<<
+ * 
+ *     days = hton.unpack_int32(frb_read(buf, 4))
+ */
+  (void)(__pyx_f_7asyncpg_7pgproto_7pgproto__decode_time(__pyx_v_buf, (&__pyx_v_seconds), (&__pyx_v_microseconds)));
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":404
+ *     _decode_time(buf, &seconds, &microseconds)
+ * 
+ *     days = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     months = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 404, __pyx_L1_error)
+  __pyx_v_days = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":405
+ * 
+ *     days = hton.unpack_int32(frb_read(buf, 4))
+ *     months = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *     if months < 0:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 405, __pyx_L1_error)
+  __pyx_v_months = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":407
+ *     months = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     if months < 0:             # <<<<<<<<<<<<<<
+ *         years = -<int32_t>(-months // 12)
+ *         months = -<int32_t>(-months % 12)
+ */
+  __pyx_t_2 = ((__pyx_v_months < 0) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":408
+ * 
+ *     if months < 0:
+ *         years = -<int32_t>(-months // 12)             # <<<<<<<<<<<<<<
+ *         months = -<int32_t>(-months % 12)
+ *     else:
+ */
+    __pyx_v_years = (-((int32_t)__Pyx_div_long((-__pyx_v_months), 12)));
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":409
+ *     if months < 0:
+ *         years = -<int32_t>(-months // 12)
+ *         months = -<int32_t>(-months % 12)             # <<<<<<<<<<<<<<
+ *     else:
+ *         years = <int32_t>(months // 12)
+ */
+    __pyx_v_months = (-((int32_t)__Pyx_mod_long((-__pyx_v_months), 12)));
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":407
+ *     months = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     if months < 0:             # <<<<<<<<<<<<<<
+ *         years = -<int32_t>(-months // 12)
+ *         months = -<int32_t>(-months % 12)
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":411
+ *         months = -<int32_t>(-months % 12)
+ *     else:
+ *         years = <int32_t>(months // 12)             # <<<<<<<<<<<<<<
+ *         months = <int32_t>(months % 12)
+ * 
+ */
+  /*else*/ {
+    __pyx_v_years = ((int32_t)__Pyx_div_long(__pyx_v_months, 12));
+
+    /* "asyncpg/pgproto/codecs/datetime.pyx":412
+ *     else:
+ *         years = <int32_t>(months // 12)
+ *         months = <int32_t>(months % 12)             # <<<<<<<<<<<<<<
+ * 
+ *     return datetime.timedelta(days=days + months * 30 + years * 365,
+ */
+    __pyx_v_months = ((int32_t)__Pyx_mod_long(__pyx_v_months, 12));
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":414
+ *         months = <int32_t>(months % 12)
+ * 
+ *     return datetime.timedelta(days=days + months * 30 + years * 365,             # <<<<<<<<<<<<<<
+ *                               seconds=seconds, microseconds=microseconds)
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_timedelta); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = __Pyx_PyInt_From_long(((__pyx_v_days + (__pyx_v_months * 30)) + (__pyx_v_years * 0x16D))); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_days, __pyx_t_5) < 0) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":415
+ * 
+ *     return datetime.timedelta(days=days + months * 30 + years * 365,
+ *                               seconds=seconds, microseconds=microseconds)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyInt_From_int64_t(__pyx_v_seconds); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 415, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_seconds, __pyx_t_5) < 0) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_microseconds); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 415, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_microseconds, __pyx_t_5) < 0) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":414
+ *         months = <int32_t>(months % 12)
+ * 
+ *     return datetime.timedelta(days=days + months * 30 + years * 365,             # <<<<<<<<<<<<<<
+ *                               seconds=seconds, microseconds=microseconds)
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 414, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_5;
+  __pyx_t_5 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":394
+ * 
+ * 
+ * cdef interval_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t days
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.interval_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/datetime.pyx":418
+ * 
+ * 
+ * cdef interval_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t days
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode_tuple(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_days;
+  int32_t __pyx_v_months;
+  int64_t __pyx_v_microseconds;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("interval_decode_tuple", 0);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":424
+ *         int64_t microseconds
+ * 
+ *     microseconds = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *     days = hton.unpack_int32(frb_read(buf, 4))
+ *     months = hton.unpack_int32(frb_read(buf, 4))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 424, __pyx_L1_error)
+  __pyx_v_microseconds = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":425
+ * 
+ *     microseconds = hton.unpack_int64(frb_read(buf, 8))
+ *     days = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     months = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 425, __pyx_L1_error)
+  __pyx_v_days = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":426
+ *     microseconds = hton.unpack_int64(frb_read(buf, 8))
+ *     days = hton.unpack_int32(frb_read(buf, 4))
+ *     months = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *     return (months, days, microseconds)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(8, 426, __pyx_L1_error)
+  __pyx_v_months = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":428
+ *     months = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *     return (months, days, microseconds)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_months); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 428, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_days); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 428, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyInt_From_int64_t(__pyx_v_microseconds); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 428, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(8, 428, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_4);
+  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
+  __pyx_t_2 = 0;
+  __pyx_t_3 = 0;
+  __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_5;
+  __pyx_t_5 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":418
+ * 
+ * 
+ * cdef interval_decode_tuple(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t days
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.interval_decode_tuple", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/float.pyx":11
+ * 
+ * 
+ * cdef float4_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     cdef float fval = <float>dval
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_float4_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  double __pyx_v_dval;
+  float __pyx_v_fval;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  double __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("float4_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":12
+ * 
+ * cdef float4_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)             # <<<<<<<<<<<<<<
+ *     cdef float fval = <float>dval
+ *     if math.isinf(fval) and not math.isinf(dval):
+ */
+  __pyx_t_1 = PyFloat_AsDouble(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((double)-1.0) && PyErr_Occurred())) __PYX_ERR(9, 12, __pyx_L1_error)
+  __pyx_v_dval = __pyx_t_1;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":13
+ * cdef float4_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     cdef float fval = <float>dval             # <<<<<<<<<<<<<<
+ *     if math.isinf(fval) and not math.isinf(dval):
+ *         raise ValueError('value out of float32 range')
+ */
+  __pyx_v_fval = ((float)__pyx_v_dval);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":14
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     cdef float fval = <float>dval
+ *     if math.isinf(fval) and not math.isinf(dval):             # <<<<<<<<<<<<<<
+ *         raise ValueError('value out of float32 range')
+ * 
+ */
+  __pyx_t_3 = (isinf(__pyx_v_fval) != 0);
+  if (__pyx_t_3) {
+  } else {
+    __pyx_t_2 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_3 = ((!(isinf(__pyx_v_dval) != 0)) != 0);
+  __pyx_t_2 = __pyx_t_3;
+  __pyx_L4_bool_binop_done:;
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/float.pyx":15
+ *     cdef float fval = <float>dval
+ *     if math.isinf(fval) and not math.isinf(dval):
+ *         raise ValueError('value out of float32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(9, 15, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(9, 15, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/float.pyx":14
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     cdef float fval = <float>dval
+ *     if math.isinf(fval) and not math.isinf(dval):             # <<<<<<<<<<<<<<
+ *         raise ValueError('value out of float32 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/float.pyx":17
+ *         raise ValueError('value out of float32 range')
+ * 
+ *     buf.write_int32(4)             # <<<<<<<<<<<<<<
+ *     buf.write_float(fval)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 4); if (unlikely(!__pyx_t_4)) __PYX_ERR(9, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":18
+ * 
+ *     buf.write_int32(4)
+ *     buf.write_float(fval)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_float(__pyx_v_buf, __pyx_v_fval); if (unlikely(!__pyx_t_4)) __PYX_ERR(9, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":11
+ * 
+ * 
+ * cdef float4_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     cdef float fval = <float>dval
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.float4_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/float.pyx":21
+ * 
+ * 
+ * cdef float4_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef float f = hton.unpack_float(frb_read(buf, 4))
+ *     return cpython.PyFloat_FromDouble(f)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_float4_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  float __pyx_v_f;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("float4_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":22
+ * 
+ * cdef float4_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef float f = hton.unpack_float(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     return cpython.PyFloat_FromDouble(f)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(9, 22, __pyx_L1_error)
+  __pyx_v_f = unpack_float(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":23
+ * cdef float4_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef float f = hton.unpack_float(frb_read(buf, 4))
+ *     return cpython.PyFloat_FromDouble(f)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = PyFloat_FromDouble(__pyx_v_f); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 23, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":21
+ * 
+ * 
+ * cdef float4_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef float f = hton.unpack_float(frb_read(buf, 4))
+ *     return cpython.PyFloat_FromDouble(f)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.float4_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/float.pyx":26
+ * 
+ * 
+ * cdef float8_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     buf.write_int32(8)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_float8_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  double __pyx_v_dval;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  double __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("float8_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":27
+ * 
+ * cdef float8_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(8)
+ *     buf.write_double(dval)
+ */
+  __pyx_t_1 = PyFloat_AsDouble(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((double)-1.0) && PyErr_Occurred())) __PYX_ERR(9, 27, __pyx_L1_error)
+  __pyx_v_dval = __pyx_t_1;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":28
+ * cdef float8_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ *     buf.write_double(dval)
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":29
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     buf.write_int32(8)
+ *     buf.write_double(dval)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_buf, __pyx_v_dval); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 29, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":26
+ * 
+ * 
+ * cdef float8_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef double dval = cpython.PyFloat_AsDouble(obj)
+ *     buf.write_int32(8)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.float8_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/float.pyx":32
+ * 
+ * 
+ * cdef float8_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef double f = hton.unpack_double(frb_read(buf, 8))
+ *     return cpython.PyFloat_FromDouble(f)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_float8_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  double __pyx_v_f;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("float8_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":33
+ * 
+ * cdef float8_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef double f = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *     return cpython.PyFloat_FromDouble(f)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(9, 33, __pyx_L1_error)
+  __pyx_v_f = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":34
+ * cdef float8_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef double f = hton.unpack_double(frb_read(buf, 8))
+ *     return cpython.PyFloat_FromDouble(f)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = PyFloat_FromDouble(__pyx_v_f); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 34, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/float.pyx":32
+ * 
+ * 
+ * cdef float8_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef double f = hton.unpack_double(frb_read(buf, 8))
+ *     return cpython.PyFloat_FromDouble(f)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.float8_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":8
+ * 
+ * 
+ * cdef bool_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     if not cpython.PyBool_Check(obj):
+ *         raise TypeError('a boolean is required (got type {})'.format(
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bool_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  char __pyx_t_6;
+  __Pyx_RefNannySetupContext("bool_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":9
+ * 
+ * cdef bool_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.PyBool_Check(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError('a boolean is required (got type {})'.format(
+ *             type(obj).__name__))
+ */
+  __pyx_t_1 = ((!(PyBool_Check(__pyx_v_obj) != 0)) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/pgproto/codecs/int.pyx":10
+ * cdef bool_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.PyBool_Check(obj):
+ *         raise TypeError('a boolean is required (got type {})'.format(             # <<<<<<<<<<<<<<
+ *             type(obj).__name__))
+ * 
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_a_boolean_is_required_got_type, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 10, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/pgproto/codecs/int.pyx":11
+ *     if not cpython.PyBool_Check(obj):
+ *         raise TypeError('a boolean is required (got type {})'.format(
+ *             type(obj).__name__))             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(1)
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_obj)), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 10, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":10
+ * cdef bool_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.PyBool_Check(obj):
+ *         raise TypeError('a boolean is required (got type {})'.format(             # <<<<<<<<<<<<<<
+ *             type(obj).__name__))
+ * 
+ */
+    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 10, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(5, 10, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/int.pyx":9
+ * 
+ * cdef bool_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     if not cpython.PyBool_Check(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError('a boolean is required (got type {})'.format(
+ *             type(obj).__name__))
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":13
+ *             type(obj).__name__))
+ * 
+ *     buf.write_int32(1)             # <<<<<<<<<<<<<<
+ *     buf.write_byte(b'\x01' if obj is True else b'\x00')
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":14
+ * 
+ *     buf.write_int32(1)
+ *     buf.write_byte(b'\x01' if obj is True else b'\x00')             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_obj == Py_True);
+  if ((__pyx_t_1 != 0)) {
+    __pyx_t_6 = '\x01';
+  } else {
+    __pyx_t_6 = '\x00';
+  }
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":8
+ * 
+ * 
+ * cdef bool_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     if not cpython.PyBool_Check(obj):
+ *         raise TypeError('a boolean is required (got type {})'.format(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.bool_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":17
+ * 
+ * 
+ * cdef bool_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return frb_read(buf, 1)[0] is b'\x01'
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bool_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("bool_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":18
+ * 
+ * cdef bool_decode(CodecContext settings, FRBuffer *buf):
+ *     return frb_read(buf, 1)[0] is b'\x01'             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(5, 18, __pyx_L1_error)
+  __pyx_t_2 = __Pyx_PyBool_FromLong(((__pyx_t_1[0]) == '\x01')); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":17
+ * 
+ * 
+ * cdef bool_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return frb_read(buf, 1)[0] is b'\x01'
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.bool_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":21
+ * 
+ * 
+ * cdef int2_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef long val
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_int2_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int __pyx_v_overflow;
+  long __pyx_v_val;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  long __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  __Pyx_RefNannySetupContext("int2_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":22
+ * 
+ * cdef int2_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0             # <<<<<<<<<<<<<<
+ *     cdef long val
+ * 
+ */
+  __pyx_v_overflow = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":25
+ *     cdef long val
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_1);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/int.pyx":26
+ * 
+ *     try:
+ *         val = cpython.PyLong_AsLong(obj)             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = 1
+ */
+      __pyx_t_4 = PyLong_AsLong(__pyx_v_obj); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(5, 26, __pyx_L3_error)
+      __pyx_v_val = __pyx_t_4;
+
+      /* "asyncpg/pgproto/codecs/int.pyx":25
+ *     cdef long val
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":27
+ *     try:
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = 1
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_5) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int2_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(5, 27, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_8);
+
+      /* "asyncpg/pgproto/codecs/int.pyx":28
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ *         overflow = 1             # <<<<<<<<<<<<<<
+ * 
+ *     if overflow or val < INT16_MIN or val > INT16_MAX:
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":25
+ *     cdef long val
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":30
+ *         overflow = 1
+ * 
+ *     if overflow or val < INT16_MIN or val > INT16_MAX:             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of int16 range')
+ * 
+ */
+  __pyx_t_10 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val < INT16_MIN) != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val > INT16_MAX) != 0);
+  __pyx_t_9 = __pyx_t_10;
+  __pyx_L12_bool_binop_done:;
+  if (unlikely(__pyx_t_9)) {
+
+    /* "asyncpg/pgproto/codecs/int.pyx":31
+ * 
+ *     if overflow or val < INT16_MIN or val > INT16_MAX:
+ *         raise OverflowError('value out of int16 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(2)
+ */
+    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_OverflowError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 31, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __PYX_ERR(5, 31, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/int.pyx":30
+ *         overflow = 1
+ * 
+ *     if overflow or val < INT16_MIN or val > INT16_MAX:             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of int16 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":33
+ *         raise OverflowError('value out of int16 range')
+ * 
+ *     buf.write_int32(2)             # <<<<<<<<<<<<<<
+ *     buf.write_int16(<int16_t>val)
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 2); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 33, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":34
+ * 
+ *     buf.write_int32(2)
+ *     buf.write_int16(<int16_t>val)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, ((int16_t)__pyx_v_val)); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 34, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":21
+ * 
+ * 
+ * cdef int2_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef long val
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int2_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":37
+ * 
+ * 
+ * cdef int2_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromLong(hton.unpack_int16(frb_read(buf, 2)))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_int2_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("int2_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":38
+ * 
+ * cdef int2_decode(CodecContext settings, FRBuffer *buf):
+ *     return cpython.PyLong_FromLong(hton.unpack_int16(frb_read(buf, 2)))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(5, 38, __pyx_L1_error)
+  __pyx_t_2 = PyLong_FromLong(unpack_int16(__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":37
+ * 
+ * 
+ * cdef int2_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromLong(hton.unpack_int16(frb_read(buf, 2)))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int2_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":41
+ * 
+ * 
+ * cdef int4_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef long val = 0
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_int4_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int __pyx_v_overflow;
+  long __pyx_v_val;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  long __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  __Pyx_RefNannySetupContext("int4_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":42
+ * 
+ * cdef int4_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0             # <<<<<<<<<<<<<<
+ *     cdef long val = 0
+ * 
+ */
+  __pyx_v_overflow = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":43
+ * cdef int4_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0
+ *     cdef long val = 0             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+  __pyx_v_val = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":45
+ *     cdef long val = 0
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_1);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/int.pyx":46
+ * 
+ *     try:
+ *         val = cpython.PyLong_AsLong(obj)             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = 1
+ */
+      __pyx_t_4 = PyLong_AsLong(__pyx_v_obj); if (unlikely(__pyx_t_4 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(5, 46, __pyx_L3_error)
+      __pyx_v_val = __pyx_t_4;
+
+      /* "asyncpg/pgproto/codecs/int.pyx":45
+ *     cdef long val = 0
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":47
+ *     try:
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = 1
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_5) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int4_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(5, 47, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_8);
+
+      /* "asyncpg/pgproto/codecs/int.pyx":48
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ *         overflow = 1             # <<<<<<<<<<<<<<
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":45
+ *     cdef long val = 0
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLong(obj)
+ *     except OverflowError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":51
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and (val < INT32_MIN or val > INT32_MAX)):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of int32 range')
+ * 
+ */
+  __pyx_t_10 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = (((sizeof(__pyx_v_val)) > 4) != 0);
+  if (__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val < INT32_MIN) != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val > INT32_MAX) != 0);
+  __pyx_t_9 = __pyx_t_10;
+  __pyx_L12_bool_binop_done:;
+  if (unlikely(__pyx_t_9)) {
+
+    /* "asyncpg/pgproto/codecs/int.pyx":52
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and (val < INT32_MIN or val > INT32_MAX)):
+ *         raise OverflowError('value out of int32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_OverflowError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 52, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __PYX_ERR(5, 52, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/int.pyx":51
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and (val < INT32_MIN or val > INT32_MAX)):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of int32 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":54
+ *         raise OverflowError('value out of int32 range')
+ * 
+ *     buf.write_int32(4)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(<int32_t>val)
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 4); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":55
+ * 
+ *     buf.write_int32(4)
+ *     buf.write_int32(<int32_t>val)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, ((int32_t)__pyx_v_val)); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":41
+ * 
+ * 
+ * cdef int4_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef long val = 0
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int4_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":58
+ * 
+ * 
+ * cdef int4_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromLong(hton.unpack_int32(frb_read(buf, 4)))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_int4_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("int4_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":59
+ * 
+ * cdef int4_decode(CodecContext settings, FRBuffer *buf):
+ *     return cpython.PyLong_FromLong(hton.unpack_int32(frb_read(buf, 4)))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(5, 59, __pyx_L1_error)
+  __pyx_t_2 = PyLong_FromLong(unpack_int32(__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":58
+ * 
+ * 
+ * cdef int4_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromLong(hton.unpack_int32(frb_read(buf, 4)))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int4_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":62
+ * 
+ * 
+ * cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef unsigned long val = 0
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int __pyx_v_overflow;
+  unsigned long __pyx_v_val;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  unsigned long __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  __Pyx_RefNannySetupContext("uint4_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":63
+ * 
+ * cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0             # <<<<<<<<<<<<<<
+ *     cdef unsigned long val = 0
+ * 
+ */
+  __pyx_v_overflow = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":64
+ * cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0
+ *     cdef unsigned long val = 0             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+  __pyx_v_val = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":66
+ *     cdef unsigned long val = 0
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsUnsignedLong(obj)
+ *     except OverflowError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_1);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/int.pyx":67
+ * 
+ *     try:
+ *         val = cpython.PyLong_AsUnsignedLong(obj)             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = 1
+ */
+      __pyx_t_4 = PyLong_AsUnsignedLong(__pyx_v_obj); if (unlikely(__pyx_t_4 == ((unsigned long)-1L) && PyErr_Occurred())) __PYX_ERR(5, 67, __pyx_L3_error)
+      __pyx_v_val = __pyx_t_4;
+
+      /* "asyncpg/pgproto/codecs/int.pyx":66
+ *     cdef unsigned long val = 0
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsUnsignedLong(obj)
+ *     except OverflowError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":68
+ *     try:
+ *         val = cpython.PyLong_AsUnsignedLong(obj)
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = 1
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_5) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.uint4_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(5, 68, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_8);
+
+      /* "asyncpg/pgproto/codecs/int.pyx":69
+ *         val = cpython.PyLong_AsUnsignedLong(obj)
+ *     except OverflowError:
+ *         overflow = 1             # <<<<<<<<<<<<<<
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":66
+ *     cdef unsigned long val = 0
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsUnsignedLong(obj)
+ *     except OverflowError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":72
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and val > UINT32_MAX):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of uint32 range')
+ * 
+ */
+  __pyx_t_10 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = (((sizeof(__pyx_v_val)) > 4) != 0);
+  if (__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val > UINT32_MAX) != 0);
+  __pyx_t_9 = __pyx_t_10;
+  __pyx_L12_bool_binop_done:;
+  if (unlikely(__pyx_t_9)) {
+
+    /* "asyncpg/pgproto/codecs/int.pyx":73
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and val > UINT32_MAX):
+ *         raise OverflowError('value out of uint32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_OverflowError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 73, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __PYX_ERR(5, 73, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/int.pyx":72
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and val > UINT32_MAX):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of uint32 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":75
+ *         raise OverflowError('value out of uint32 range')
+ * 
+ *     buf.write_int32(4)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(<int32_t>val)
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 4); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 75, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":76
+ * 
+ *     buf.write_int32(4)
+ *     buf.write_int32(<int32_t>val)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, ((int32_t)__pyx_v_val)); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 76, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":62
+ * 
+ * 
+ * cdef uint4_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef unsigned long val = 0
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.uint4_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":79
+ * 
+ * 
+ * cdef uint4_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromUnsignedLong(
+ *         <uint32_t>hton.unpack_int32(frb_read(buf, 4)))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("uint4_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":80
+ * 
+ * cdef uint4_decode(CodecContext settings, FRBuffer *buf):
+ *     return cpython.PyLong_FromUnsignedLong(             # <<<<<<<<<<<<<<
+ *         <uint32_t>hton.unpack_int32(frb_read(buf, 4)))
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":81
+ * cdef uint4_decode(CodecContext settings, FRBuffer *buf):
+ *     return cpython.PyLong_FromUnsignedLong(
+ *         <uint32_t>hton.unpack_int32(frb_read(buf, 4)))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(5, 81, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/codecs/int.pyx":80
+ * 
+ * cdef uint4_decode(CodecContext settings, FRBuffer *buf):
+ *     return cpython.PyLong_FromUnsignedLong(             # <<<<<<<<<<<<<<
+ *         <uint32_t>hton.unpack_int32(frb_read(buf, 4)))
+ * 
+ */
+  __pyx_t_2 = PyLong_FromUnsignedLong(((uint32_t)unpack_int32(__pyx_t_1))); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":79
+ * 
+ * 
+ * cdef uint4_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromUnsignedLong(
+ *         <uint32_t>hton.unpack_int32(frb_read(buf, 4)))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.uint4_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":84
+ * 
+ * 
+ * cdef int8_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef long long val
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_int8_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int __pyx_v_overflow;
+  PY_LONG_LONG __pyx_v_val;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PY_LONG_LONG __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  __Pyx_RefNannySetupContext("int8_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":85
+ * 
+ * cdef int8_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0             # <<<<<<<<<<<<<<
+ *     cdef long long val
+ * 
+ */
+  __pyx_v_overflow = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":88
+ *     cdef long long val
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLongLong(obj)
+ *     except OverflowError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_1);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/int.pyx":89
+ * 
+ *     try:
+ *         val = cpython.PyLong_AsLongLong(obj)             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = 1
+ */
+      __pyx_t_4 = PyLong_AsLongLong(__pyx_v_obj); if (unlikely(__pyx_t_4 == ((PY_LONG_LONG)-1LL) && PyErr_Occurred())) __PYX_ERR(5, 89, __pyx_L3_error)
+      __pyx_v_val = __pyx_t_4;
+
+      /* "asyncpg/pgproto/codecs/int.pyx":88
+ *     cdef long long val
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLongLong(obj)
+ *     except OverflowError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":90
+ *     try:
+ *         val = cpython.PyLong_AsLongLong(obj)
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = 1
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_5) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int8_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(5, 90, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_8);
+
+      /* "asyncpg/pgproto/codecs/int.pyx":91
+ *         val = cpython.PyLong_AsLongLong(obj)
+ *     except OverflowError:
+ *         overflow = 1             # <<<<<<<<<<<<<<
+ * 
+ *     # Just in case for systems with "long long" bigger than 8 bytes
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/pgproto/codecs/int.pyx":88
+ *     cdef long long val
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         val = cpython.PyLong_AsLongLong(obj)
+ *     except OverflowError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":94
+ * 
+ *     # Just in case for systems with "long long" bigger than 8 bytes
+ *     if overflow or (sizeof(val) > 8 and (val < INT64_MIN or val > INT64_MAX)):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of int64 range')
+ * 
+ */
+  __pyx_t_10 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = (((sizeof(__pyx_v_val)) > 8) != 0);
+  if (__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val < INT64_MIN) != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_val > INT64_MAX) != 0);
+  __pyx_t_9 = __pyx_t_10;
+  __pyx_L12_bool_binop_done:;
+  if (unlikely(__pyx_t_9)) {
+
+    /* "asyncpg/pgproto/codecs/int.pyx":95
+ *     # Just in case for systems with "long long" bigger than 8 bytes
+ *     if overflow or (sizeof(val) > 8 and (val < INT64_MIN or val > INT64_MAX)):
+ *         raise OverflowError('value out of int64 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(8)
+ */
+    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_OverflowError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 95, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __PYX_ERR(5, 95, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/int.pyx":94
+ * 
+ *     # Just in case for systems with "long long" bigger than 8 bytes
+ *     if overflow or (sizeof(val) > 8 and (val < INT64_MIN or val > INT64_MAX)):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('value out of int64 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/int.pyx":97
+ *         raise OverflowError('value out of int64 range')
+ * 
+ *     buf.write_int32(8)             # <<<<<<<<<<<<<<
+ *     buf.write_int64(<int64_t>val)
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 8); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 97, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":98
+ * 
+ *     buf.write_int32(8)
+ *     buf.write_int64(<int64_t>val)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_8 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, ((int64_t)__pyx_v_val)); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 98, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":84
+ * 
+ * 
+ * cdef int8_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef long long val
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int8_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/int.pyx":101
+ * 
+ * 
+ * cdef int8_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_int8_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("int8_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":102
+ * 
+ * cdef int8_decode(CodecContext settings, FRBuffer *buf):
+ *     return cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(5, 102, __pyx_L1_error)
+  __pyx_t_2 = PyLong_FromLongLong(unpack_int64(__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 102, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/int.pyx":101
+ * 
+ * 
+ * cdef int8_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.int8_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/json.pyx":8
+ * 
+ * 
+ * cdef jsonb_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         char *str
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  char *__pyx_v_str;
+  Py_ssize_t __pyx_v_size;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("jsonb_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/json.pyx":13
+ *         ssize_t size
+ * 
+ *     as_pg_string_and_size(settings, obj, &str, &size)             # <<<<<<<<<<<<<<
+ * 
+ *     if size > 0x7fffffff - 1:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(__pyx_v_settings, __pyx_v_obj, (&__pyx_v_str), (&__pyx_v_size)); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/json.pyx":15
+ *     as_pg_string_and_size(settings, obj, &str, &size)
+ * 
+ *     if size > 0x7fffffff - 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError('string too long')
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_size > 0x7FFFFFFE) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/json.pyx":16
+ * 
+ *     if size > 0x7fffffff - 1:
+ *         raise ValueError('string too long')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(<int32_t>size + 1)
+ */
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 16, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(10, 16, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/json.pyx":15
+ *     as_pg_string_and_size(settings, obj, &str, &size)
+ * 
+ *     if size > 0x7fffffff - 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError('string too long')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/json.pyx":18
+ *         raise ValueError('string too long')
+ * 
+ *     buf.write_int32(<int32_t>size + 1)             # <<<<<<<<<<<<<<
+ *     buf.write_byte(1)  # JSONB format version
+ *     buf.write_cstr(str, size)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, (((int32_t)__pyx_v_size) + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/json.pyx":19
+ * 
+ *     buf.write_int32(<int32_t>size + 1)
+ *     buf.write_byte(1)  # JSONB format version             # <<<<<<<<<<<<<<
+ *     buf.write_cstr(str, size)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/json.pyx":20
+ *     buf.write_int32(<int32_t>size + 1)
+ *     buf.write_byte(1)  # JSONB format version
+ *     buf.write_cstr(str, size)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_buf, __pyx_v_str, __pyx_v_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 20, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/json.pyx":8
+ * 
+ * 
+ * cdef jsonb_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         char *str
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.jsonb_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/json.pyx":23
+ * 
+ * 
+ * cdef jsonb_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef uint8_t format = <uint8_t>(frb_read(buf, 1)[0])
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  uint8_t __pyx_v_format;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("jsonb_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/json.pyx":24
+ * 
+ * cdef jsonb_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef uint8_t format = <uint8_t>(frb_read(buf, 1)[0])             # <<<<<<<<<<<<<<
+ * 
+ *     if format != 1:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(10, 24, __pyx_L1_error)
+  __pyx_v_format = ((uint8_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/pgproto/codecs/json.pyx":26
+ *     cdef uint8_t format = <uint8_t>(frb_read(buf, 1)[0])
+ * 
+ *     if format != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError('unexpected JSONB format: {}'.format(format))
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_format != 1) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/json.pyx":27
+ * 
+ *     if format != 1:
+ *         raise ValueError('unexpected JSONB format: {}'.format(format))             # <<<<<<<<<<<<<<
+ * 
+ *     return text_decode(settings, buf)
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_JSONB_format, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(10, 27, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyInt_From_uint8_t(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(10, 27, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(10, 27, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(10, 27, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(10, 27, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/json.pyx":26
+ *     cdef uint8_t format = <uint8_t>(frb_read(buf, 1)[0])
+ * 
+ *     if format != 1:             # <<<<<<<<<<<<<<
+ *         raise ValueError('unexpected JSONB format: {}'.format(format))
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/json.pyx":29
+ *         raise ValueError('unexpected JSONB format: {}'.format(format))
+ * 
+ *     return text_decode(settings, buf)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(__pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_4)) __PYX_ERR(10, 29, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_r = __pyx_t_4;
+  __pyx_t_4 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/json.pyx":23
+ * 
+ * 
+ * cdef jsonb_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef uint8_t format = <uint8_t>(frb_read(buf, 1)[0])
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.jsonb_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/uuid.pyx":14
+ * 
+ * 
+ * cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     if cpython.PyUnicode_Check(obj):
+ *         obj = _UUID(obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("uuid_encode", 0);
+  __Pyx_INCREF(__pyx_v_obj);
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":15
+ * 
+ * cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     if cpython.PyUnicode_Check(obj):             # <<<<<<<<<<<<<<
+ *         obj = _UUID(obj)
+ * 
+ */
+  __pyx_t_1 = (PyUnicode_Check(__pyx_v_obj) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/uuid.pyx":16
+ * cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     if cpython.PyUnicode_Check(obj):
+ *         obj = _UUID(obj)             # <<<<<<<<<<<<<<
+ * 
+ *     bytea_encode(settings, wbuf, obj.bytes)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_UUID); if (unlikely(!__pyx_t_3)) __PYX_ERR(11, 16, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_obj);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(11, 16, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/codecs/uuid.pyx":15
+ * 
+ * cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     if cpython.PyUnicode_Check(obj):             # <<<<<<<<<<<<<<
+ *         obj = _UUID(obj)
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":18
+ *         obj = _UUID(obj)
+ * 
+ *     bytea_encode(settings, wbuf, obj.bytes)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_bytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(11, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode(__pyx_v_settings, __pyx_v_wbuf, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(11, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":14
+ * 
+ * 
+ * cdef uuid_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     if cpython.PyUnicode_Check(obj):
+ *         obj = _UUID(obj)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.uuid_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_obj);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/uuid.pyx":21
+ * 
+ * 
+ * cdef uuid_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return _UUID(bytes=bytea_decode(settings, buf))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("uuid_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":22
+ * 
+ * cdef uuid_decode(CodecContext settings, FRBuffer *buf):
+ *     return _UUID(bytes=bytea_decode(settings, buf))             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_UUID); if (unlikely(!__pyx_t_1)) __PYX_ERR(11, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(11, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode(__pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_3)) __PYX_ERR(11, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_bytes, __pyx_t_3) < 0) __PYX_ERR(11, 22, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(11, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":21
+ * 
+ * 
+ * cdef uuid_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return _UUID(bytes=bytea_decode(settings, buf))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.uuid_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/numeric.pyx":23
+ * 
+ * 
+ * cdef numeric_encode_text(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     text_encode(settings, buf, str(obj))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_text(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("numeric_encode_text", 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":24
+ * 
+ * cdef numeric_encode_text(CodecContext settings, WriteBuffer buf, obj):
+ *     text_encode(settings, buf, str(obj))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 24, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_encode(__pyx_v_settings, __pyx_v_buf, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(6, 24, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":23
+ * 
+ * 
+ * cdef numeric_encode_text(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     text_encode(settings, buf, str(obj))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.numeric_encode_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/numeric.pyx":27
+ * 
+ * 
+ * cdef numeric_decode_text(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return _Dec(text_decode(settings, buf))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_text(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("numeric_decode_text", 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":28
+ * 
+ * cdef numeric_decode_text(CodecContext settings, FRBuffer *buf):
+ *     return _Dec(text_decode(settings, buf))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Dec); if (unlikely(!__pyx_t_2)) __PYX_ERR(6, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(__pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":27
+ * 
+ * 
+ * cdef numeric_decode_text(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return _Dec(text_decode(settings, buf))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.numeric_decode_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/numeric.pyx":31
+ * 
+ * 
+ * cdef numeric_encode_binary(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         object dec
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_binary(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_dec = 0;
+  PyObject *__pyx_v_dt = 0;
+  int64_t __pyx_v_exponent;
+  CYTHON_UNUSED int64_t __pyx_v_i;
+  int64_t __pyx_v_j;
+  PyObject *__pyx_v_pydigits = 0;
+  int64_t __pyx_v_num_pydigits;
+  int16_t __pyx_v_pgdigit;
+  int64_t __pyx_v_num_pgdigits;
+  int16_t __pyx_v_dscale;
+  int64_t __pyx_v_dweight;
+  int64_t __pyx_v_weight;
+  uint16_t __pyx_v_sign;
+  int64_t __pyx_v_padding_size;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int64_t __pyx_t_6;
+  Py_ssize_t __pyx_t_7;
+  int64_t __pyx_t_8;
+  int64_t __pyx_t_9;
+  int64_t __pyx_t_10;
+  int16_t __pyx_t_11;
+  __Pyx_RefNannySetupContext("numeric_encode_binary", 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":46
+ *         int64_t weight
+ *         uint16_t sign
+ *         int64_t padding_size = 0             # <<<<<<<<<<<<<<
+ * 
+ *     if isinstance(obj, _Dec):
+ */
+  __pyx_v_padding_size = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":48
+ *         int64_t padding_size = 0
+ * 
+ *     if isinstance(obj, _Dec):             # <<<<<<<<<<<<<<
+ *         dec = obj
+ *     else:
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Dec); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 48, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(6, 48, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":49
+ * 
+ *     if isinstance(obj, _Dec):
+ *         dec = obj             # <<<<<<<<<<<<<<
+ *     else:
+ *         dec = _Dec(obj)
+ */
+    __Pyx_INCREF(__pyx_v_obj);
+    __pyx_v_dec = __pyx_v_obj;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":48
+ *         int64_t padding_size = 0
+ * 
+ *     if isinstance(obj, _Dec):             # <<<<<<<<<<<<<<
+ *         dec = obj
+ *     else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":51
+ *         dec = obj
+ *     else:
+ *         dec = _Dec(obj)             # <<<<<<<<<<<<<<
+ * 
+ *     dt = dec.as_tuple()
+ */
+  /*else*/ {
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_Dec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 51, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_obj);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 51, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_v_dec = __pyx_t_1;
+    __pyx_t_1 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":53
+ *         dec = _Dec(obj)
+ * 
+ *     dt = dec.as_tuple()             # <<<<<<<<<<<<<<
+ *     if dt.exponent == 'F':
+ *         raise ValueError('numeric type does not support infinite values')
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_dec, __pyx_n_s_as_tuple); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 53, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 53, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_dt = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":54
+ * 
+ *     dt = dec.as_tuple()
+ *     if dt.exponent == 'F':             # <<<<<<<<<<<<<<
+ *         raise ValueError('numeric type does not support infinite values')
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dt, __pyx_n_s_exponent); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_F, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(6, 54, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":55
+ *     dt = dec.as_tuple()
+ *     if dt.exponent == 'F':
+ *         raise ValueError('numeric type does not support infinite values')             # <<<<<<<<<<<<<<
+ * 
+ *     if dt.exponent == 'n' or dt.exponent == 'N':
+ */
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 55, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(6, 55, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":54
+ * 
+ *     dt = dec.as_tuple()
+ *     if dt.exponent == 'F':             # <<<<<<<<<<<<<<
+ *         raise ValueError('numeric type does not support infinite values')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":57
+ *         raise ValueError('numeric type does not support infinite values')
+ * 
+ *     if dt.exponent == 'n' or dt.exponent == 'N':             # <<<<<<<<<<<<<<
+ *         # NaN
+ *         sign = NUMERIC_NAN
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dt, __pyx_n_s_exponent); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 57, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_n, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(6, 57, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_3 = __pyx_t_2;
+    goto __pyx_L6_bool_binop_done;
+  }
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dt, __pyx_n_s_exponent); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 57, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_N, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(6, 57, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = __pyx_t_2;
+  __pyx_L6_bool_binop_done:;
+  if (__pyx_t_3) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":59
+ *     if dt.exponent == 'n' or dt.exponent == 'N':
+ *         # NaN
+ *         sign = NUMERIC_NAN             # <<<<<<<<<<<<<<
+ *         num_pgdigits = 0
+ *         weight = 0
+ */
+    __pyx_v_sign = 0xC000;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":60
+ *         # NaN
+ *         sign = NUMERIC_NAN
+ *         num_pgdigits = 0             # <<<<<<<<<<<<<<
+ *         weight = 0
+ *         dscale = 0
+ */
+    __pyx_v_num_pgdigits = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":61
+ *         sign = NUMERIC_NAN
+ *         num_pgdigits = 0
+ *         weight = 0             # <<<<<<<<<<<<<<
+ *         dscale = 0
+ *     else:
+ */
+    __pyx_v_weight = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":62
+ *         num_pgdigits = 0
+ *         weight = 0
+ *         dscale = 0             # <<<<<<<<<<<<<<
+ *     else:
+ *         exponent = dt.exponent
+ */
+    __pyx_v_dscale = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":57
+ *         raise ValueError('numeric type does not support infinite values')
+ * 
+ *     if dt.exponent == 'n' or dt.exponent == 'N':             # <<<<<<<<<<<<<<
+ *         # NaN
+ *         sign = NUMERIC_NAN
+ */
+    goto __pyx_L5;
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":64
+ *         dscale = 0
+ *     else:
+ *         exponent = dt.exponent             # <<<<<<<<<<<<<<
+ *         if exponent < 0 and -exponent > MAX_DSCALE:
+ *             raise ValueError(
+ */
+  /*else*/ {
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dt, __pyx_n_s_exponent); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 64, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_6 = __Pyx_PyInt_As_int64_t(__pyx_t_1); if (unlikely((__pyx_t_6 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 64, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_v_exponent = __pyx_t_6;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":65
+ *     else:
+ *         exponent = dt.exponent
+ *         if exponent < 0 and -exponent > MAX_DSCALE:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                 'cannot encode Decimal value into numeric: '
+ */
+    __pyx_t_2 = ((__pyx_v_exponent < 0) != 0);
+    if (__pyx_t_2) {
+    } else {
+      __pyx_t_3 = __pyx_t_2;
+      goto __pyx_L9_bool_binop_done;
+    }
+    __pyx_t_2 = (((-__pyx_v_exponent) > 0x3FFF) != 0);
+    __pyx_t_3 = __pyx_t_2;
+    __pyx_L9_bool_binop_done:;
+    if (unlikely(__pyx_t_3)) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":66
+ *         exponent = dt.exponent
+ *         if exponent < 0 and -exponent > MAX_DSCALE:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                 'cannot encode Decimal value into numeric: '
+ *                 'exponent is too small')
+ */
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 66, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(6, 66, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":65
+ *     else:
+ *         exponent = dt.exponent
+ *         if exponent < 0 and -exponent > MAX_DSCALE:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                 'cannot encode Decimal value into numeric: '
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":70
+ *                 'exponent is too small')
+ * 
+ *         if dt.sign:             # <<<<<<<<<<<<<<
+ *             sign = NUMERIC_NEG
+ *         else:
+ */
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dt, __pyx_n_s_sign); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 70, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(6, 70, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    if (__pyx_t_3) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":71
+ * 
+ *         if dt.sign:
+ *             sign = NUMERIC_NEG             # <<<<<<<<<<<<<<
+ *         else:
+ *             sign = NUMERIC_POS
+ */
+      __pyx_v_sign = 0x4000;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":70
+ *                 'exponent is too small')
+ * 
+ *         if dt.sign:             # <<<<<<<<<<<<<<
+ *             sign = NUMERIC_NEG
+ *         else:
+ */
+      goto __pyx_L11;
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":73
+ *             sign = NUMERIC_NEG
+ *         else:
+ *             sign = NUMERIC_POS             # <<<<<<<<<<<<<<
+ * 
+ *         pydigits = dt.digits
+ */
+    /*else*/ {
+      __pyx_v_sign = 0;
+    }
+    __pyx_L11:;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":75
+ *             sign = NUMERIC_POS
+ * 
+ *         pydigits = dt.digits             # <<<<<<<<<<<<<<
+ *         num_pydigits = len(pydigits)
+ * 
+ */
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dt, __pyx_n_s_digits); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 75, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(6, 75, __pyx_L1_error)
+    __pyx_v_pydigits = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":76
+ * 
+ *         pydigits = dt.digits
+ *         num_pydigits = len(pydigits)             # <<<<<<<<<<<<<<
+ * 
+ *         dweight = num_pydigits + exponent - 1
+ */
+    if (unlikely(__pyx_v_pydigits == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+      __PYX_ERR(6, 76, __pyx_L1_error)
+    }
+    __pyx_t_7 = PyTuple_GET_SIZE(__pyx_v_pydigits); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(6, 76, __pyx_L1_error)
+    __pyx_v_num_pydigits = __pyx_t_7;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":78
+ *         num_pydigits = len(pydigits)
+ * 
+ *         dweight = num_pydigits + exponent - 1             # <<<<<<<<<<<<<<
+ *         if dweight >= 0:
+ *             weight = (dweight + DEC_DIGITS) // DEC_DIGITS - 1
+ */
+    __pyx_v_dweight = ((__pyx_v_num_pydigits + __pyx_v_exponent) - 1);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":79
+ * 
+ *         dweight = num_pydigits + exponent - 1
+ *         if dweight >= 0:             # <<<<<<<<<<<<<<
+ *             weight = (dweight + DEC_DIGITS) // DEC_DIGITS - 1
+ *         else:
+ */
+    __pyx_t_3 = ((__pyx_v_dweight >= 0) != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":80
+ *         dweight = num_pydigits + exponent - 1
+ *         if dweight >= 0:
+ *             weight = (dweight + DEC_DIGITS) // DEC_DIGITS - 1             # <<<<<<<<<<<<<<
+ *         else:
+ *             weight = -((-dweight - 1) // DEC_DIGITS + 1)
+ */
+      __pyx_v_weight = (__Pyx_div_int64_t((__pyx_v_dweight + 4), 4) - 1);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":79
+ * 
+ *         dweight = num_pydigits + exponent - 1
+ *         if dweight >= 0:             # <<<<<<<<<<<<<<
+ *             weight = (dweight + DEC_DIGITS) // DEC_DIGITS - 1
+ *         else:
+ */
+      goto __pyx_L12;
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":82
+ *             weight = (dweight + DEC_DIGITS) // DEC_DIGITS - 1
+ *         else:
+ *             weight = -((-dweight - 1) // DEC_DIGITS + 1)             # <<<<<<<<<<<<<<
+ * 
+ *         if weight > 2 ** 16 - 1:
+ */
+    /*else*/ {
+      __pyx_v_weight = (-(__Pyx_div_int64_t(((-__pyx_v_dweight) - 1), 4) + 1));
+    }
+    __pyx_L12:;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":84
+ *             weight = -((-dweight - 1) // DEC_DIGITS + 1)
+ * 
+ *         if weight > 2 ** 16 - 1:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                     'cannot encode Decimal value into numeric: '
+ */
+    __pyx_t_3 = ((__pyx_v_weight > 0xFFFF) != 0);
+    if (unlikely(__pyx_t_3)) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":85
+ * 
+ *         if weight > 2 ** 16 - 1:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'exponent is too large')
+ */
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 85, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(6, 85, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":84
+ *             weight = -((-dweight - 1) // DEC_DIGITS + 1)
+ * 
+ *         if weight > 2 ** 16 - 1:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                     'cannot encode Decimal value into numeric: '
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":90
+ * 
+ *         padding_size = \
+ *             (weight + 1) * DEC_DIGITS - (dweight + 1)             # <<<<<<<<<<<<<<
+ *         num_pgdigits = \
+ *             (num_pydigits + padding_size + DEC_DIGITS - 1) // DEC_DIGITS
+ */
+    __pyx_v_padding_size = (((__pyx_v_weight + 1) * 4) - (__pyx_v_dweight + 1));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":92
+ *             (weight + 1) * DEC_DIGITS - (dweight + 1)
+ *         num_pgdigits = \
+ *             (num_pydigits + padding_size + DEC_DIGITS - 1) // DEC_DIGITS             # <<<<<<<<<<<<<<
+ * 
+ *         if num_pgdigits > 2 ** 16 - 1:
+ */
+    __pyx_v_num_pgdigits = __Pyx_div_int64_t((((__pyx_v_num_pydigits + __pyx_v_padding_size) + 4) - 1), 4);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":94
+ *             (num_pydigits + padding_size + DEC_DIGITS - 1) // DEC_DIGITS
+ * 
+ *         if num_pgdigits > 2 ** 16 - 1:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                     'cannot encode Decimal value into numeric: '
+ */
+    __pyx_t_3 = ((__pyx_v_num_pgdigits > 0xFFFF) != 0);
+    if (unlikely(__pyx_t_3)) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":95
+ * 
+ *         if num_pgdigits > 2 ** 16 - 1:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'number of digits is too large')
+ */
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 95, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(6, 95, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":94
+ *             (num_pydigits + padding_size + DEC_DIGITS - 1) // DEC_DIGITS
+ * 
+ *         if num_pgdigits > 2 ** 16 - 1:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                     'cannot encode Decimal value into numeric: '
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":101
+ *         # Pad decimal digits to provide room for correct Postgres
+ *         # digit alignment in the digit computation loop.
+ *         pydigits = (0,) * DEC_DIGITS + pydigits + (0,) * DEC_DIGITS             # <<<<<<<<<<<<<<
+ * 
+ *         if exponent < 0:
+ */
+    __pyx_t_1 = PyNumber_Add(__pyx_tuple__17, __pyx_v_pydigits); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 101, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_tuple__17); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 101, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF_SET(__pyx_v_pydigits, ((PyObject*)__pyx_t_4));
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":103
+ *         pydigits = (0,) * DEC_DIGITS + pydigits + (0,) * DEC_DIGITS
+ * 
+ *         if exponent < 0:             # <<<<<<<<<<<<<<
+ *             if -exponent > MAX_DSCALE:
+ *                 raise ValueError(
+ */
+    __pyx_t_3 = ((__pyx_v_exponent < 0) != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":104
+ * 
+ *         if exponent < 0:
+ *             if -exponent > MAX_DSCALE:             # <<<<<<<<<<<<<<
+ *                 raise ValueError(
+ *                     'cannot encode Decimal value into numeric: '
+ */
+      __pyx_t_3 = (((-__pyx_v_exponent) > 0x3FFF) != 0);
+      if (unlikely(__pyx_t_3)) {
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":105
+ *         if exponent < 0:
+ *             if -exponent > MAX_DSCALE:
+ *                 raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'exponent is too small')
+ */
+        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 105, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __PYX_ERR(6, 105, __pyx_L1_error)
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":104
+ * 
+ *         if exponent < 0:
+ *             if -exponent > MAX_DSCALE:             # <<<<<<<<<<<<<<
+ *                 raise ValueError(
+ *                     'cannot encode Decimal value into numeric: '
+ */
+      }
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":108
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'exponent is too small')
+ *             dscale = <int16_t>-exponent             # <<<<<<<<<<<<<<
+ *         else:
+ *             dscale = 0
+ */
+      __pyx_v_dscale = ((int16_t)(-__pyx_v_exponent));
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":103
+ *         pydigits = (0,) * DEC_DIGITS + pydigits + (0,) * DEC_DIGITS
+ * 
+ *         if exponent < 0:             # <<<<<<<<<<<<<<
+ *             if -exponent > MAX_DSCALE:
+ *                 raise ValueError(
+ */
+      goto __pyx_L15;
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":110
+ *             dscale = <int16_t>-exponent
+ *         else:
+ *             dscale = 0             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(2 + 2 + 2 + 2 + 2 * <uint16_t>num_pgdigits)
+ */
+    /*else*/ {
+      __pyx_v_dscale = 0;
+    }
+    __pyx_L15:;
+  }
+  __pyx_L5:;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":112
+ *             dscale = 0
+ * 
+ *     buf.write_int32(2 + 2 + 2 + 2 + 2 * <uint16_t>num_pgdigits)             # <<<<<<<<<<<<<<
+ *     buf.write_int16(<int16_t>num_pgdigits)
+ *     buf.write_int16(<int16_t>weight)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, (8 + (2 * ((uint16_t)__pyx_v_num_pgdigits)))); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 112, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":113
+ * 
+ *     buf.write_int32(2 + 2 + 2 + 2 + 2 * <uint16_t>num_pgdigits)
+ *     buf.write_int16(<int16_t>num_pgdigits)             # <<<<<<<<<<<<<<
+ *     buf.write_int16(<int16_t>weight)
+ *     buf.write_int16(<int16_t>sign)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, ((int16_t)__pyx_v_num_pgdigits)); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 113, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":114
+ *     buf.write_int32(2 + 2 + 2 + 2 + 2 * <uint16_t>num_pgdigits)
+ *     buf.write_int16(<int16_t>num_pgdigits)
+ *     buf.write_int16(<int16_t>weight)             # <<<<<<<<<<<<<<
+ *     buf.write_int16(<int16_t>sign)
+ *     buf.write_int16(dscale)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, ((int16_t)__pyx_v_weight)); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 114, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":115
+ *     buf.write_int16(<int16_t>num_pgdigits)
+ *     buf.write_int16(<int16_t>weight)
+ *     buf.write_int16(<int16_t>sign)             # <<<<<<<<<<<<<<
+ *     buf.write_int16(dscale)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, ((int16_t)__pyx_v_sign)); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 115, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":116
+ *     buf.write_int16(<int16_t>weight)
+ *     buf.write_int16(<int16_t>sign)
+ *     buf.write_int16(dscale)             # <<<<<<<<<<<<<<
+ * 
+ *     j = DEC_DIGITS - padding_size
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, __pyx_v_dscale); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 116, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":118
+ *     buf.write_int16(dscale)
+ * 
+ *     j = DEC_DIGITS - padding_size             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(num_pgdigits):
+ */
+  __pyx_v_j = (4 - __pyx_v_padding_size);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":120
+ *     j = DEC_DIGITS - padding_size
+ * 
+ *     for i in range(num_pgdigits):             # <<<<<<<<<<<<<<
+ *         pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])
+ */
+  __pyx_t_6 = __pyx_v_num_pgdigits;
+  __pyx_t_8 = __pyx_t_6;
+  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
+    __pyx_v_i = __pyx_t_9;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":121
+ * 
+ *     for i in range(num_pgdigits):
+ *         pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +             # <<<<<<<<<<<<<<
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])
+ *         j += DEC_DIGITS
+ */
+    if (unlikely(!__pyx_v_pydigits)) { __Pyx_RaiseUnboundLocalError("pydigits"); __PYX_ERR(6, 121, __pyx_L1_error) }
+    __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_pydigits, __pyx_v_j, int64_t, 1, __Pyx_PyInt_From_int64_t, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 121, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyNumber_Multiply(__pyx_t_4, __pyx_int_1000); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 121, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_v_pydigits)) { __Pyx_RaiseUnboundLocalError("pydigits"); __PYX_ERR(6, 121, __pyx_L1_error) }
+    __pyx_t_10 = (__pyx_v_j + 1);
+    __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_pydigits, __pyx_t_10, int64_t, 1, __Pyx_PyInt_From_int64_t, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 121, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_int_100); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 121, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 121, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":122
+ *     for i in range(num_pgdigits):
+ *         pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])             # <<<<<<<<<<<<<<
+ *         j += DEC_DIGITS
+ *         buf.write_int16(pgdigit)
+ */
+    if (unlikely(!__pyx_v_pydigits)) { __Pyx_RaiseUnboundLocalError("pydigits"); __PYX_ERR(6, 122, __pyx_L1_error) }
+    __pyx_t_10 = (__pyx_v_j + 2);
+    __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_pydigits, __pyx_t_10, int64_t, 1, __Pyx_PyInt_From_int64_t, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, __pyx_int_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":121
+ * 
+ *     for i in range(num_pgdigits):
+ *         pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +             # <<<<<<<<<<<<<<
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])
+ *         j += DEC_DIGITS
+ */
+    __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 121, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":122
+ *     for i in range(num_pgdigits):
+ *         pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])             # <<<<<<<<<<<<<<
+ *         j += DEC_DIGITS
+ *         buf.write_int16(pgdigit)
+ */
+    if (unlikely(!__pyx_v_pydigits)) { __Pyx_RaiseUnboundLocalError("pydigits"); __PYX_ERR(6, 122, __pyx_L1_error) }
+    __pyx_t_10 = (__pyx_v_j + 3);
+    __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_pydigits, __pyx_t_10, int64_t, 1, __Pyx_PyInt_From_int64_t, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_11 = __Pyx_PyInt_As_int16_t(__pyx_t_4); if (unlikely((__pyx_t_11 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_v_pgdigit = __pyx_t_11;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":123
+ *         pgdigit = (pydigits[j] * 1000 + pydigits[j + 1] * 100 +
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])
+ *         j += DEC_DIGITS             # <<<<<<<<<<<<<<
+ *         buf.write_int16(pgdigit)
+ * 
+ */
+    __pyx_v_j = (__pyx_v_j + 4);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":124
+ *                    pydigits[j + 2] * 10 + pydigits[j + 3])
+ *         j += DEC_DIGITS
+ *         buf.write_int16(pgdigit)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, __pyx_v_pgdigit); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 124, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":31
+ * 
+ * 
+ * cdef numeric_encode_binary(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         object dec
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.numeric_encode_binary", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_dec);
+  __Pyx_XDECREF(__pyx_v_dt);
+  __Pyx_XDECREF(__pyx_v_pydigits);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/numeric.pyx":132
+ * # than the simple text decoder above.  That said, we need the binary
+ * # decoder to support binary COPY with numeric values.
+ * cdef numeric_decode_binary(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint16_t num_pgdigits = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_binary(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  uint16_t __pyx_v_num_pgdigits;
+  int16_t __pyx_v_weight;
+  uint16_t __pyx_v_sign;
+  uint16_t __pyx_v_dscale;
+  int16_t __pyx_v_pgdigit0;
+  Py_ssize_t __pyx_v_i;
+  int16_t __pyx_v_pgdigit;
+  PyObject *__pyx_v_pydigits = 0;
+  Py_ssize_t __pyx_v_num_pydigits;
+  Py_ssize_t __pyx_v_buf_size;
+  int64_t __pyx_v_exponent;
+  int64_t __pyx_v_abs_exponent;
+  Py_ssize_t __pyx_v_exponent_chars;
+  Py_ssize_t __pyx_v_front_padding;
+  CYTHON_UNUSED Py_ssize_t __pyx_v_trailing_padding;
+  Py_ssize_t __pyx_v_num_fract_digits;
+  Py_ssize_t __pyx_v_dscale_left;
+  char __pyx_v_smallbuf[0x100];
+  char *__pyx_v_charbuf;
+  char *__pyx_v_bufptr;
+  int __pyx_v_buf_allocated;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int64_t __pyx_t_7;
+  uint16_t __pyx_t_8;
+  uint16_t __pyx_t_9;
+  Py_ssize_t __pyx_t_10;
+  Py_ssize_t __pyx_t_11;
+  Py_ssize_t __pyx_t_12;
+  int __pyx_t_13;
+  int __pyx_t_14;
+  char const *__pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  PyObject *__pyx_t_21 = NULL;
+  __Pyx_RefNannySetupContext("numeric_decode_binary", 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":134
+ * cdef numeric_decode_binary(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         uint16_t num_pgdigits = <uint16_t>hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ *         int16_t weight = hton.unpack_int16(frb_read(buf, 2))
+ *         uint16_t sign = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(6, 134, __pyx_L1_error)
+  __pyx_v_num_pgdigits = ((uint16_t)unpack_int16(__pyx_t_1));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":135
+ *     cdef:
+ *         uint16_t num_pgdigits = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ *         int16_t weight = hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ *         uint16_t sign = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ *         uint16_t dscale = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(6, 135, __pyx_L1_error)
+  __pyx_v_weight = unpack_int16(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":136
+ *         uint16_t num_pgdigits = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ *         int16_t weight = hton.unpack_int16(frb_read(buf, 2))
+ *         uint16_t sign = <uint16_t>hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ *         uint16_t dscale = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ *         int16_t pgdigit0
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(6, 136, __pyx_L1_error)
+  __pyx_v_sign = ((uint16_t)unpack_int16(__pyx_t_1));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":137
+ *         int16_t weight = hton.unpack_int16(frb_read(buf, 2))
+ *         uint16_t sign = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ *         uint16_t dscale = <uint16_t>hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ *         int16_t pgdigit0
+ *         ssize_t i
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(6, 137, __pyx_L1_error)
+  __pyx_v_dscale = ((uint16_t)unpack_int16(__pyx_t_1));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":147
+ *         int64_t abs_exponent
+ *         ssize_t exponent_chars
+ *         ssize_t front_padding = 0             # <<<<<<<<<<<<<<
+ *         ssize_t trailing_padding = 0
+ *         ssize_t num_fract_digits
+ */
+  __pyx_v_front_padding = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":148
+ *         ssize_t exponent_chars
+ *         ssize_t front_padding = 0
+ *         ssize_t trailing_padding = 0             # <<<<<<<<<<<<<<
+ *         ssize_t num_fract_digits
+ *         ssize_t dscale_left
+ */
+  __pyx_v_trailing_padding = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":154
+ *         char *charbuf
+ *         char *bufptr
+ *         bint buf_allocated = False             # <<<<<<<<<<<<<<
+ * 
+ *     if sign == NUMERIC_NAN:
+ */
+  __pyx_v_buf_allocated = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":156
+ *         bint buf_allocated = False
+ * 
+ *     if sign == NUMERIC_NAN:             # <<<<<<<<<<<<<<
+ *         # Not-a-number
+ *         return _Dec('NaN')
+ */
+  __pyx_t_2 = ((__pyx_v_sign == 0xC000) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":158
+ *     if sign == NUMERIC_NAN:
+ *         # Not-a-number
+ *         return _Dec('NaN')             # <<<<<<<<<<<<<<
+ * 
+ *     if num_pgdigits == 0:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_Dec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 158, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_n_u_NaN) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u_NaN);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 158, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":156
+ *         bint buf_allocated = False
+ * 
+ *     if sign == NUMERIC_NAN:             # <<<<<<<<<<<<<<
+ *         # Not-a-number
+ *         return _Dec('NaN')
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":160
+ *         return _Dec('NaN')
+ * 
+ *     if num_pgdigits == 0:             # <<<<<<<<<<<<<<
+ *         # Zero
+ *         return _Dec('0e-' + str(dscale))
+ */
+  __pyx_t_2 = ((__pyx_v_num_pgdigits == 0) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":162
+ *     if num_pgdigits == 0:
+ *         # Zero
+ *         return _Dec('0e-' + str(dscale))             # <<<<<<<<<<<<<<
+ * 
+ *     pgdigit0 = hton.unpack_int16(frb_read(buf, 2))
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_Dec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 162, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyInt_From_uint16_t(__pyx_v_dscale); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 162, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 162, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = __Pyx_PyUnicode_Concat(__pyx_kp_u_0e, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 162, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 162, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":160
+ *         return _Dec('NaN')
+ * 
+ *     if num_pgdigits == 0:             # <<<<<<<<<<<<<<
+ *         # Zero
+ *         return _Dec('0e-' + str(dscale))
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":164
+ *         return _Dec('0e-' + str(dscale))
+ * 
+ *     pgdigit0 = hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ *     if weight >= 0:
+ *         if pgdigit0 < 10:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(6, 164, __pyx_L1_error)
+  __pyx_v_pgdigit0 = unpack_int16(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":165
+ * 
+ *     pgdigit0 = hton.unpack_int16(frb_read(buf, 2))
+ *     if weight >= 0:             # <<<<<<<<<<<<<<
+ *         if pgdigit0 < 10:
+ *             front_padding = 3
+ */
+  __pyx_t_2 = ((__pyx_v_weight >= 0) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":166
+ *     pgdigit0 = hton.unpack_int16(frb_read(buf, 2))
+ *     if weight >= 0:
+ *         if pgdigit0 < 10:             # <<<<<<<<<<<<<<
+ *             front_padding = 3
+ *         elif pgdigit0 < 100:
+ */
+    __pyx_t_2 = ((__pyx_v_pgdigit0 < 10) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":167
+ *     if weight >= 0:
+ *         if pgdigit0 < 10:
+ *             front_padding = 3             # <<<<<<<<<<<<<<
+ *         elif pgdigit0 < 100:
+ *             front_padding = 2
+ */
+      __pyx_v_front_padding = 3;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":166
+ *     pgdigit0 = hton.unpack_int16(frb_read(buf, 2))
+ *     if weight >= 0:
+ *         if pgdigit0 < 10:             # <<<<<<<<<<<<<<
+ *             front_padding = 3
+ *         elif pgdigit0 < 100:
+ */
+      goto __pyx_L6;
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":168
+ *         if pgdigit0 < 10:
+ *             front_padding = 3
+ *         elif pgdigit0 < 100:             # <<<<<<<<<<<<<<
+ *             front_padding = 2
+ *         elif pgdigit0 < 1000:
+ */
+    __pyx_t_2 = ((__pyx_v_pgdigit0 < 0x64) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":169
+ *             front_padding = 3
+ *         elif pgdigit0 < 100:
+ *             front_padding = 2             # <<<<<<<<<<<<<<
+ *         elif pgdigit0 < 1000:
+ *             front_padding = 1
+ */
+      __pyx_v_front_padding = 2;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":168
+ *         if pgdigit0 < 10:
+ *             front_padding = 3
+ *         elif pgdigit0 < 100:             # <<<<<<<<<<<<<<
+ *             front_padding = 2
+ *         elif pgdigit0 < 1000:
+ */
+      goto __pyx_L6;
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":170
+ *         elif pgdigit0 < 100:
+ *             front_padding = 2
+ *         elif pgdigit0 < 1000:             # <<<<<<<<<<<<<<
+ *             front_padding = 1
+ * 
+ */
+    __pyx_t_2 = ((__pyx_v_pgdigit0 < 0x3E8) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":171
+ *             front_padding = 2
+ *         elif pgdigit0 < 1000:
+ *             front_padding = 1             # <<<<<<<<<<<<<<
+ * 
+ *     # Maximum possible number of decimal digits in base 10.
+ */
+      __pyx_v_front_padding = 1;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":170
+ *         elif pgdigit0 < 100:
+ *             front_padding = 2
+ *         elif pgdigit0 < 1000:             # <<<<<<<<<<<<<<
+ *             front_padding = 1
+ * 
+ */
+    }
+    __pyx_L6:;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":165
+ * 
+ *     pgdigit0 = hton.unpack_int16(frb_read(buf, 2))
+ *     if weight >= 0:             # <<<<<<<<<<<<<<
+ *         if pgdigit0 < 10:
+ *             front_padding = 3
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":174
+ * 
+ *     # Maximum possible number of decimal digits in base 10.
+ *     num_pydigits = num_pgdigits * DEC_DIGITS + dscale             # <<<<<<<<<<<<<<
+ *     # Exponent.
+ *     exponent = (weight + 1) * DEC_DIGITS - front_padding
+ */
+  __pyx_v_num_pydigits = ((__pyx_v_num_pgdigits * 4) + __pyx_v_dscale);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":176
+ *     num_pydigits = num_pgdigits * DEC_DIGITS + dscale
+ *     # Exponent.
+ *     exponent = (weight + 1) * DEC_DIGITS - front_padding             # <<<<<<<<<<<<<<
+ *     abs_exponent = abs(exponent)
+ *     # Number of characters required to render absolute exponent value.
+ */
+  __pyx_v_exponent = (((__pyx_v_weight + 1) * 4) - __pyx_v_front_padding);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":177
+ *     # Exponent.
+ *     exponent = (weight + 1) * DEC_DIGITS - front_padding
+ *     abs_exponent = abs(exponent)             # <<<<<<<<<<<<<<
+ *     # Number of characters required to render absolute exponent value.
+ *     exponent_chars = <ssize_t>log10(<double>abs_exponent) + 1
+ */
+  __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_exponent); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 177, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 177, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 177, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_abs_exponent = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":179
+ *     abs_exponent = abs(exponent)
+ *     # Number of characters required to render absolute exponent value.
+ *     exponent_chars = <ssize_t>log10(<double>abs_exponent) + 1             # <<<<<<<<<<<<<<
+ * 
+ *     buf_size = (
+ */
+  __pyx_v_exponent_chars = (((Py_ssize_t)log10(((double)__pyx_v_abs_exponent))) + 1);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":187
+ *         num_pydigits +      # digits
+ *         2 +                 # exponent indicator (E-,E+)
+ *         exponent_chars +    # exponent             # <<<<<<<<<<<<<<
+ *         1                   # null terminator char
+ *     )
+ */
+  __pyx_v_buf_size = ((((3 + __pyx_v_num_pydigits) + 2) + __pyx_v_exponent_chars) + 1);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":191
+ *     )
+ * 
+ *     if buf_size > _NUMERIC_DECODER_SMALLBUF_SIZE:             # <<<<<<<<<<<<<<
+ *         charbuf = <char *>cpython.PyMem_Malloc(<size_t>buf_size)
+ *         buf_allocated = True
+ */
+  __pyx_t_2 = ((__pyx_v_buf_size > 0x100) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":192
+ * 
+ *     if buf_size > _NUMERIC_DECODER_SMALLBUF_SIZE:
+ *         charbuf = <char *>cpython.PyMem_Malloc(<size_t>buf_size)             # <<<<<<<<<<<<<<
+ *         buf_allocated = True
+ *     else:
+ */
+    __pyx_v_charbuf = ((char *)PyMem_Malloc(((size_t)__pyx_v_buf_size)));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":193
+ *     if buf_size > _NUMERIC_DECODER_SMALLBUF_SIZE:
+ *         charbuf = <char *>cpython.PyMem_Malloc(<size_t>buf_size)
+ *         buf_allocated = True             # <<<<<<<<<<<<<<
+ *     else:
+ *         charbuf = smallbuf
+ */
+    __pyx_v_buf_allocated = 1;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":191
+ *     )
+ * 
+ *     if buf_size > _NUMERIC_DECODER_SMALLBUF_SIZE:             # <<<<<<<<<<<<<<
+ *         charbuf = <char *>cpython.PyMem_Malloc(<size_t>buf_size)
+ *         buf_allocated = True
+ */
+    goto __pyx_L7;
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":195
+ *         buf_allocated = True
+ *     else:
+ *         charbuf = smallbuf             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+  /*else*/ {
+    __pyx_v_charbuf = __pyx_v_smallbuf;
+  }
+  __pyx_L7:;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":197
+ *         charbuf = smallbuf
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         bufptr = charbuf
+ * 
+ */
+  /*try:*/ {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":198
+ * 
+ *     try:
+ *         bufptr = charbuf             # <<<<<<<<<<<<<<
+ * 
+ *         if sign == NUMERIC_NEG:
+ */
+    __pyx_v_bufptr = __pyx_v_charbuf;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":200
+ *         bufptr = charbuf
+ * 
+ *         if sign == NUMERIC_NEG:             # <<<<<<<<<<<<<<
+ *             bufptr[0] = b'-'
+ *             bufptr += 1
+ */
+    __pyx_t_2 = ((__pyx_v_sign == 0x4000) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":201
+ * 
+ *         if sign == NUMERIC_NEG:
+ *             bufptr[0] = b'-'             # <<<<<<<<<<<<<<
+ *             bufptr += 1
+ * 
+ */
+      (__pyx_v_bufptr[0]) = '-';
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":202
+ *         if sign == NUMERIC_NEG:
+ *             bufptr[0] = b'-'
+ *             bufptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *         bufptr[0] = b'0'
+ */
+      __pyx_v_bufptr = (__pyx_v_bufptr + 1);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":200
+ *         bufptr = charbuf
+ * 
+ *         if sign == NUMERIC_NEG:             # <<<<<<<<<<<<<<
+ *             bufptr[0] = b'-'
+ *             bufptr += 1
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":204
+ *             bufptr += 1
+ * 
+ *         bufptr[0] = b'0'             # <<<<<<<<<<<<<<
+ *         bufptr[1] = b'.'
+ *         bufptr += 2
+ */
+    (__pyx_v_bufptr[0]) = '0';
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":205
+ * 
+ *         bufptr[0] = b'0'
+ *         bufptr[1] = b'.'             # <<<<<<<<<<<<<<
+ *         bufptr += 2
+ * 
+ */
+    (__pyx_v_bufptr[1]) = '.';
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":206
+ *         bufptr[0] = b'0'
+ *         bufptr[1] = b'.'
+ *         bufptr += 2             # <<<<<<<<<<<<<<
+ * 
+ *         if weight >= 0:
+ */
+    __pyx_v_bufptr = (__pyx_v_bufptr + 2);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":208
+ *         bufptr += 2
+ * 
+ *         if weight >= 0:             # <<<<<<<<<<<<<<
+ *             bufptr = _unpack_digit_stripping_lzeros(bufptr, pgdigit0)
+ *         else:
+ */
+    __pyx_t_2 = ((__pyx_v_weight >= 0) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":209
+ * 
+ *         if weight >= 0:
+ *             bufptr = _unpack_digit_stripping_lzeros(bufptr, pgdigit0)             # <<<<<<<<<<<<<<
+ *         else:
+ *             bufptr = _unpack_digit(bufptr, pgdigit0)
+ */
+      __pyx_v_bufptr = __pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit_stripping_lzeros(__pyx_v_bufptr, __pyx_v_pgdigit0);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":208
+ *         bufptr += 2
+ * 
+ *         if weight >= 0:             # <<<<<<<<<<<<<<
+ *             bufptr = _unpack_digit_stripping_lzeros(bufptr, pgdigit0)
+ *         else:
+ */
+      goto __pyx_L12;
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":211
+ *             bufptr = _unpack_digit_stripping_lzeros(bufptr, pgdigit0)
+ *         else:
+ *             bufptr = _unpack_digit(bufptr, pgdigit0)             # <<<<<<<<<<<<<<
+ * 
+ *         for i in range(1, num_pgdigits):
+ */
+    /*else*/ {
+      __pyx_v_bufptr = __pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit(__pyx_v_bufptr, __pyx_v_pgdigit0);
+    }
+    __pyx_L12:;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":213
+ *             bufptr = _unpack_digit(bufptr, pgdigit0)
+ * 
+ *         for i in range(1, num_pgdigits):             # <<<<<<<<<<<<<<
+ *             pgdigit = hton.unpack_int16(frb_read(buf, 2))
+ *             bufptr = _unpack_digit(bufptr, pgdigit)
+ */
+    __pyx_t_8 = __pyx_v_num_pgdigits;
+    __pyx_t_9 = __pyx_t_8;
+    for (__pyx_t_10 = 1; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
+      __pyx_v_i = __pyx_t_10;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":214
+ * 
+ *         for i in range(1, num_pgdigits):
+ *             pgdigit = hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ *             bufptr = _unpack_digit(bufptr, pgdigit)
+ * 
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(6, 214, __pyx_L9_error)
+      __pyx_v_pgdigit = unpack_int16(__pyx_t_1);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":215
+ *         for i in range(1, num_pgdigits):
+ *             pgdigit = hton.unpack_int16(frb_read(buf, 2))
+ *             bufptr = _unpack_digit(bufptr, pgdigit)             # <<<<<<<<<<<<<<
+ * 
+ *         if dscale:
+ */
+      __pyx_v_bufptr = __pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit(__pyx_v_bufptr, __pyx_v_pgdigit);
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":217
+ *             bufptr = _unpack_digit(bufptr, pgdigit)
+ * 
+ *         if dscale:             # <<<<<<<<<<<<<<
+ *             if weight >= 0:
+ *                 num_fract_digits = num_pgdigits - weight - 1
+ */
+    __pyx_t_2 = (__pyx_v_dscale != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":218
+ * 
+ *         if dscale:
+ *             if weight >= 0:             # <<<<<<<<<<<<<<
+ *                 num_fract_digits = num_pgdigits - weight - 1
+ *             else:
+ */
+      __pyx_t_2 = ((__pyx_v_weight >= 0) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":219
+ *         if dscale:
+ *             if weight >= 0:
+ *                 num_fract_digits = num_pgdigits - weight - 1             # <<<<<<<<<<<<<<
+ *             else:
+ *                 num_fract_digits = num_pgdigits
+ */
+        __pyx_v_num_fract_digits = ((__pyx_v_num_pgdigits - __pyx_v_weight) - 1);
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":218
+ * 
+ *         if dscale:
+ *             if weight >= 0:             # <<<<<<<<<<<<<<
+ *                 num_fract_digits = num_pgdigits - weight - 1
+ *             else:
+ */
+        goto __pyx_L16;
+      }
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":221
+ *                 num_fract_digits = num_pgdigits - weight - 1
+ *             else:
+ *                 num_fract_digits = num_pgdigits             # <<<<<<<<<<<<<<
+ * 
+ *             # Check how much dscale is left to render (trailing zeros).
+ */
+      /*else*/ {
+        __pyx_v_num_fract_digits = __pyx_v_num_pgdigits;
+      }
+      __pyx_L16:;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":224
+ * 
+ *             # Check how much dscale is left to render (trailing zeros).
+ *             dscale_left = dscale - num_fract_digits * DEC_DIGITS             # <<<<<<<<<<<<<<
+ *             if dscale_left > 0:
+ *                 for i in range(dscale_left):
+ */
+      __pyx_v_dscale_left = (__pyx_v_dscale - (__pyx_v_num_fract_digits * 4));
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":225
+ *             # Check how much dscale is left to render (trailing zeros).
+ *             dscale_left = dscale - num_fract_digits * DEC_DIGITS
+ *             if dscale_left > 0:             # <<<<<<<<<<<<<<
+ *                 for i in range(dscale_left):
+ *                     bufptr[i] = <char>b'0'
+ */
+      __pyx_t_2 = ((__pyx_v_dscale_left > 0) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":226
+ *             dscale_left = dscale - num_fract_digits * DEC_DIGITS
+ *             if dscale_left > 0:
+ *                 for i in range(dscale_left):             # <<<<<<<<<<<<<<
+ *                     bufptr[i] = <char>b'0'
+ * 
+ */
+        __pyx_t_10 = __pyx_v_dscale_left;
+        __pyx_t_11 = __pyx_t_10;
+        for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
+          __pyx_v_i = __pyx_t_12;
+
+          /* "asyncpg/pgproto/codecs/numeric.pyx":227
+ *             if dscale_left > 0:
+ *                 for i in range(dscale_left):
+ *                     bufptr[i] = <char>b'0'             # <<<<<<<<<<<<<<
+ * 
+ *             # If display scale is _less_ than the number of rendered digits,
+ */
+          (__pyx_v_bufptr[__pyx_v_i]) = ((char)'0');
+        }
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":225
+ *             # Check how much dscale is left to render (trailing zeros).
+ *             dscale_left = dscale - num_fract_digits * DEC_DIGITS
+ *             if dscale_left > 0:             # <<<<<<<<<<<<<<
+ *                 for i in range(dscale_left):
+ *                     bufptr[i] = <char>b'0'
+ */
+      }
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":232
+ *             # dscale_left will be negative and this will strip the excess
+ *             # trailing zeros.
+ *             bufptr += dscale_left             # <<<<<<<<<<<<<<
+ * 
+ *         if exponent != 0:
+ */
+      __pyx_v_bufptr = (__pyx_v_bufptr + __pyx_v_dscale_left);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":217
+ *             bufptr = _unpack_digit(bufptr, pgdigit)
+ * 
+ *         if dscale:             # <<<<<<<<<<<<<<
+ *             if weight >= 0:
+ *                 num_fract_digits = num_pgdigits - weight - 1
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":234
+ *             bufptr += dscale_left
+ * 
+ *         if exponent != 0:             # <<<<<<<<<<<<<<
+ *             bufptr[0] = b'E'
+ *             if exponent < 0:
+ */
+    __pyx_t_2 = ((__pyx_v_exponent != 0) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":235
+ * 
+ *         if exponent != 0:
+ *             bufptr[0] = b'E'             # <<<<<<<<<<<<<<
+ *             if exponent < 0:
+ *                 bufptr[1] = b'-'
+ */
+      (__pyx_v_bufptr[0]) = 'E';
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":236
+ *         if exponent != 0:
+ *             bufptr[0] = b'E'
+ *             if exponent < 0:             # <<<<<<<<<<<<<<
+ *                 bufptr[1] = b'-'
+ *             else:
+ */
+      __pyx_t_2 = ((__pyx_v_exponent < 0) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":237
+ *             bufptr[0] = b'E'
+ *             if exponent < 0:
+ *                 bufptr[1] = b'-'             # <<<<<<<<<<<<<<
+ *             else:
+ *                 bufptr[1] = b'+'
+ */
+        (__pyx_v_bufptr[1]) = '-';
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":236
+ *         if exponent != 0:
+ *             bufptr[0] = b'E'
+ *             if exponent < 0:             # <<<<<<<<<<<<<<
+ *                 bufptr[1] = b'-'
+ *             else:
+ */
+        goto __pyx_L21;
+      }
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":239
+ *                 bufptr[1] = b'-'
+ *             else:
+ *                 bufptr[1] = b'+'             # <<<<<<<<<<<<<<
+ *             bufptr += 2
+ *             snprintf(bufptr, <size_t>exponent_chars + 1, '%d',
+ */
+      /*else*/ {
+        (__pyx_v_bufptr[1]) = '+';
+      }
+      __pyx_L21:;
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":240
+ *             else:
+ *                 bufptr[1] = b'+'
+ *             bufptr += 2             # <<<<<<<<<<<<<<
+ *             snprintf(bufptr, <size_t>exponent_chars + 1, '%d',
+ *                      <int>abs_exponent)
+ */
+      __pyx_v_bufptr = (__pyx_v_bufptr + 2);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":241
+ *                 bufptr[1] = b'+'
+ *             bufptr += 2
+ *             snprintf(bufptr, <size_t>exponent_chars + 1, '%d',             # <<<<<<<<<<<<<<
+ *                      <int>abs_exponent)
+ *             bufptr += exponent_chars
+ */
+      (void)(snprintf(__pyx_v_bufptr, (((size_t)__pyx_v_exponent_chars) + 1), ((char const *)"%d"), ((int)__pyx_v_abs_exponent)));
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":243
+ *             snprintf(bufptr, <size_t>exponent_chars + 1, '%d',
+ *                      <int>abs_exponent)
+ *             bufptr += exponent_chars             # <<<<<<<<<<<<<<
+ * 
+ *         bufptr[0] = 0
+ */
+      __pyx_v_bufptr = (__pyx_v_bufptr + __pyx_v_exponent_chars);
+
+      /* "asyncpg/pgproto/codecs/numeric.pyx":234
+ *             bufptr += dscale_left
+ * 
+ *         if exponent != 0:             # <<<<<<<<<<<<<<
+ *             bufptr[0] = b'E'
+ *             if exponent < 0:
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":245
+ *             bufptr += exponent_chars
+ * 
+ *         bufptr[0] = 0             # <<<<<<<<<<<<<<
+ * 
+ *         pydigits = cpythonx.PyUnicode_FromString(charbuf)
+ */
+    (__pyx_v_bufptr[0]) = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":247
+ *         bufptr[0] = 0
+ * 
+ *         pydigits = cpythonx.PyUnicode_FromString(charbuf)             # <<<<<<<<<<<<<<
+ * 
+ *         return _Dec(pydigits)
+ */
+    __pyx_t_4 = PyUnicode_FromString(__pyx_v_charbuf); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 247, __pyx_L9_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_v_pydigits = __pyx_t_4;
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":249
+ *         pydigits = cpythonx.PyUnicode_FromString(charbuf)
+ * 
+ *         return _Dec(pydigits)             # <<<<<<<<<<<<<<
+ * 
+ *     finally:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_Dec); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 249, __pyx_L9_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_pydigits) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_pydigits);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 249, __pyx_L9_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    goto __pyx_L8_return;
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":252
+ * 
+ *     finally:
+ *         if buf_allocated:             # <<<<<<<<<<<<<<
+ *             cpython.PyMem_Free(charbuf)
+ * 
+ */
+  /*finally:*/ {
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18) < 0)) __Pyx_ErrFetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
+      __Pyx_XGOTREF(__pyx_t_16);
+      __Pyx_XGOTREF(__pyx_t_17);
+      __Pyx_XGOTREF(__pyx_t_18);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_21);
+      __pyx_t_13 = __pyx_lineno; __pyx_t_14 = __pyx_clineno; __pyx_t_15 = __pyx_filename;
+      {
+        __pyx_t_2 = (__pyx_v_buf_allocated != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/pgproto/codecs/numeric.pyx":253
+ *     finally:
+ *         if buf_allocated:
+ *             cpython.PyMem_Free(charbuf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+          PyMem_Free(__pyx_v_charbuf);
+
+          /* "asyncpg/pgproto/codecs/numeric.pyx":252
+ * 
+ *     finally:
+ *         if buf_allocated:             # <<<<<<<<<<<<<<
+ *             cpython.PyMem_Free(charbuf)
+ * 
+ */
+        }
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_21);
+        __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21);
+      }
+      __Pyx_XGIVEREF(__pyx_t_16);
+      __Pyx_XGIVEREF(__pyx_t_17);
+      __Pyx_XGIVEREF(__pyx_t_18);
+      __Pyx_ErrRestore(__pyx_t_16, __pyx_t_17, __pyx_t_18);
+      __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0;
+      __pyx_lineno = __pyx_t_13; __pyx_clineno = __pyx_t_14; __pyx_filename = __pyx_t_15;
+      goto __pyx_L1_error;
+    }
+    __pyx_L8_return: {
+      __pyx_t_21 = __pyx_r;
+      __pyx_r = 0;
+      __pyx_t_2 = (__pyx_v_buf_allocated != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":253
+ *     finally:
+ *         if buf_allocated:
+ *             cpython.PyMem_Free(charbuf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+        PyMem_Free(__pyx_v_charbuf);
+
+        /* "asyncpg/pgproto/codecs/numeric.pyx":252
+ * 
+ *     finally:
+ *         if buf_allocated:             # <<<<<<<<<<<<<<
+ *             cpython.PyMem_Free(charbuf)
+ * 
+ */
+      }
+      __pyx_r = __pyx_t_21;
+      __pyx_t_21 = 0;
+      goto __pyx_L0;
+    }
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":132
+ * # than the simple text decoder above.  That said, we need the binary
+ * # decoder to support binary COPY with numeric values.
+ * cdef numeric_decode_binary(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint16_t num_pgdigits = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.numeric_decode_binary", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_pydigits);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/numeric.pyx":256
+ * 
+ * 
+ * cdef inline char *_unpack_digit_stripping_lzeros(char *buf, int64_t pgdigit):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t d
+ */
+
+static CYTHON_INLINE char *__pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit_stripping_lzeros(char *__pyx_v_buf, int64_t __pyx_v_pgdigit) {
+  int64_t __pyx_v_d;
+  int __pyx_v_significant;
+  char *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("_unpack_digit_stripping_lzeros", 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":261
+ *         bint significant
+ * 
+ *     d = pgdigit // 1000             # <<<<<<<<<<<<<<
+ *     significant = (d > 0)
+ *     if significant:
+ */
+  __pyx_v_d = __Pyx_div_int64_t(__pyx_v_pgdigit, 0x3E8);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":262
+ * 
+ *     d = pgdigit // 1000
+ *     significant = (d > 0)             # <<<<<<<<<<<<<<
+ *     if significant:
+ *         pgdigit -= d * 1000
+ */
+  __pyx_v_significant = (__pyx_v_d > 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":263
+ *     d = pgdigit // 1000
+ *     significant = (d > 0)
+ *     if significant:             # <<<<<<<<<<<<<<
+ *         pgdigit -= d * 1000
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ */
+  __pyx_t_1 = (__pyx_v_significant != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":264
+ *     significant = (d > 0)
+ *     if significant:
+ *         pgdigit -= d * 1000             # <<<<<<<<<<<<<<
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ *         buf += 1
+ */
+    __pyx_v_pgdigit = (__pyx_v_pgdigit - (__pyx_v_d * 0x3E8));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":265
+ *     if significant:
+ *         pgdigit -= d * 1000
+ *         buf[0] = <char>(d + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ *         buf += 1
+ * 
+ */
+    (__pyx_v_buf[0]) = ((char)(__pyx_v_d + ((int32_t)'0')));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":266
+ *         pgdigit -= d * 1000
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ *         buf += 1             # <<<<<<<<<<<<<<
+ * 
+ *     d = pgdigit // 100
+ */
+    __pyx_v_buf = (__pyx_v_buf + 1);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":263
+ *     d = pgdigit // 1000
+ *     significant = (d > 0)
+ *     if significant:             # <<<<<<<<<<<<<<
+ *         pgdigit -= d * 1000
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":268
+ *         buf += 1
+ * 
+ *     d = pgdigit // 100             # <<<<<<<<<<<<<<
+ *     significant |= (d > 0)
+ *     if significant:
+ */
+  __pyx_v_d = __Pyx_div_int64_t(__pyx_v_pgdigit, 0x64);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":269
+ * 
+ *     d = pgdigit // 100
+ *     significant |= (d > 0)             # <<<<<<<<<<<<<<
+ *     if significant:
+ *         pgdigit -= d * 100
+ */
+  __pyx_v_significant = (__pyx_v_significant | (__pyx_v_d > 0));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":270
+ *     d = pgdigit // 100
+ *     significant |= (d > 0)
+ *     if significant:             # <<<<<<<<<<<<<<
+ *         pgdigit -= d * 100
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ */
+  __pyx_t_1 = (__pyx_v_significant != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":271
+ *     significant |= (d > 0)
+ *     if significant:
+ *         pgdigit -= d * 100             # <<<<<<<<<<<<<<
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ *         buf += 1
+ */
+    __pyx_v_pgdigit = (__pyx_v_pgdigit - (__pyx_v_d * 0x64));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":272
+ *     if significant:
+ *         pgdigit -= d * 100
+ *         buf[0] = <char>(d + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ *         buf += 1
+ * 
+ */
+    (__pyx_v_buf[0]) = ((char)(__pyx_v_d + ((int32_t)'0')));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":273
+ *         pgdigit -= d * 100
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ *         buf += 1             # <<<<<<<<<<<<<<
+ * 
+ *     d = pgdigit // 10
+ */
+    __pyx_v_buf = (__pyx_v_buf + 1);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":270
+ *     d = pgdigit // 100
+ *     significant |= (d > 0)
+ *     if significant:             # <<<<<<<<<<<<<<
+ *         pgdigit -= d * 100
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":275
+ *         buf += 1
+ * 
+ *     d = pgdigit // 10             # <<<<<<<<<<<<<<
+ *     significant |= (d > 0)
+ *     if significant:
+ */
+  __pyx_v_d = __Pyx_div_int64_t(__pyx_v_pgdigit, 10);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":276
+ * 
+ *     d = pgdigit // 10
+ *     significant |= (d > 0)             # <<<<<<<<<<<<<<
+ *     if significant:
+ *         pgdigit -= d * 10
+ */
+  __pyx_v_significant = (__pyx_v_significant | (__pyx_v_d > 0));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":277
+ *     d = pgdigit // 10
+ *     significant |= (d > 0)
+ *     if significant:             # <<<<<<<<<<<<<<
+ *         pgdigit -= d * 10
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ */
+  __pyx_t_1 = (__pyx_v_significant != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":278
+ *     significant |= (d > 0)
+ *     if significant:
+ *         pgdigit -= d * 10             # <<<<<<<<<<<<<<
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ *         buf += 1
+ */
+    __pyx_v_pgdigit = (__pyx_v_pgdigit - (__pyx_v_d * 10));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":279
+ *     if significant:
+ *         pgdigit -= d * 10
+ *         buf[0] = <char>(d + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ *         buf += 1
+ * 
+ */
+    (__pyx_v_buf[0]) = ((char)(__pyx_v_d + ((int32_t)'0')));
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":280
+ *         pgdigit -= d * 10
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ *         buf += 1             # <<<<<<<<<<<<<<
+ * 
+ *     buf[0] = <char>(pgdigit + <int32_t>b'0')
+ */
+    __pyx_v_buf = (__pyx_v_buf + 1);
+
+    /* "asyncpg/pgproto/codecs/numeric.pyx":277
+ *     d = pgdigit // 10
+ *     significant |= (d > 0)
+ *     if significant:             # <<<<<<<<<<<<<<
+ *         pgdigit -= d * 10
+ *         buf[0] = <char>(d + <int32_t>b'0')
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":282
+ *         buf += 1
+ * 
+ *     buf[0] = <char>(pgdigit + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ *     buf += 1
+ * 
+ */
+  (__pyx_v_buf[0]) = ((char)(__pyx_v_pgdigit + ((int32_t)'0')));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":283
+ * 
+ *     buf[0] = <char>(pgdigit + <int32_t>b'0')
+ *     buf += 1             # <<<<<<<<<<<<<<
+ * 
+ *     return buf
+ */
+  __pyx_v_buf = (__pyx_v_buf + 1);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":285
+ *     buf += 1
+ * 
+ *     return buf             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":256
+ * 
+ * 
+ * cdef inline char *_unpack_digit_stripping_lzeros(char *buf, int64_t pgdigit):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t d
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/numeric.pyx":288
+ * 
+ * 
+ * cdef inline char *_unpack_digit(char *buf, int64_t pgdigit):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t d
+ */
+
+static CYTHON_INLINE char *__pyx_f_7asyncpg_7pgproto_7pgproto__unpack_digit(char *__pyx_v_buf, int64_t __pyx_v_pgdigit) {
+  int64_t __pyx_v_d;
+  char *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_unpack_digit", 0);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":292
+ *         int64_t d
+ * 
+ *     d = pgdigit // 1000             # <<<<<<<<<<<<<<
+ *     pgdigit -= d * 1000
+ *     buf[0] = <char>(d + <int32_t>b'0')
+ */
+  __pyx_v_d = __Pyx_div_int64_t(__pyx_v_pgdigit, 0x3E8);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":293
+ * 
+ *     d = pgdigit // 1000
+ *     pgdigit -= d * 1000             # <<<<<<<<<<<<<<
+ *     buf[0] = <char>(d + <int32_t>b'0')
+ * 
+ */
+  __pyx_v_pgdigit = (__pyx_v_pgdigit - (__pyx_v_d * 0x3E8));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":294
+ *     d = pgdigit // 1000
+ *     pgdigit -= d * 1000
+ *     buf[0] = <char>(d + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ * 
+ *     d = pgdigit // 100
+ */
+  (__pyx_v_buf[0]) = ((char)(__pyx_v_d + ((int32_t)'0')));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":296
+ *     buf[0] = <char>(d + <int32_t>b'0')
+ * 
+ *     d = pgdigit // 100             # <<<<<<<<<<<<<<
+ *     pgdigit -= d * 100
+ *     buf[1] = <char>(d + <int32_t>b'0')
+ */
+  __pyx_v_d = __Pyx_div_int64_t(__pyx_v_pgdigit, 0x64);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":297
+ * 
+ *     d = pgdigit // 100
+ *     pgdigit -= d * 100             # <<<<<<<<<<<<<<
+ *     buf[1] = <char>(d + <int32_t>b'0')
+ * 
+ */
+  __pyx_v_pgdigit = (__pyx_v_pgdigit - (__pyx_v_d * 0x64));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":298
+ *     d = pgdigit // 100
+ *     pgdigit -= d * 100
+ *     buf[1] = <char>(d + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ * 
+ *     d = pgdigit // 10
+ */
+  (__pyx_v_buf[1]) = ((char)(__pyx_v_d + ((int32_t)'0')));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":300
+ *     buf[1] = <char>(d + <int32_t>b'0')
+ * 
+ *     d = pgdigit // 10             # <<<<<<<<<<<<<<
+ *     pgdigit -= d * 10
+ *     buf[2] = <char>(d + <int32_t>b'0')
+ */
+  __pyx_v_d = __Pyx_div_int64_t(__pyx_v_pgdigit, 10);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":301
+ * 
+ *     d = pgdigit // 10
+ *     pgdigit -= d * 10             # <<<<<<<<<<<<<<
+ *     buf[2] = <char>(d + <int32_t>b'0')
+ * 
+ */
+  __pyx_v_pgdigit = (__pyx_v_pgdigit - (__pyx_v_d * 10));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":302
+ *     d = pgdigit // 10
+ *     pgdigit -= d * 10
+ *     buf[2] = <char>(d + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ * 
+ *     buf[3] = <char>(pgdigit + <int32_t>b'0')
+ */
+  (__pyx_v_buf[2]) = ((char)(__pyx_v_d + ((int32_t)'0')));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":304
+ *     buf[2] = <char>(d + <int32_t>b'0')
+ * 
+ *     buf[3] = <char>(pgdigit + <int32_t>b'0')             # <<<<<<<<<<<<<<
+ *     buf += 4
+ * 
+ */
+  (__pyx_v_buf[3]) = ((char)(__pyx_v_pgdigit + ((int32_t)'0')));
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":305
+ * 
+ *     buf[3] = <char>(pgdigit + <int32_t>b'0')
+ *     buf += 4             # <<<<<<<<<<<<<<
+ * 
+ *     return buf
+ */
+  __pyx_v_buf = (__pyx_v_buf + 4);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":307
+ *     buf += 4
+ * 
+ *     return buf             # <<<<<<<<<<<<<<
+ */
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":288
+ * 
+ * 
+ * cdef inline char *_unpack_digit(char *buf, int64_t pgdigit):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t d
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/bits.pyx":8
+ * 
+ * 
+ * cdef bits_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         Py_buffer pybuf
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bits_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  Py_buffer __pyx_v_pybuf;
+  int __pyx_v_pybuf_used;
+  char *__pyx_v_buf;
+  Py_ssize_t __pyx_v_len;
+  Py_ssize_t __pyx_v_bitlen;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  Py_ssize_t __pyx_t_7;
+  Py_ssize_t __pyx_t_8;
+  int __pyx_t_9;
+  char const *__pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  __Pyx_RefNannySetupContext("bits_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":11
+ *     cdef:
+ *         Py_buffer pybuf
+ *         bint pybuf_used = False             # <<<<<<<<<<<<<<
+ *         char *buf
+ *         ssize_t len
+ */
+  __pyx_v_pybuf_used = 0;
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":16
+ *         ssize_t bitlen
+ * 
+ *     if cpython.PyBytes_CheckExact(obj):             # <<<<<<<<<<<<<<
+ *         buf = cpython.PyBytes_AS_STRING(obj)
+ *         len = cpython.Py_SIZE(obj)
+ */
+  __pyx_t_1 = (PyBytes_CheckExact(__pyx_v_obj) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":17
+ * 
+ *     if cpython.PyBytes_CheckExact(obj):
+ *         buf = cpython.PyBytes_AS_STRING(obj)             # <<<<<<<<<<<<<<
+ *         len = cpython.Py_SIZE(obj)
+ *         bitlen = len * 8
+ */
+    __pyx_v_buf = PyBytes_AS_STRING(__pyx_v_obj);
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":18
+ *     if cpython.PyBytes_CheckExact(obj):
+ *         buf = cpython.PyBytes_AS_STRING(obj)
+ *         len = cpython.Py_SIZE(obj)             # <<<<<<<<<<<<<<
+ *         bitlen = len * 8
+ *     elif isinstance(obj, pgproto_types.BitString):
+ */
+    __pyx_v_len = Py_SIZE(__pyx_v_obj);
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":19
+ *         buf = cpython.PyBytes_AS_STRING(obj)
+ *         len = cpython.Py_SIZE(obj)
+ *         bitlen = len * 8             # <<<<<<<<<<<<<<
+ *     elif isinstance(obj, pgproto_types.BitString):
+ *         cpython.PyBytes_AsStringAndSize(obj.bytes, &buf, &len)
+ */
+    __pyx_v_bitlen = (__pyx_v_len * 8);
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":16
+ *         ssize_t bitlen
+ * 
+ *     if cpython.PyBytes_CheckExact(obj):             # <<<<<<<<<<<<<<
+ *         buf = cpython.PyBytes_AS_STRING(obj)
+ *         len = cpython.Py_SIZE(obj)
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":20
+ *         len = cpython.Py_SIZE(obj)
+ *         bitlen = len * 8
+ *     elif isinstance(obj, pgproto_types.BitString):             # <<<<<<<<<<<<<<
+ *         cpython.PyBytes_AsStringAndSize(obj.bytes, &buf, &len)
+ *         bitlen = obj.__len__()
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_2)) __PYX_ERR(12, 20, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_BitString); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 20, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_1 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_3); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(12, 20, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_4 = (__pyx_t_1 != 0);
+  if (__pyx_t_4) {
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":21
+ *         bitlen = len * 8
+ *     elif isinstance(obj, pgproto_types.BitString):
+ *         cpython.PyBytes_AsStringAndSize(obj.bytes, &buf, &len)             # <<<<<<<<<<<<<<
+ *         bitlen = obj.__len__()
+ *     else:
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_bytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 21, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = PyBytes_AsStringAndSize(__pyx_t_3, (&__pyx_v_buf), ((Py_ssize_t *)(&__pyx_v_len))); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(12, 21, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":22
+ *     elif isinstance(obj, pgproto_types.BitString):
+ *         cpython.PyBytes_AsStringAndSize(obj.bytes, &buf, &len)
+ *         bitlen = obj.__len__()             # <<<<<<<<<<<<<<
+ *     else:
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+ */
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(12, 22, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 22, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_7 = PyInt_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(12, 22, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_v_bitlen = __pyx_t_7;
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":20
+ *         len = cpython.Py_SIZE(obj)
+ *         bitlen = len * 8
+ *     elif isinstance(obj, pgproto_types.BitString):             # <<<<<<<<<<<<<<
+ *         cpython.PyBytes_AsStringAndSize(obj.bytes, &buf, &len)
+ *         bitlen = obj.__len__()
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":24
+ *         bitlen = obj.__len__()
+ *     else:
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)             # <<<<<<<<<<<<<<
+ *         pybuf_used = True
+ *         buf = <char*>pybuf.buf
+ */
+  /*else*/ {
+    __pyx_t_5 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_pybuf), PyBUF_SIMPLE); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(12, 24, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":25
+ *     else:
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+ *         pybuf_used = True             # <<<<<<<<<<<<<<
+ *         buf = <char*>pybuf.buf
+ *         len = pybuf.len
+ */
+    __pyx_v_pybuf_used = 1;
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":26
+ *         cpython.PyObject_GetBuffer(obj, &pybuf, cpython.PyBUF_SIMPLE)
+ *         pybuf_used = True
+ *         buf = <char*>pybuf.buf             # <<<<<<<<<<<<<<
+ *         len = pybuf.len
+ *         bitlen = len * 8
+ */
+    __pyx_v_buf = ((char *)__pyx_v_pybuf.buf);
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":27
+ *         pybuf_used = True
+ *         buf = <char*>pybuf.buf
+ *         len = pybuf.len             # <<<<<<<<<<<<<<
+ *         bitlen = len * 8
+ * 
+ */
+    __pyx_t_8 = __pyx_v_pybuf.len;
+    __pyx_v_len = __pyx_t_8;
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":28
+ *         buf = <char*>pybuf.buf
+ *         len = pybuf.len
+ *         bitlen = len * 8             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+    __pyx_v_bitlen = (__pyx_v_len * 8);
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":30
+ *         bitlen = len * 8
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         if bitlen > _MAXINT32:
+ *             raise ValueError('bit value too long')
+ */
+  /*try:*/ {
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":31
+ * 
+ *     try:
+ *         if bitlen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *             raise ValueError('bit value too long')
+ *         wbuf.write_int32(4 + <int32_t>len)
+ */
+    __pyx_t_4 = ((__pyx_v_bitlen > 0x7FFFFFFF) != 0);
+    if (unlikely(__pyx_t_4)) {
+
+      /* "asyncpg/pgproto/codecs/bits.pyx":32
+ *     try:
+ *         if bitlen > _MAXINT32:
+ *             raise ValueError('bit value too long')             # <<<<<<<<<<<<<<
+ *         wbuf.write_int32(4 + <int32_t>len)
+ *         wbuf.write_int32(<int32_t>bitlen)
+ */
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 32, __pyx_L5_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(12, 32, __pyx_L5_error)
+
+      /* "asyncpg/pgproto/codecs/bits.pyx":31
+ * 
+ *     try:
+ *         if bitlen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *             raise ValueError('bit value too long')
+ *         wbuf.write_int32(4 + <int32_t>len)
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":33
+ *         if bitlen > _MAXINT32:
+ *             raise ValueError('bit value too long')
+ *         wbuf.write_int32(4 + <int32_t>len)             # <<<<<<<<<<<<<<
+ *         wbuf.write_int32(<int32_t>bitlen)
+ *         wbuf.write_cstr(buf, len)
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, (4 + ((int32_t)__pyx_v_len))); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 33, __pyx_L5_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":34
+ *             raise ValueError('bit value too long')
+ *         wbuf.write_int32(4 + <int32_t>len)
+ *         wbuf.write_int32(<int32_t>bitlen)             # <<<<<<<<<<<<<<
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, ((int32_t)__pyx_v_bitlen)); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 34, __pyx_L5_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/bits.pyx":35
+ *         wbuf.write_int32(4 + <int32_t>len)
+ *         wbuf.write_int32(<int32_t>bitlen)
+ *         wbuf.write_cstr(buf, len)             # <<<<<<<<<<<<<<
+ *     finally:
+ *         if pybuf_used:
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_wbuf, __pyx_v_buf, __pyx_v_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 35, __pyx_L5_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  }
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":37
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ *         if pybuf_used:             # <<<<<<<<<<<<<<
+ *             cpython.PyBuffer_Release(&pybuf)
+ * 
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __pyx_t_4 = (__pyx_v_pybuf_used != 0);
+      if (__pyx_t_4) {
+
+        /* "asyncpg/pgproto/codecs/bits.pyx":38
+ *     finally:
+ *         if pybuf_used:
+ *             cpython.PyBuffer_Release(&pybuf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+        PyBuffer_Release((&__pyx_v_pybuf));
+
+        /* "asyncpg/pgproto/codecs/bits.pyx":37
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ *         if pybuf_used:             # <<<<<<<<<<<<<<
+ *             cpython.PyBuffer_Release(&pybuf)
+ * 
+ */
+      }
+      goto __pyx_L6;
+    }
+    __pyx_L5_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13) < 0)) __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
+      __Pyx_XGOTREF(__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_12);
+      __Pyx_XGOTREF(__pyx_t_13);
+      __Pyx_XGOTREF(__pyx_t_14);
+      __Pyx_XGOTREF(__pyx_t_15);
+      __Pyx_XGOTREF(__pyx_t_16);
+      __pyx_t_5 = __pyx_lineno; __pyx_t_9 = __pyx_clineno; __pyx_t_10 = __pyx_filename;
+      {
+        __pyx_t_4 = (__pyx_v_pybuf_used != 0);
+        if (__pyx_t_4) {
+
+          /* "asyncpg/pgproto/codecs/bits.pyx":38
+ *     finally:
+ *         if pybuf_used:
+ *             cpython.PyBuffer_Release(&pybuf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+          PyBuffer_Release((&__pyx_v_pybuf));
+
+          /* "asyncpg/pgproto/codecs/bits.pyx":37
+ *         wbuf.write_cstr(buf, len)
+ *     finally:
+ *         if pybuf_used:             # <<<<<<<<<<<<<<
+ *             cpython.PyBuffer_Release(&pybuf)
+ * 
+ */
+        }
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_14);
+        __Pyx_XGIVEREF(__pyx_t_15);
+        __Pyx_XGIVEREF(__pyx_t_16);
+        __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
+      }
+      __Pyx_XGIVEREF(__pyx_t_11);
+      __Pyx_XGIVEREF(__pyx_t_12);
+      __Pyx_XGIVEREF(__pyx_t_13);
+      __Pyx_ErrRestore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
+      __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0;
+      __pyx_lineno = __pyx_t_5; __pyx_clineno = __pyx_t_9; __pyx_filename = __pyx_t_10;
+      goto __pyx_L1_error;
+    }
+    __pyx_L6:;
+  }
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":8
+ * 
+ * 
+ * cdef bits_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         Py_buffer pybuf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.bits_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/bits.pyx":41
+ * 
+ * 
+ * cdef bits_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t bitlen = hton.unpack_int32(frb_read(buf, 4))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_bits_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_bitlen;
+  Py_ssize_t __pyx_v_buf_len;
+  PyObject *__pyx_v_bytes_ = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("bits_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":43
+ * cdef bits_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int32_t bitlen = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         ssize_t buf_len = buf.len
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(12, 43, __pyx_L1_error)
+  __pyx_v_bitlen = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":44
+ *     cdef:
+ *         int32_t bitlen = hton.unpack_int32(frb_read(buf, 4))
+ *         ssize_t buf_len = buf.len             # <<<<<<<<<<<<<<
+ * 
+ *     bytes_ = cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)
+ */
+  __pyx_t_2 = __pyx_v_buf->len;
+  __pyx_v_buf_len = __pyx_t_2;
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":46
+ *         ssize_t buf_len = buf.len
+ * 
+ *     bytes_ = cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)             # <<<<<<<<<<<<<<
+ *     return pgproto_types.BitString.frombytes(bytes_, bitlen)
+ */
+  __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(__pyx_v_buf), __pyx_v_buf_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 46, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_v_bytes_ = ((PyObject*)__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":47
+ * 
+ *     bytes_ = cpython.PyBytes_FromStringAndSize(frb_read_all(buf), buf_len)
+ *     return pgproto_types.BitString.frombytes(bytes_, bitlen)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_4)) __PYX_ERR(12, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_BitString); if (unlikely(!__pyx_t_5)) __PYX_ERR(12, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_frombytes); if (unlikely(!__pyx_t_4)) __PYX_ERR(12, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_bitlen); if (unlikely(!__pyx_t_5)) __PYX_ERR(12, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = NULL;
+  __pyx_t_7 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_7 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_bytes_, __pyx_t_5};
+    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 47, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_bytes_, __pyx_t_5};
+    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 47, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(12, 47, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    if (__pyx_t_6) {
+      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_bytes_);
+    __Pyx_GIVEREF(__pyx_v_bytes_);
+    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_bytes_);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5);
+    __pyx_t_5 = 0;
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(12, 47, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":41
+ * 
+ * 
+ * cdef bits_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t bitlen = hton.unpack_int32(frb_read(buf, 4))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.bits_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_bytes_);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":8
+ * 
+ * 
+ * cdef inline _encode_points(WriteBuffer wbuf, object points):             # <<<<<<<<<<<<<<
+ *     cdef object point
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__encode_points(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_points) {
+  PyObject *__pyx_v_point = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *(*__pyx_t_3)(PyObject *);
+  PyObject *__pyx_t_4 = NULL;
+  double __pyx_t_5;
+  __Pyx_RefNannySetupContext("_encode_points", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":11
+ *     cdef object point
+ * 
+ *     for point in points:             # <<<<<<<<<<<<<<
+ *         wbuf.write_double(point[0])
+ *         wbuf.write_double(point[1])
+ */
+  if (likely(PyList_CheckExact(__pyx_v_points)) || PyTuple_CheckExact(__pyx_v_points)) {
+    __pyx_t_1 = __pyx_v_points; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+    __pyx_t_3 = NULL;
+  } else {
+    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_points); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 11, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_3)) {
+      if (likely(PyList_CheckExact(__pyx_t_1))) {
+        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(13, 11, __pyx_L1_error)
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 11, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      } else {
+        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(13, 11, __pyx_L1_error)
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 11, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      }
+    } else {
+      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
+      if (unlikely(!__pyx_t_4)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(13, 11, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_4);
+    }
+    __Pyx_XDECREF_SET(__pyx_v_point, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":12
+ * 
+ *     for point in points:
+ *         wbuf.write_double(point[0])             # <<<<<<<<<<<<<<
+ *         wbuf.write_double(point[1])
+ * 
+ */
+    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_point, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_5 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 12, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":13
+ *     for point in points:
+ *         wbuf.write_double(point[0])
+ *         wbuf.write_double(point[1])             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_point, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_5 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 13, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":11
+ *     cdef object point
+ * 
+ *     for point in points:             # <<<<<<<<<<<<<<
+ *         wbuf.write_double(point[0])
+ *         wbuf.write_double(point[1])
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":8
+ * 
+ * 
+ * cdef inline _encode_points(WriteBuffer wbuf, object points):             # <<<<<<<<<<<<<<
+ *     cdef object point
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto._encode_points", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_point);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":16
+ * 
+ * 
+ * cdef inline _decode_points(FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t npts = hton.unpack_int32(frb_read(buf, 4))
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__decode_points(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_npts;
+  PyObject *__pyx_v_pts = 0;
+  int32_t __pyx_v_i;
+  PyObject *__pyx_v_point = 0;
+  double __pyx_v_x;
+  double __pyx_v_y;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  int32_t __pyx_t_3;
+  int32_t __pyx_t_4;
+  int32_t __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  __Pyx_RefNannySetupContext("_decode_points", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":18
+ * cdef inline _decode_points(FRBuffer *buf):
+ *     cdef:
+ *         int32_t npts = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         pts = cpython.PyTuple_New(npts)
+ *         int32_t i
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 18, __pyx_L1_error)
+  __pyx_v_npts = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":19
+ *     cdef:
+ *         int32_t npts = hton.unpack_int32(frb_read(buf, 4))
+ *         pts = cpython.PyTuple_New(npts)             # <<<<<<<<<<<<<<
+ *         int32_t i
+ *         object point
+ */
+  __pyx_t_2 = PyTuple_New(__pyx_v_npts); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_pts = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":25
+ *         double y
+ * 
+ *     for i in range(npts):             # <<<<<<<<<<<<<<
+ *         x = hton.unpack_double(frb_read(buf, 8))
+ *         y = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_3 = __pyx_v_npts;
+  __pyx_t_4 = __pyx_t_3;
+  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
+    __pyx_v_i = __pyx_t_5;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":26
+ * 
+ *     for i in range(npts):
+ *         x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         y = hton.unpack_double(frb_read(buf, 8))
+ *         point = pgproto_types.Point(x, y)
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 26, __pyx_L1_error)
+    __pyx_v_x = unpack_double(__pyx_t_1);
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":27
+ *     for i in range(npts):
+ *         x = hton.unpack_double(frb_read(buf, 8))
+ *         y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         point = pgproto_types.Point(x, y)
+ *         cpython.Py_INCREF(point)
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 27, __pyx_L1_error)
+    __pyx_v_y = unpack_double(__pyx_t_1);
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":28
+ *         x = hton.unpack_double(frb_read(buf, 8))
+ *         y = hton.unpack_double(frb_read(buf, 8))
+ *         point = pgproto_types.Point(x, y)             # <<<<<<<<<<<<<<
+ *         cpython.Py_INCREF(point)
+ *         cpython.PyTuple_SET_ITEM(pts, i, point)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 28, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Point); if (unlikely(!__pyx_t_7)) __PYX_ERR(13, 28, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 28, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_8 = PyFloat_FromDouble(__pyx_v_y); if (unlikely(!__pyx_t_8)) __PYX_ERR(13, 28, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_9 = NULL;
+    __pyx_t_10 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_9)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_9);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+        __pyx_t_10 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_7)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_6, __pyx_t_8};
+      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 28, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_6, __pyx_t_8};
+      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 28, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(13, 28, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      if (__pyx_t_9) {
+        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_6);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
+      __pyx_t_6 = 0;
+      __pyx_t_8 = 0;
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 28, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF_SET(__pyx_v_point, __pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":29
+ *         y = hton.unpack_double(frb_read(buf, 8))
+ *         point = pgproto_types.Point(x, y)
+ *         cpython.Py_INCREF(point)             # <<<<<<<<<<<<<<
+ *         cpython.PyTuple_SET_ITEM(pts, i, point)
+ * 
+ */
+    Py_INCREF(__pyx_v_point);
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":30
+ *         point = pgproto_types.Point(x, y)
+ *         cpython.Py_INCREF(point)
+ *         cpython.PyTuple_SET_ITEM(pts, i, point)             # <<<<<<<<<<<<<<
+ * 
+ *     return pts
+ */
+    PyTuple_SET_ITEM(__pyx_v_pts, __pyx_v_i, __pyx_v_point);
+  }
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":32
+ *         cpython.PyTuple_SET_ITEM(pts, i, point)
+ * 
+ *     return pts             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_pts);
+  __pyx_r = __pyx_v_pts;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":16
+ * 
+ * 
+ * cdef inline _decode_points(FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t npts = hton.unpack_int32(frb_read(buf, 4))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto._decode_points", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_pts);
+  __Pyx_XDECREF(__pyx_v_point);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":35
+ * 
+ * 
+ * cdef box_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(32)
+ *     _encode_points(wbuf, (obj[0], obj[1]))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_box_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("box_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":36
+ * 
+ * cdef box_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(32)             # <<<<<<<<<<<<<<
+ *     _encode_points(wbuf, (obj[0], obj[1]))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, 32); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":37
+ * cdef box_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(32)
+ *     _encode_points(wbuf, (obj[0], obj[1]))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_points(__pyx_v_wbuf, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":35
+ * 
+ * 
+ * cdef box_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(32)
+ *     _encode_points(wbuf, (obj[0], obj[1]))
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.box_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":40
+ * 
+ * 
+ * cdef box_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double high_x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_box_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  double __pyx_v_high_x;
+  double __pyx_v_high_y;
+  double __pyx_v_low_x;
+  double __pyx_v_low_y;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  __Pyx_RefNannySetupContext("box_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":42
+ * cdef box_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         double high_x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double high_y = hton.unpack_double(frb_read(buf, 8))
+ *         double low_x = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 42, __pyx_L1_error)
+  __pyx_v_high_x = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":43
+ *     cdef:
+ *         double high_x = hton.unpack_double(frb_read(buf, 8))
+ *         double high_y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double low_x = hton.unpack_double(frb_read(buf, 8))
+ *         double low_y = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 43, __pyx_L1_error)
+  __pyx_v_high_y = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":44
+ *         double high_x = hton.unpack_double(frb_read(buf, 8))
+ *         double high_y = hton.unpack_double(frb_read(buf, 8))
+ *         double low_x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double low_y = hton.unpack_double(frb_read(buf, 8))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 44, __pyx_L1_error)
+  __pyx_v_low_x = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":45
+ *         double high_y = hton.unpack_double(frb_read(buf, 8))
+ *         double low_x = hton.unpack_double(frb_read(buf, 8))
+ *         double low_y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return pgproto_types.Box(
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 45, __pyx_L1_error)
+  __pyx_v_low_y = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":47
+ *         double low_y = hton.unpack_double(frb_read(buf, 8))
+ * 
+ *     return pgproto_types.Box(             # <<<<<<<<<<<<<<
+ *         pgproto_types.Point(high_x, high_y),
+ *         pgproto_types.Point(low_x, low_y))
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Box); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":48
+ * 
+ *     return pgproto_types.Box(
+ *         pgproto_types.Point(high_x, high_y),             # <<<<<<<<<<<<<<
+ *         pgproto_types.Point(low_x, low_y))
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 48, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Point); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 48, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_high_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 48, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_7 = PyFloat_FromDouble(__pyx_v_high_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(13, 48, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __pyx_t_8 = NULL;
+  __pyx_t_9 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
+    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
+    if (likely(__pyx_t_8)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+      __Pyx_INCREF(__pyx_t_8);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_6, function);
+      __pyx_t_9 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_6)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_5, __pyx_t_7};
+    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 48, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_5, __pyx_t_7};
+    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 48, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(13, 48, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    if (__pyx_t_8) {
+      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_7);
+    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7);
+    __pyx_t_5 = 0;
+    __pyx_t_7 = 0;
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 48, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":49
+ *     return pgproto_types.Box(
+ *         pgproto_types.Point(high_x, high_y),
+ *         pgproto_types.Point(low_x, low_y))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_10)) __PYX_ERR(13, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_10);
+  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_Point); if (unlikely(!__pyx_t_7)) __PYX_ERR(13, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+  __pyx_t_10 = PyFloat_FromDouble(__pyx_v_low_x); if (unlikely(!__pyx_t_10)) __PYX_ERR(13, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_10);
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_low_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_8 = NULL;
+  __pyx_t_9 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
+    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+    if (likely(__pyx_t_8)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+      __Pyx_INCREF(__pyx_t_8);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_7, function);
+      __pyx_t_9 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_7)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_10, __pyx_t_5};
+    __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 49, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_10, __pyx_t_5};
+    __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 49, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(13, 49, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_11);
+    if (__pyx_t_8) {
+      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_10);
+    PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_t_10);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_5);
+    __pyx_t_10 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 49, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __pyx_t_7 = NULL;
+  __pyx_t_9 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_9 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_3, __pyx_t_6};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 47, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_3, __pyx_t_6};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 47, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_11 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(13, 47, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_11);
+    if (__pyx_t_7) {
+      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_7); __pyx_t_7 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_t_6);
+    __pyx_t_3 = 0;
+    __pyx_t_6 = 0;
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 47, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":40
+ * 
+ * 
+ * cdef box_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double high_x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.box_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":52
+ * 
+ * 
+ * cdef line_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0])
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_line_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  double __pyx_t_2;
+  __Pyx_RefNannySetupContext("line_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":53
+ * 
+ * cdef line_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(24)             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[0])
+ *     wbuf.write_double(obj[1])
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, 24); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 53, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":54
+ * cdef line_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0])             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[1])
+ *     wbuf.write_double(obj[2])
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 54, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":55
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0])
+ *     wbuf.write_double(obj[1])             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[2])
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 55, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":56
+ *     wbuf.write_double(obj[0])
+ *     wbuf.write_double(obj[1])
+ *     wbuf.write_double(obj[2])             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 56, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":52
+ * 
+ * 
+ * cdef line_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0])
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.line_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":59
+ * 
+ * 
+ * cdef line_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double A = hton.unpack_double(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_line_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  double __pyx_v_A;
+  double __pyx_v_B;
+  double __pyx_v_C;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("line_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":61
+ * cdef line_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         double A = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double B = hton.unpack_double(frb_read(buf, 8))
+ *         double C = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 61, __pyx_L1_error)
+  __pyx_v_A = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":62
+ *     cdef:
+ *         double A = hton.unpack_double(frb_read(buf, 8))
+ *         double B = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double C = hton.unpack_double(frb_read(buf, 8))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 62, __pyx_L1_error)
+  __pyx_v_B = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":63
+ *         double A = hton.unpack_double(frb_read(buf, 8))
+ *         double B = hton.unpack_double(frb_read(buf, 8))
+ *         double C = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return pgproto_types.Line(A, B, C)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 63, __pyx_L1_error)
+  __pyx_v_C = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":65
+ *         double C = hton.unpack_double(frb_read(buf, 8))
+ * 
+ *     return pgproto_types.Line(A, B, C)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 65, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Line); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 65, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_A); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 65, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_B); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 65, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = PyFloat_FromDouble(__pyx_v_C); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 65, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = NULL;
+  __pyx_t_8 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_8 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_t_3, __pyx_t_5, __pyx_t_6};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 65, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_t_3, __pyx_t_5, __pyx_t_6};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 65, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_9 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(13, 65, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    if (__pyx_t_7) {
+      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_t_6);
+    __pyx_t_3 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_6 = 0;
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 65, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":59
+ * 
+ * 
+ * cdef line_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double A = hton.unpack_double(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.line_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":68
+ * 
+ * 
+ * cdef lseg_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(32)
+ *     _encode_points(wbuf, (obj[0], obj[1]))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("lseg_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":69
+ * 
+ * cdef lseg_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(32)             # <<<<<<<<<<<<<<
+ *     _encode_points(wbuf, (obj[0], obj[1]))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, 32); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 69, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":70
+ * cdef lseg_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(32)
+ *     _encode_points(wbuf, (obj[0], obj[1]))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 70, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 70, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 70, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_points(__pyx_v_wbuf, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 70, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":68
+ * 
+ * 
+ * cdef lseg_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(32)
+ *     _encode_points(wbuf, (obj[0], obj[1]))
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.lseg_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":73
+ * 
+ * 
+ * cdef lseg_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double p1_x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  double __pyx_v_p1_x;
+  double __pyx_v_p1_y;
+  double __pyx_v_p2_x;
+  double __pyx_v_p2_y;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  __Pyx_RefNannySetupContext("lseg_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":75
+ * cdef lseg_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         double p1_x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double p1_y = hton.unpack_double(frb_read(buf, 8))
+ *         double p2_x = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 75, __pyx_L1_error)
+  __pyx_v_p1_x = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":76
+ *     cdef:
+ *         double p1_x = hton.unpack_double(frb_read(buf, 8))
+ *         double p1_y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double p2_x = hton.unpack_double(frb_read(buf, 8))
+ *         double p2_y = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 76, __pyx_L1_error)
+  __pyx_v_p1_y = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":77
+ *         double p1_x = hton.unpack_double(frb_read(buf, 8))
+ *         double p1_y = hton.unpack_double(frb_read(buf, 8))
+ *         double p2_x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double p2_y = hton.unpack_double(frb_read(buf, 8))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 77, __pyx_L1_error)
+  __pyx_v_p2_x = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":78
+ *         double p1_y = hton.unpack_double(frb_read(buf, 8))
+ *         double p2_x = hton.unpack_double(frb_read(buf, 8))
+ *         double p2_y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return pgproto_types.LineSegment((p1_x, p1_y), (p2_x, p2_y))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 78, __pyx_L1_error)
+  __pyx_v_p2_y = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":80
+ *         double p2_y = hton.unpack_double(frb_read(buf, 8))
+ * 
+ *     return pgproto_types.LineSegment((p1_x, p1_y), (p2_x, p2_y))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_LineSegment); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_p1_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_p1_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
+  __pyx_t_3 = 0;
+  __pyx_t_5 = 0;
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_p2_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_p2_y); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(13, 80, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __Pyx_GIVEREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3);
+  __pyx_t_5 = 0;
+  __pyx_t_3 = 0;
+  __pyx_t_3 = NULL;
+  __pyx_t_8 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_8 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_6, __pyx_t_7};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 80, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_6, __pyx_t_7};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 80, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_5 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 80, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    if (__pyx_t_3) {
+      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_7);
+    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_t_7);
+    __pyx_t_6 = 0;
+    __pyx_t_7 = 0;
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 80, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":73
+ * 
+ * 
+ * cdef lseg_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double p1_x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.lseg_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":83
+ * 
+ * 
+ * cdef point_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(16)
+ *     wbuf.write_double(obj[0])
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_point_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  double __pyx_t_2;
+  __Pyx_RefNannySetupContext("point_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":84
+ * 
+ * cdef point_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(16)             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[0])
+ *     wbuf.write_double(obj[1])
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, 16); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 84, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":85
+ * cdef point_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(16)
+ *     wbuf.write_double(obj[0])             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[1])
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 85, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 85, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 85, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":86
+ *     wbuf.write_int32(16)
+ *     wbuf.write_double(obj[0])
+ *     wbuf.write_double(obj[1])             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 86, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 86, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 86, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":83
+ * 
+ * 
+ * cdef point_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(16)
+ *     wbuf.write_double(obj[0])
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.point_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":89
+ * 
+ * 
+ * cdef point_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_point_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  double __pyx_v_x;
+  double __pyx_v_y;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("point_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":91
+ * cdef point_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         double x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double y = hton.unpack_double(frb_read(buf, 8))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 91, __pyx_L1_error)
+  __pyx_v_x = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":92
+ *     cdef:
+ *         double x = hton.unpack_double(frb_read(buf, 8))
+ *         double y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return pgproto_types.Point(x, y)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 92, __pyx_L1_error)
+  __pyx_v_y = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":94
+ *         double y = hton.unpack_double(frb_read(buf, 8))
+ * 
+ *     return pgproto_types.Point(x, y)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 94, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Point); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 94, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 94, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 94, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = NULL;
+  __pyx_t_7 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_7 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 94, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_3, __pyx_t_5};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 94, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(13, 94, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    if (__pyx_t_6) {
+      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5);
+    __pyx_t_3 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 94, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":89
+ * 
+ * 
+ * cdef point_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.point_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":97
+ * 
+ * 
+ * cdef path_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int8_t is_closed = 0
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_path_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  int8_t __pyx_v_is_closed;
+  Py_ssize_t __pyx_v_npts;
+  Py_ssize_t __pyx_v_encoded_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int8_t __pyx_t_5;
+  Py_ssize_t __pyx_t_6;
+  __Pyx_RefNannySetupContext("path_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":99
+ * cdef path_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     cdef:
+ *         int8_t is_closed = 0             # <<<<<<<<<<<<<<
+ *         ssize_t npts
+ *         ssize_t encoded_len
+ */
+  __pyx_v_is_closed = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":104
+ *         int32_t i
+ * 
+ *     if cpython.PyTuple_Check(obj):             # <<<<<<<<<<<<<<
+ *         is_closed = 1
+ *     elif cpython.PyList_Check(obj):
+ */
+  __pyx_t_1 = (PyTuple_Check(__pyx_v_obj) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":105
+ * 
+ *     if cpython.PyTuple_Check(obj):
+ *         is_closed = 1             # <<<<<<<<<<<<<<
+ *     elif cpython.PyList_Check(obj):
+ *         is_closed = 0
+ */
+    __pyx_v_is_closed = 1;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":104
+ *         int32_t i
+ * 
+ *     if cpython.PyTuple_Check(obj):             # <<<<<<<<<<<<<<
+ *         is_closed = 1
+ *     elif cpython.PyList_Check(obj):
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":106
+ *     if cpython.PyTuple_Check(obj):
+ *         is_closed = 1
+ *     elif cpython.PyList_Check(obj):             # <<<<<<<<<<<<<<
+ *         is_closed = 0
+ *     elif isinstance(obj, pgproto_types.Path):
+ */
+  __pyx_t_1 = (PyList_Check(__pyx_v_obj) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":107
+ *         is_closed = 1
+ *     elif cpython.PyList_Check(obj):
+ *         is_closed = 0             # <<<<<<<<<<<<<<
+ *     elif isinstance(obj, pgproto_types.Path):
+ *         is_closed = obj.is_closed
+ */
+    __pyx_v_is_closed = 0;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":106
+ *     if cpython.PyTuple_Check(obj):
+ *         is_closed = 1
+ *     elif cpython.PyList_Check(obj):             # <<<<<<<<<<<<<<
+ *         is_closed = 0
+ *     elif isinstance(obj, pgproto_types.Path):
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":108
+ *     elif cpython.PyList_Check(obj):
+ *         is_closed = 0
+ *     elif isinstance(obj, pgproto_types.Path):             # <<<<<<<<<<<<<<
+ *         is_closed = obj.is_closed
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 108, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Path); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 108, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_1 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_3); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(13, 108, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_4 = (__pyx_t_1 != 0);
+  if (__pyx_t_4) {
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":109
+ *         is_closed = 0
+ *     elif isinstance(obj, pgproto_types.Path):
+ *         is_closed = obj.is_closed             # <<<<<<<<<<<<<<
+ * 
+ *     npts = len(obj)
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_is_closed); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 109, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = __Pyx_PyInt_As_int8_t(__pyx_t_3); if (unlikely((__pyx_t_5 == ((int8_t)-1)) && PyErr_Occurred())) __PYX_ERR(13, 109, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_v_is_closed = __pyx_t_5;
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":108
+ *     elif cpython.PyList_Check(obj):
+ *         is_closed = 0
+ *     elif isinstance(obj, pgproto_types.Path):             # <<<<<<<<<<<<<<
+ *         is_closed = obj.is_closed
+ * 
+ */
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":111
+ *         is_closed = obj.is_closed
+ * 
+ *     npts = len(obj)             # <<<<<<<<<<<<<<
+ *     encoded_len = 1 + 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:
+ */
+  __pyx_t_6 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(13, 111, __pyx_L1_error)
+  __pyx_v_npts = __pyx_t_6;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":112
+ * 
+ *     npts = len(obj)
+ *     encoded_len = 1 + 4 + 16 * npts             # <<<<<<<<<<<<<<
+ *     if encoded_len > _MAXINT32:
+ *         raise ValueError('path value too long')
+ */
+  __pyx_v_encoded_len = (5 + (16 * __pyx_v_npts));
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":113
+ *     npts = len(obj)
+ *     encoded_len = 1 + 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('path value too long')
+ * 
+ */
+  __pyx_t_4 = ((__pyx_v_encoded_len > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_4)) {
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":114
+ *     encoded_len = 1 + 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:
+ *         raise ValueError('path value too long')             # <<<<<<<<<<<<<<
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ */
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 114, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(13, 114, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":113
+ *     npts = len(obj)
+ *     encoded_len = 1 + 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('path value too long')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":116
+ *         raise ValueError('path value too long')
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)             # <<<<<<<<<<<<<<
+ *     wbuf.write_byte(is_closed)
+ *     wbuf.write_int32(<int32_t>npts)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, ((int32_t)__pyx_v_encoded_len)); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 116, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":117
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ *     wbuf.write_byte(is_closed)             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(<int32_t>npts)
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_wbuf, __pyx_v_is_closed); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 117, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":118
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ *     wbuf.write_byte(is_closed)
+ *     wbuf.write_int32(<int32_t>npts)             # <<<<<<<<<<<<<<
+ * 
+ *     _encode_points(wbuf, obj)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, ((int32_t)__pyx_v_npts)); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 118, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":120
+ *     wbuf.write_int32(<int32_t>npts)
+ * 
+ *     _encode_points(wbuf, obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_points(__pyx_v_wbuf, __pyx_v_obj); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 120, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":97
+ * 
+ * 
+ * cdef path_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int8_t is_closed = 0
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.path_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":123
+ * 
+ * 
+ * cdef path_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int8_t is_closed = <int8_t>(frb_read(buf, 1)[0])
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_path_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int8_t __pyx_v_is_closed;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("path_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":125
+ * cdef path_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int8_t is_closed = <int8_t>(frb_read(buf, 1)[0])             # <<<<<<<<<<<<<<
+ * 
+ *     return pgproto_types.Path(*_decode_points(buf), is_closed=is_closed == 1)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 125, __pyx_L1_error)
+  __pyx_v_is_closed = ((int8_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":127
+ *         int8_t is_closed = <int8_t>(frb_read(buf, 1)[0])
+ * 
+ *     return pgproto_types.Path(*_decode_points(buf), is_closed=is_closed == 1)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Path); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto__decode_points(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_5 = __Pyx_PyBool_FromLong((__pyx_v_is_closed == 1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_is_closed, __pyx_t_5) < 0) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 127, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_5;
+  __pyx_t_5 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":123
+ * 
+ * 
+ * cdef path_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int8_t is_closed = <int8_t>(frb_read(buf, 1)[0])
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.path_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":130
+ * 
+ * 
+ * cdef poly_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         bint is_closed
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_poly_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  Py_ssize_t __pyx_v_npts;
+  Py_ssize_t __pyx_v_encoded_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("poly_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":137
+ *         int32_t i
+ * 
+ *     npts = len(obj)             # <<<<<<<<<<<<<<
+ *     encoded_len = 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(13, 137, __pyx_L1_error)
+  __pyx_v_npts = __pyx_t_1;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":138
+ * 
+ *     npts = len(obj)
+ *     encoded_len = 4 + 16 * npts             # <<<<<<<<<<<<<<
+ *     if encoded_len > _MAXINT32:
+ *         raise ValueError('polygon value too long')
+ */
+  __pyx_v_encoded_len = (4 + (16 * __pyx_v_npts));
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":139
+ *     npts = len(obj)
+ *     encoded_len = 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('polygon value too long')
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_encoded_len > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":140
+ *     encoded_len = 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:
+ *         raise ValueError('polygon value too long')             # <<<<<<<<<<<<<<
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ */
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 140, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(13, 140, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/geometry.pyx":139
+ *     npts = len(obj)
+ *     encoded_len = 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('polygon value too long')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":142
+ *         raise ValueError('polygon value too long')
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(<int32_t>npts)
+ *     _encode_points(wbuf, obj)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, ((int32_t)__pyx_v_encoded_len)); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 142, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":143
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ *     wbuf.write_int32(<int32_t>npts)             # <<<<<<<<<<<<<<
+ *     _encode_points(wbuf, obj)
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, ((int32_t)__pyx_v_npts)); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 143, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":144
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ *     wbuf.write_int32(<int32_t>npts)
+ *     _encode_points(wbuf, obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto__encode_points(__pyx_v_wbuf, __pyx_v_obj); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 144, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":130
+ * 
+ * 
+ * cdef poly_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         bint is_closed
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.poly_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":147
+ * 
+ * 
+ * cdef poly_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return pgproto_types.Polygon(*_decode_points(buf))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_poly_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("poly_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":148
+ * 
+ * cdef poly_decode(CodecContext settings, FRBuffer *buf):
+ *     return pgproto_types.Polygon(*_decode_points(buf))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 148, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Polygon); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 148, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto__decode_points(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 148, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 148, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 148, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":147
+ * 
+ * 
+ * cdef poly_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return pgproto_types.Polygon(*_decode_points(buf))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.poly_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":151
+ * 
+ * 
+ * cdef circle_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0][0])
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_circle_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  double __pyx_t_3;
+  __Pyx_RefNannySetupContext("circle_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":152
+ * 
+ * cdef circle_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(24)             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[0][0])
+ *     wbuf.write_double(obj[0][1])
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_wbuf, 24); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":153
+ * cdef circle_encode(CodecContext settings, WriteBuffer wbuf, obj):
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0][0])             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[0][1])
+ *     wbuf.write_double(obj[1])
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 153, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 153, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 153, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 153, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":154
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0][0])
+ *     wbuf.write_double(obj[0][1])             # <<<<<<<<<<<<<<
+ *     wbuf.write_double(obj[1])
+ * 
+ */
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 154, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 154, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 154, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 154, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":155
+ *     wbuf.write_double(obj[0][0])
+ *     wbuf.write_double(obj[0][1])
+ *     wbuf.write_double(obj[1])             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 155, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) __PYX_ERR(13, 155, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double(__pyx_v_wbuf, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 155, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":151
+ * 
+ * 
+ * cdef circle_encode(CodecContext settings, WriteBuffer wbuf, obj):             # <<<<<<<<<<<<<<
+ *     wbuf.write_int32(24)
+ *     wbuf.write_double(obj[0][0])
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.circle_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/geometry.pyx":158
+ * 
+ * 
+ * cdef circle_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double center_x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_circle_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  double __pyx_v_center_x;
+  double __pyx_v_center_y;
+  double __pyx_v_radius;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("circle_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":160
+ * cdef circle_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         double center_x = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double center_y = hton.unpack_double(frb_read(buf, 8))
+ *         double radius = hton.unpack_double(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 160, __pyx_L1_error)
+  __pyx_v_center_x = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":161
+ *     cdef:
+ *         double center_x = hton.unpack_double(frb_read(buf, 8))
+ *         double center_y = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *         double radius = hton.unpack_double(frb_read(buf, 8))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 161, __pyx_L1_error)
+  __pyx_v_center_y = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":162
+ *         double center_x = hton.unpack_double(frb_read(buf, 8))
+ *         double center_y = hton.unpack_double(frb_read(buf, 8))
+ *         double radius = hton.unpack_double(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     return pgproto_types.Circle((center_x, center_y), radius)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(13, 162, __pyx_L1_error)
+  __pyx_v_radius = unpack_double(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":164
+ *         double radius = hton.unpack_double(frb_read(buf, 8))
+ * 
+ *     return pgproto_types.Circle((center_x, center_y), radius)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pgproto_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 164, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Circle); if (unlikely(!__pyx_t_4)) __PYX_ERR(13, 164, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = PyFloat_FromDouble(__pyx_v_center_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(13, 164, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_center_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 164, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(13, 164, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
+  __pyx_t_3 = 0;
+  __pyx_t_5 = 0;
+  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_radius); if (unlikely(!__pyx_t_5)) __PYX_ERR(13, 164, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_3 = NULL;
+  __pyx_t_7 = 0;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_7 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_6, __pyx_t_5};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 164, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_t_6, __pyx_t_5};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 164, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(13, 164, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    if (__pyx_t_3) {
+      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5);
+    __pyx_t_6 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(13, 164, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":158
+ * 
+ * 
+ * cdef circle_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         double center_x = hton.unpack_double(frb_read(buf, 8))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.circle_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/hstore.pyx":8
+ * 
+ * 
+ * cdef hstore_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         char *str
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  char *__pyx_v_str;
+  Py_ssize_t __pyx_v_size;
+  Py_ssize_t __pyx_v_count;
+  PyObject *__pyx_v_items = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_item_buf = 0;
+  PyObject *__pyx_v_k = NULL;
+  PyObject *__pyx_v_v = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  int __pyx_t_3;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *(*__pyx_t_7)(PyObject *);
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *(*__pyx_t_10)(PyObject *);
+  int32_t __pyx_t_11;
+  __Pyx_RefNannySetupContext("hstore_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":14
+ *         ssize_t count
+ *         object items
+ *         WriteBuffer item_buf = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ * 
+ *     count = len(obj)
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new()); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_item_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":16
+ *         WriteBuffer item_buf = WriteBuffer.new()
+ * 
+ *     count = len(obj)             # <<<<<<<<<<<<<<
+ *     if count > _MAXINT32:
+ *         raise ValueError('hstore value is too large')
+ */
+  __pyx_t_2 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(14, 16, __pyx_L1_error)
+  __pyx_v_count = __pyx_t_2;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":17
+ * 
+ *     count = len(obj)
+ *     if count > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('hstore value is too large')
+ *     item_buf.write_int32(<int32_t>count)
+ */
+  __pyx_t_3 = ((__pyx_v_count > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":18
+ *     count = len(obj)
+ *     if count > _MAXINT32:
+ *         raise ValueError('hstore value is too large')             # <<<<<<<<<<<<<<
+ *     item_buf.write_int32(<int32_t>count)
+ * 
+ */
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 18, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(14, 18, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":17
+ * 
+ *     count = len(obj)
+ *     if count > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('hstore value is too large')
+ *     item_buf.write_int32(<int32_t>count)
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":19
+ *     if count > _MAXINT32:
+ *         raise ValueError('hstore value is too large')
+ *     item_buf.write_int32(<int32_t>count)             # <<<<<<<<<<<<<<
+ * 
+ *     if hasattr(obj, 'items'):
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_item_buf, ((int32_t)__pyx_v_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":21
+ *     item_buf.write_int32(<int32_t>count)
+ * 
+ *     if hasattr(obj, 'items'):             # <<<<<<<<<<<<<<
+ *         items = obj.items()
+ *     else:
+ */
+  __pyx_t_3 = __Pyx_HasAttr(__pyx_v_obj, __pyx_n_u_items); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(14, 21, __pyx_L1_error)
+  __pyx_t_4 = (__pyx_t_3 != 0);
+  if (__pyx_t_4) {
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":22
+ * 
+ *     if hasattr(obj, 'items'):
+ *         items = obj.items()             # <<<<<<<<<<<<<<
+ *     else:
+ *         items = obj
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_items); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 22, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 22, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_v_items = __pyx_t_1;
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":21
+ *     item_buf.write_int32(<int32_t>count)
+ * 
+ *     if hasattr(obj, 'items'):             # <<<<<<<<<<<<<<
+ *         items = obj.items()
+ *     else:
+ */
+    goto __pyx_L4;
+  }
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":24
+ *         items = obj.items()
+ *     else:
+ *         items = obj             # <<<<<<<<<<<<<<
+ * 
+ *     for k, v in items:
+ */
+  /*else*/ {
+    __Pyx_INCREF(__pyx_v_obj);
+    __pyx_v_items = __pyx_v_obj;
+  }
+  __pyx_L4:;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":26
+ *         items = obj
+ * 
+ *     for k, v in items:             # <<<<<<<<<<<<<<
+ *         if k is None:
+ *             raise ValueError('null value not allowed in hstore key')
+ */
+  if (likely(PyList_CheckExact(__pyx_v_items)) || PyTuple_CheckExact(__pyx_v_items)) {
+    __pyx_t_1 = __pyx_v_items; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+    __pyx_t_7 = NULL;
+  } else {
+    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 26, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(14, 26, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_7)) {
+      if (likely(PyList_CheckExact(__pyx_t_1))) {
+        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(14, 26, __pyx_L1_error)
+        #else
+        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 26, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        #endif
+      } else {
+        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(14, 26, __pyx_L1_error)
+        #else
+        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 26, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        #endif
+      }
+    } else {
+      __pyx_t_5 = __pyx_t_7(__pyx_t_1);
+      if (unlikely(!__pyx_t_5)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(14, 26, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_5);
+    }
+    if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
+      PyObject* sequence = __pyx_t_5;
+      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
+      if (unlikely(size != 2)) {
+        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
+        __PYX_ERR(14, 26, __pyx_L1_error)
+      }
+      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+      if (likely(PyTuple_CheckExact(sequence))) {
+        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
+        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
+      } else {
+        __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
+        __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
+      }
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(__pyx_t_8);
+      #else
+      __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(14, 26, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(14, 26, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      #endif
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else {
+      Py_ssize_t index = -1;
+      __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(14, 26, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
+      index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L7_unpacking_failed;
+      __Pyx_GOTREF(__pyx_t_6);
+      index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L7_unpacking_failed;
+      __Pyx_GOTREF(__pyx_t_8);
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(14, 26, __pyx_L1_error)
+      __pyx_t_10 = NULL;
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      goto __pyx_L8_unpacking_done;
+      __pyx_L7_unpacking_failed:;
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_10 = NULL;
+      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
+      __PYX_ERR(14, 26, __pyx_L1_error)
+      __pyx_L8_unpacking_done:;
+    }
+    __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_6);
+    __pyx_t_6 = 0;
+    __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_8);
+    __pyx_t_8 = 0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":27
+ * 
+ *     for k, v in items:
+ *         if k is None:             # <<<<<<<<<<<<<<
+ *             raise ValueError('null value not allowed in hstore key')
+ *         as_pg_string_and_size(settings, k, &str, &size)
+ */
+    __pyx_t_4 = (__pyx_v_k == Py_None);
+    __pyx_t_3 = (__pyx_t_4 != 0);
+    if (unlikely(__pyx_t_3)) {
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":28
+ *     for k, v in items:
+ *         if k is None:
+ *             raise ValueError('null value not allowed in hstore key')             # <<<<<<<<<<<<<<
+ *         as_pg_string_and_size(settings, k, &str, &size)
+ *         item_buf.write_int32(<int32_t>size)
+ */
+      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 28, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __PYX_ERR(14, 28, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":27
+ * 
+ *     for k, v in items:
+ *         if k is None:             # <<<<<<<<<<<<<<
+ *             raise ValueError('null value not allowed in hstore key')
+ *         as_pg_string_and_size(settings, k, &str, &size)
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":29
+ *         if k is None:
+ *             raise ValueError('null value not allowed in hstore key')
+ *         as_pg_string_and_size(settings, k, &str, &size)             # <<<<<<<<<<<<<<
+ *         item_buf.write_int32(<int32_t>size)
+ *         item_buf.write_cstr(str, size)
+ */
+    __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(__pyx_v_settings, __pyx_v_k, (&__pyx_v_str), (&__pyx_v_size)); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 29, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":30
+ *             raise ValueError('null value not allowed in hstore key')
+ *         as_pg_string_and_size(settings, k, &str, &size)
+ *         item_buf.write_int32(<int32_t>size)             # <<<<<<<<<<<<<<
+ *         item_buf.write_cstr(str, size)
+ *         if v is None:
+ */
+    __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_item_buf, ((int32_t)__pyx_v_size)); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 30, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":31
+ *         as_pg_string_and_size(settings, k, &str, &size)
+ *         item_buf.write_int32(<int32_t>size)
+ *         item_buf.write_cstr(str, size)             # <<<<<<<<<<<<<<
+ *         if v is None:
+ *             item_buf.write_int32(<int32_t>-1)
+ */
+    __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_item_buf, __pyx_v_str, __pyx_v_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 31, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":32
+ *         item_buf.write_int32(<int32_t>size)
+ *         item_buf.write_cstr(str, size)
+ *         if v is None:             # <<<<<<<<<<<<<<
+ *             item_buf.write_int32(<int32_t>-1)
+ *         else:
+ */
+    __pyx_t_3 = (__pyx_v_v == Py_None);
+    __pyx_t_4 = (__pyx_t_3 != 0);
+    if (__pyx_t_4) {
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":33
+ *         item_buf.write_cstr(str, size)
+ *         if v is None:
+ *             item_buf.write_int32(<int32_t>-1)             # <<<<<<<<<<<<<<
+ *         else:
+ *             as_pg_string_and_size(settings, v, &str, &size)
+ */
+      __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_item_buf, ((int32_t)-1L)); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 33, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":32
+ *         item_buf.write_int32(<int32_t>size)
+ *         item_buf.write_cstr(str, size)
+ *         if v is None:             # <<<<<<<<<<<<<<
+ *             item_buf.write_int32(<int32_t>-1)
+ *         else:
+ */
+      goto __pyx_L10;
+    }
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":35
+ *             item_buf.write_int32(<int32_t>-1)
+ *         else:
+ *             as_pg_string_and_size(settings, v, &str, &size)             # <<<<<<<<<<<<<<
+ *             item_buf.write_int32(<int32_t>size)
+ *             item_buf.write_cstr(str, size)
+ */
+    /*else*/ {
+      __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(__pyx_v_settings, __pyx_v_v, (&__pyx_v_str), (&__pyx_v_size)); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 35, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":36
+ *         else:
+ *             as_pg_string_and_size(settings, v, &str, &size)
+ *             item_buf.write_int32(<int32_t>size)             # <<<<<<<<<<<<<<
+ *             item_buf.write_cstr(str, size)
+ * 
+ */
+      __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_item_buf, ((int32_t)__pyx_v_size)); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 36, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":37
+ *             as_pg_string_and_size(settings, v, &str, &size)
+ *             item_buf.write_int32(<int32_t>size)
+ *             item_buf.write_cstr(str, size)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(item_buf.len())
+ */
+      __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_item_buf, __pyx_v_str, __pyx_v_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(14, 37, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    }
+    __pyx_L10:;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":26
+ *         items = obj
+ * 
+ *     for k, v in items:             # <<<<<<<<<<<<<<
+ *         if k is None:
+ *             raise ValueError('null value not allowed in hstore key')
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":39
+ *             item_buf.write_cstr(str, size)
+ * 
+ *     buf.write_int32(item_buf.len())             # <<<<<<<<<<<<<<
+ *     buf.write_buffer(item_buf)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_item_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_11 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(14, 39, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":40
+ * 
+ *     buf.write_int32(item_buf.len())
+ *     buf.write_buffer(item_buf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_buffer(__pyx_v_buf, __pyx_v_item_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 40, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":8
+ * 
+ * 
+ * cdef hstore_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         char *str
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.hstore_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_items);
+  __Pyx_XDECREF((PyObject *)__pyx_v_item_buf);
+  __Pyx_XDECREF(__pyx_v_k);
+  __Pyx_XDECREF(__pyx_v_v);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/hstore.pyx":43
+ * 
+ * 
+ * cdef hstore_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         dict result
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_decode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_v_result = 0;
+  uint32_t __pyx_v_elem_count;
+  int32_t __pyx_v_elem_len;
+  CYTHON_UNUSED uint32_t __pyx_v_i;
+  PyObject *__pyx_v_k = 0;
+  PyObject *__pyx_v_v = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  char const *__pyx_t_2;
+  int __pyx_t_3;
+  uint32_t __pyx_t_4;
+  uint32_t __pyx_t_5;
+  uint32_t __pyx_t_6;
+  __Pyx_RefNannySetupContext("hstore_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":52
+ *         str v
+ * 
+ *     result = {}             # <<<<<<<<<<<<<<
+ * 
+ *     elem_count = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 52, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_result = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":54
+ *     result = {}
+ * 
+ *     elem_count = <uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     if elem_count == 0:
+ *         return result
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(14, 54, __pyx_L1_error)
+  __pyx_v_elem_count = ((uint32_t)unpack_int32(__pyx_t_2));
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":55
+ * 
+ *     elem_count = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *     if elem_count == 0:             # <<<<<<<<<<<<<<
+ *         return result
+ * 
+ */
+  __pyx_t_3 = ((__pyx_v_elem_count == 0) != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":56
+ *     elem_count = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *     if elem_count == 0:
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(elem_count):
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(__pyx_v_result);
+    __pyx_r = __pyx_v_result;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":55
+ * 
+ *     elem_count = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *     if elem_count == 0:             # <<<<<<<<<<<<<<
+ *         return result
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":58
+ *         return result
+ * 
+ *     for i in range(elem_count):             # <<<<<<<<<<<<<<
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:
+ */
+  __pyx_t_4 = __pyx_v_elem_count;
+  __pyx_t_5 = __pyx_t_4;
+  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
+    __pyx_v_i = __pyx_t_6;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":59
+ * 
+ *     for i in range(elem_count):
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         if elem_len < 0:
+ *             raise ValueError('null value not allowed in hstore key')
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(14, 59, __pyx_L1_error)
+    __pyx_v_elem_len = unpack_int32(__pyx_t_2);
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":60
+ *     for i in range(elem_count):
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:             # <<<<<<<<<<<<<<
+ *             raise ValueError('null value not allowed in hstore key')
+ * 
+ */
+    __pyx_t_3 = ((__pyx_v_elem_len < 0) != 0);
+    if (unlikely(__pyx_t_3)) {
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":61
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:
+ *             raise ValueError('null value not allowed in hstore key')             # <<<<<<<<<<<<<<
+ * 
+ *         k = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+ */
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 61, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(14, 61, __pyx_L1_error)
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":60
+ *     for i in range(elem_count):
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:             # <<<<<<<<<<<<<<
+ *             raise ValueError('null value not allowed in hstore key')
+ * 
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":63
+ *             raise ValueError('null value not allowed in hstore key')
+ * 
+ *         k = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)             # <<<<<<<<<<<<<<
+ * 
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, __pyx_v_elem_len); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(14, 63, __pyx_L1_error)
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_decode_pg_string(__pyx_v_settings, __pyx_t_2, __pyx_v_elem_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 63, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(14, 63, __pyx_L1_error)
+    __Pyx_XDECREF_SET(__pyx_v_k, ((PyObject*)__pyx_t_1));
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":65
+ *         k = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+ * 
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         if elem_len < 0:
+ *             v = None
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(14, 65, __pyx_L1_error)
+    __pyx_v_elem_len = unpack_int32(__pyx_t_2);
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":66
+ * 
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:             # <<<<<<<<<<<<<<
+ *             v = None
+ *         else:
+ */
+    __pyx_t_3 = ((__pyx_v_elem_len < 0) != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":67
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:
+ *             v = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             v = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_v, ((PyObject*)Py_None));
+
+      /* "asyncpg/pgproto/codecs/hstore.pyx":66
+ * 
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:             # <<<<<<<<<<<<<<
+ *             v = None
+ *         else:
+ */
+      goto __pyx_L7;
+    }
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":69
+ *             v = None
+ *         else:
+ *             v = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)             # <<<<<<<<<<<<<<
+ * 
+ *         result[k] = v
+ */
+    /*else*/ {
+      __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, __pyx_v_elem_len); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(14, 69, __pyx_L1_error)
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_decode_pg_string(__pyx_v_settings, __pyx_t_2, __pyx_v_elem_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(14, 69, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(14, 69, __pyx_L1_error)
+      __Pyx_XDECREF_SET(__pyx_v_v, ((PyObject*)__pyx_t_1));
+      __pyx_t_1 = 0;
+    }
+    __pyx_L7:;
+
+    /* "asyncpg/pgproto/codecs/hstore.pyx":71
+ *             v = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+ * 
+ *         result[k] = v             # <<<<<<<<<<<<<<
+ * 
+ *     return result
+ */
+    if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(14, 71, __pyx_L1_error)
+  }
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":73
+ *         result[k] = v
+ * 
+ *     return result             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":43
+ * 
+ * 
+ * cdef hstore_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         dict result
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.hstore_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF(__pyx_v_k);
+  __Pyx_XDECREF(__pyx_v_v);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/misc.pyx":8
+ * 
+ * 
+ * cdef void_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     # Void is zero bytes
+ *     buf.write_int32(0)
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_void_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, CYTHON_UNUSED PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("void_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/misc.pyx":10
+ * cdef void_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     # Void is zero bytes
+ *     buf.write_int32(0)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(15, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/misc.pyx":8
+ * 
+ * 
+ * cdef void_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     # Void is zero bytes
+ *     buf.write_int32(0)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.void_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/misc.pyx":13
+ * 
+ * 
+ * cdef void_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     # Do nothing; void will be passed as NULL so this function
+ *     # will never be called.
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_void_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, CYTHON_UNUSED struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("void_decode", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":21
+ * 
+ * 
+ * cdef inline uint8_t _ip_max_prefix_len(int32_t family):             # <<<<<<<<<<<<<<
+ *     # Maximum number of bits in the network prefix of the specified
+ *     # IP protocol version.
+ */
+
+static CYTHON_INLINE uint8_t __pyx_f_7asyncpg_7pgproto_7pgproto__ip_max_prefix_len(int32_t __pyx_v_family) {
+  uint8_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("_ip_max_prefix_len", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":24
+ *     # Maximum number of bits in the network prefix of the specified
+ *     # IP protocol version.
+ *     if family == PGSQL_AF_INET:             # <<<<<<<<<<<<<<
+ *         return 32
+ *     else:
+ */
+  __pyx_t_1 = ((__pyx_v_family == 2) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":25
+ *     # IP protocol version.
+ *     if family == PGSQL_AF_INET:
+ *         return 32             # <<<<<<<<<<<<<<
+ *     else:
+ *         return 128
+ */
+    __pyx_r = 32;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":24
+ *     # Maximum number of bits in the network prefix of the specified
+ *     # IP protocol version.
+ *     if family == PGSQL_AF_INET:             # <<<<<<<<<<<<<<
+ *         return 32
+ *     else:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":27
+ *         return 32
+ *     else:
+ *         return 128             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __pyx_r = 0x80;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":21
+ * 
+ * 
+ * cdef inline uint8_t _ip_max_prefix_len(int32_t family):             # <<<<<<<<<<<<<<
+ *     # Maximum number of bits in the network prefix of the specified
+ *     # IP protocol version.
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":30
+ * 
+ * 
+ * cdef inline int32_t _ip_addr_len(int32_t family):             # <<<<<<<<<<<<<<
+ *     # Length of address in bytes for the specified IP protocol version.
+ *     if family == PGSQL_AF_INET:
+ */
+
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto__ip_addr_len(int32_t __pyx_v_family) {
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("_ip_addr_len", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":32
+ * cdef inline int32_t _ip_addr_len(int32_t family):
+ *     # Length of address in bytes for the specified IP protocol version.
+ *     if family == PGSQL_AF_INET:             # <<<<<<<<<<<<<<
+ *         return 4
+ *     else:
+ */
+  __pyx_t_1 = ((__pyx_v_family == 2) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":33
+ *     # Length of address in bytes for the specified IP protocol version.
+ *     if family == PGSQL_AF_INET:
+ *         return 4             # <<<<<<<<<<<<<<
+ *     else:
+ *         return 16
+ */
+    __pyx_r = 4;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":32
+ * cdef inline int32_t _ip_addr_len(int32_t family):
+ *     # Length of address in bytes for the specified IP protocol version.
+ *     if family == PGSQL_AF_INET:             # <<<<<<<<<<<<<<
+ *         return 4
+ *     else:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":35
+ *         return 4
+ *     else:
+ *         return 16             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __pyx_r = 16;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":30
+ * 
+ * 
+ * cdef inline int32_t _ip_addr_len(int32_t family):             # <<<<<<<<<<<<<<
+ *     # Length of address in bytes for the specified IP protocol version.
+ *     if family == PGSQL_AF_INET:
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":38
+ * 
+ * 
+ * cdef inline int8_t _ver_to_family(int32_t version):             # <<<<<<<<<<<<<<
+ *     if version == 4:
+ *         return PGSQL_AF_INET
+ */
+
+static CYTHON_INLINE int8_t __pyx_f_7asyncpg_7pgproto_7pgproto__ver_to_family(int32_t __pyx_v_version) {
+  int8_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("_ver_to_family", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":39
+ * 
+ * cdef inline int8_t _ver_to_family(int32_t version):
+ *     if version == 4:             # <<<<<<<<<<<<<<
+ *         return PGSQL_AF_INET
+ *     else:
+ */
+  __pyx_t_1 = ((__pyx_v_version == 4) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":40
+ * cdef inline int8_t _ver_to_family(int32_t version):
+ *     if version == 4:
+ *         return PGSQL_AF_INET             # <<<<<<<<<<<<<<
+ *     else:
+ *         return PGSQL_AF_INET6
+ */
+    __pyx_r = 2;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":39
+ * 
+ * cdef inline int8_t _ver_to_family(int32_t version):
+ *     if version == 4:             # <<<<<<<<<<<<<<
+ *         return PGSQL_AF_INET
+ *     else:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":42
+ *         return PGSQL_AF_INET
+ *     else:
+ *         return PGSQL_AF_INET6             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __pyx_r = 3;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":38
+ * 
+ * 
+ * cdef inline int8_t _ver_to_family(int32_t version):             # <<<<<<<<<<<<<<
+ *     if version == 4:
+ *         return PGSQL_AF_INET
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":45
+ * 
+ * 
+ * cdef inline _net_encode(WriteBuffer buf, int8_t family, uint32_t bits,             # <<<<<<<<<<<<<<
+ *                         int8_t is_cidr, bytes addr):
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto__net_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, int8_t __pyx_v_family, uint32_t __pyx_v_bits, int8_t __pyx_v_is_cidr, PyObject *__pyx_v_addr) {
+  char *__pyx_v_addrbytes;
+  Py_ssize_t __pyx_v_addrlen;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_net_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":52
+ *         ssize_t addrlen
+ * 
+ *     cpython.PyBytes_AsStringAndSize(addr, &addrbytes, &addrlen)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4 + <int32_t>addrlen)
+ */
+  __pyx_t_1 = PyBytes_AsStringAndSize(__pyx_v_addr, (&__pyx_v_addrbytes), ((Py_ssize_t *)(&__pyx_v_addrlen))); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(16, 52, __pyx_L1_error)
+
+  /* "asyncpg/pgproto/codecs/network.pyx":54
+ *     cpython.PyBytes_AsStringAndSize(addr, &addrbytes, &addrlen)
+ * 
+ *     buf.write_int32(4 + <int32_t>addrlen)             # <<<<<<<<<<<<<<
+ *     buf.write_byte(family)
+ *     buf.write_byte(<int8_t>bits)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, (4 + ((int32_t)__pyx_v_addrlen))); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":55
+ * 
+ *     buf.write_int32(4 + <int32_t>addrlen)
+ *     buf.write_byte(family)             # <<<<<<<<<<<<<<
+ *     buf.write_byte(<int8_t>bits)
+ *     buf.write_byte(is_cidr)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, __pyx_v_family); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":56
+ *     buf.write_int32(4 + <int32_t>addrlen)
+ *     buf.write_byte(family)
+ *     buf.write_byte(<int8_t>bits)             # <<<<<<<<<<<<<<
+ *     buf.write_byte(is_cidr)
+ *     buf.write_byte(<int8_t>addrlen)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, ((int8_t)__pyx_v_bits)); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":57
+ *     buf.write_byte(family)
+ *     buf.write_byte(<int8_t>bits)
+ *     buf.write_byte(is_cidr)             # <<<<<<<<<<<<<<
+ *     buf.write_byte(<int8_t>addrlen)
+ *     buf.write_cstr(addrbytes, addrlen)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, __pyx_v_is_cidr); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 57, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":58
+ *     buf.write_byte(<int8_t>bits)
+ *     buf.write_byte(is_cidr)
+ *     buf.write_byte(<int8_t>addrlen)             # <<<<<<<<<<<<<<
+ *     buf.write_cstr(addrbytes, addrlen)
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte(__pyx_v_buf, ((int8_t)__pyx_v_addrlen)); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 58, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":59
+ *     buf.write_byte(is_cidr)
+ *     buf.write_byte(<int8_t>addrlen)
+ *     buf.write_cstr(addrbytes, addrlen)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr(__pyx_v_buf, __pyx_v_addrbytes, __pyx_v_addrlen); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":45
+ * 
+ * 
+ * cdef inline _net_encode(WriteBuffer buf, int8_t family, uint32_t bits,             # <<<<<<<<<<<<<<
+ *                         int8_t is_cidr, bytes addr):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto._net_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":62
+ * 
+ * 
+ * cdef net_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t family = <int32_t>frb_read(buf, 1)[0]
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_net_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_family;
+  uint8_t __pyx_v_bits;
+  int32_t __pyx_v_is_cidr;
+  int32_t __pyx_v_addrlen;
+  PyObject *__pyx_v_addr = 0;
+  uint8_t __pyx_v_max_prefix_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  __Pyx_RefNannySetupContext("net_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":64
+ * cdef net_decode(CodecContext settings, FRBuffer *buf):
+ *     cdef:
+ *         int32_t family = <int32_t>frb_read(buf, 1)[0]             # <<<<<<<<<<<<<<
+ *         uint8_t bits = <uint8_t>frb_read(buf, 1)[0]
+ *         int32_t is_cidr = <int32_t>frb_read(buf, 1)[0]
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(16, 64, __pyx_L1_error)
+  __pyx_v_family = ((int32_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/pgproto/codecs/network.pyx":65
+ *     cdef:
+ *         int32_t family = <int32_t>frb_read(buf, 1)[0]
+ *         uint8_t bits = <uint8_t>frb_read(buf, 1)[0]             # <<<<<<<<<<<<<<
+ *         int32_t is_cidr = <int32_t>frb_read(buf, 1)[0]
+ *         int32_t addrlen = <int32_t>frb_read(buf, 1)[0]
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(16, 65, __pyx_L1_error)
+  __pyx_v_bits = ((uint8_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/pgproto/codecs/network.pyx":66
+ *         int32_t family = <int32_t>frb_read(buf, 1)[0]
+ *         uint8_t bits = <uint8_t>frb_read(buf, 1)[0]
+ *         int32_t is_cidr = <int32_t>frb_read(buf, 1)[0]             # <<<<<<<<<<<<<<
+ *         int32_t addrlen = <int32_t>frb_read(buf, 1)[0]
+ *         bytes addr
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(16, 66, __pyx_L1_error)
+  __pyx_v_is_cidr = ((int32_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/pgproto/codecs/network.pyx":67
+ *         uint8_t bits = <uint8_t>frb_read(buf, 1)[0]
+ *         int32_t is_cidr = <int32_t>frb_read(buf, 1)[0]
+ *         int32_t addrlen = <int32_t>frb_read(buf, 1)[0]             # <<<<<<<<<<<<<<
+ *         bytes addr
+ *         uint8_t max_prefix_len = _ip_max_prefix_len(family)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(16, 67, __pyx_L1_error)
+  __pyx_v_addrlen = ((int32_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/pgproto/codecs/network.pyx":69
+ *         int32_t addrlen = <int32_t>frb_read(buf, 1)[0]
+ *         bytes addr
+ *         uint8_t max_prefix_len = _ip_max_prefix_len(family)             # <<<<<<<<<<<<<<
+ * 
+ *     if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:
+ */
+  __pyx_v_max_prefix_len = __pyx_f_7asyncpg_7pgproto_7pgproto__ip_max_prefix_len(__pyx_v_family);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":71
+ *         uint8_t max_prefix_len = _ip_max_prefix_len(family)
+ * 
+ *     if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:             # <<<<<<<<<<<<<<
+ *         raise ValueError('invalid address family in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'
+ */
+  switch (__pyx_v_family) {
+    case 2:
+    case 3:
+    __pyx_t_2 = 0;
+    break;
+    default:
+    __pyx_t_2 = 1;
+    break;
+  }
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":72
+ * 
+ *     if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:
+ *         raise ValueError('invalid address family in "{}" value'.format(             # <<<<<<<<<<<<<<
+ *             'cidr' if is_cidr else 'inet'
+ *         ))
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_address_family_in_value, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 72, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/pgproto/codecs/network.pyx":73
+ *     if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:
+ *         raise ValueError('invalid address family in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'             # <<<<<<<<<<<<<<
+ *         ))
+ * 
+ */
+    if ((__pyx_v_is_cidr != 0)) {
+      __Pyx_INCREF(__pyx_n_u_cidr);
+      __pyx_t_5 = __pyx_n_u_cidr;
+    } else {
+      __Pyx_INCREF(__pyx_n_u_inet);
+      __pyx_t_5 = __pyx_n_u_inet;
+    }
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(16, 72, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":72
+ * 
+ *     if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:
+ *         raise ValueError('invalid address family in "{}" value'.format(             # <<<<<<<<<<<<<<
+ *             'cidr' if is_cidr else 'inet'
+ *         ))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 72, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(16, 72, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/network.pyx":71
+ *         uint8_t max_prefix_len = _ip_max_prefix_len(family)
+ * 
+ *     if family != PGSQL_AF_INET and family != PGSQL_AF_INET6:             # <<<<<<<<<<<<<<
+ *         raise ValueError('invalid address family in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":76
+ *         ))
+ * 
+ *     max_prefix_len = _ip_max_prefix_len(family)             # <<<<<<<<<<<<<<
+ * 
+ *     if bits > max_prefix_len:
+ */
+  __pyx_v_max_prefix_len = __pyx_f_7asyncpg_7pgproto_7pgproto__ip_max_prefix_len(__pyx_v_family);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":78
+ *     max_prefix_len = _ip_max_prefix_len(family)
+ * 
+ *     if bits > max_prefix_len:             # <<<<<<<<<<<<<<
+ *         raise ValueError('invalid network prefix length in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'
+ */
+  __pyx_t_2 = ((__pyx_v_bits > __pyx_v_max_prefix_len) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":79
+ * 
+ *     if bits > max_prefix_len:
+ *         raise ValueError('invalid network prefix length in "{}" value'.format(             # <<<<<<<<<<<<<<
+ *             'cidr' if is_cidr else 'inet'
+ *         ))
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_network_prefix_length_in, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(16, 79, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/pgproto/codecs/network.pyx":80
+ *     if bits > max_prefix_len:
+ *         raise ValueError('invalid network prefix length in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'             # <<<<<<<<<<<<<<
+ *         ))
+ * 
+ */
+    if ((__pyx_v_is_cidr != 0)) {
+      __Pyx_INCREF(__pyx_n_u_cidr);
+      __pyx_t_5 = __pyx_n_u_cidr;
+    } else {
+      __Pyx_INCREF(__pyx_n_u_inet);
+      __pyx_t_5 = __pyx_n_u_inet;
+    }
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 79, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":79
+ * 
+ *     if bits > max_prefix_len:
+ *         raise ValueError('invalid network prefix length in "{}" value'.format(             # <<<<<<<<<<<<<<
+ *             'cidr' if is_cidr else 'inet'
+ *         ))
+ */
+    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(16, 79, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(16, 79, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/network.pyx":78
+ *     max_prefix_len = _ip_max_prefix_len(family)
+ * 
+ *     if bits > max_prefix_len:             # <<<<<<<<<<<<<<
+ *         raise ValueError('invalid network prefix length in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":83
+ *         ))
+ * 
+ *     if addrlen != _ip_addr_len(family):             # <<<<<<<<<<<<<<
+ *         raise ValueError('invalid address length in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'
+ */
+  __pyx_t_2 = ((__pyx_v_addrlen != __pyx_f_7asyncpg_7pgproto_7pgproto__ip_addr_len(__pyx_v_family)) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":84
+ * 
+ *     if addrlen != _ip_addr_len(family):
+ *         raise ValueError('invalid address length in "{}" value'.format(             # <<<<<<<<<<<<<<
+ *             'cidr' if is_cidr else 'inet'
+ *         ))
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_address_length_in_value, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/pgproto/codecs/network.pyx":85
+ *     if addrlen != _ip_addr_len(family):
+ *         raise ValueError('invalid address length in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'             # <<<<<<<<<<<<<<
+ *         ))
+ * 
+ */
+    if ((__pyx_v_is_cidr != 0)) {
+      __Pyx_INCREF(__pyx_n_u_cidr);
+      __pyx_t_5 = __pyx_n_u_cidr;
+    } else {
+      __Pyx_INCREF(__pyx_n_u_inet);
+      __pyx_t_5 = __pyx_n_u_inet;
+    }
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(16, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":84
+ * 
+ *     if addrlen != _ip_addr_len(family):
+ *         raise ValueError('invalid address length in "{}" value'.format(             # <<<<<<<<<<<<<<
+ *             'cidr' if is_cidr else 'inet'
+ *         ))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(16, 84, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/network.pyx":83
+ *         ))
+ * 
+ *     if addrlen != _ip_addr_len(family):             # <<<<<<<<<<<<<<
+ *         raise ValueError('invalid address length in "{}" value'.format(
+ *             'cidr' if is_cidr else 'inet'
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":88
+ *         ))
+ * 
+ *     addr = cpython.PyBytes_FromStringAndSize(frb_read(buf, addrlen), addrlen)             # <<<<<<<<<<<<<<
+ * 
+ *     if is_cidr or bits != max_prefix_len:
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, __pyx_v_addrlen); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(16, 88, __pyx_L1_error)
+  __pyx_t_4 = PyBytes_FromStringAndSize(__pyx_t_1, __pyx_v_addrlen); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 88, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_v_addr = ((PyObject*)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":90
+ *     addr = cpython.PyBytes_FromStringAndSize(frb_read(buf, addrlen), addrlen)
+ * 
+ *     if is_cidr or bits != max_prefix_len:             # <<<<<<<<<<<<<<
+ *         return _ipnet(addr).supernet(new_prefix=cpython.PyLong_FromLong(bits))
+ *     else:
+ */
+  __pyx_t_7 = (__pyx_v_is_cidr != 0);
+  if (!__pyx_t_7) {
+  } else {
+    __pyx_t_2 = __pyx_t_7;
+    goto __pyx_L7_bool_binop_done;
+  }
+  __pyx_t_7 = ((__pyx_v_bits != __pyx_v_max_prefix_len) != 0);
+  __pyx_t_2 = __pyx_t_7;
+  __pyx_L7_bool_binop_done:;
+  if (__pyx_t_2) {
+
+    /* "asyncpg/pgproto/codecs/network.pyx":91
+ * 
+ *     if is_cidr or bits != max_prefix_len:
+ *         return _ipnet(addr).supernet(new_prefix=cpython.PyLong_FromLong(bits))             # <<<<<<<<<<<<<<
+ *     else:
+ *         return _ipaddr(addr)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ipnet); if (unlikely(!__pyx_t_3)) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_addr) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_addr);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_supernet); if (unlikely(!__pyx_t_3)) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = PyLong_FromLong(__pyx_v_bits); if (unlikely(!__pyx_t_5)) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_new_prefix, __pyx_t_5) < 0) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(16, 91, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_5;
+    __pyx_t_5 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":90
+ *     addr = cpython.PyBytes_FromStringAndSize(frb_read(buf, addrlen), addrlen)
+ * 
+ *     if is_cidr or bits != max_prefix_len:             # <<<<<<<<<<<<<<
+ *         return _ipnet(addr).supernet(new_prefix=cpython.PyLong_FromLong(bits))
+ *     else:
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":93
+ *         return _ipnet(addr).supernet(new_prefix=cpython.PyLong_FromLong(bits))
+ *     else:
+ *         return _ipaddr(addr)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ipaddr); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 93, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_addr) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_addr);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_5)) __PYX_ERR(16, 93, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_5;
+    __pyx_t_5 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":62
+ * 
+ * 
+ * cdef net_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t family = <int32_t>frb_read(buf, 1)[0]
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.net_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_addr);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":96
+ * 
+ * 
+ * cdef cidr_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         object ipnet
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_ipnet = 0;
+  int8_t __pyx_v_family;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int32_t __pyx_t_4;
+  uint32_t __pyx_t_5;
+  __Pyx_RefNannySetupContext("cidr_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":101
+ *         int8_t family
+ * 
+ *     ipnet = _ipnet(obj)             # <<<<<<<<<<<<<<
+ *     family = _ver_to_family(ipnet.version)
+ *     _net_encode(buf, family, ipnet.prefixlen, 1, ipnet.network_address.packed)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ipnet); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 101, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_obj);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(16, 101, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_ipnet = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":102
+ * 
+ *     ipnet = _ipnet(obj)
+ *     family = _ver_to_family(ipnet.version)             # <<<<<<<<<<<<<<
+ *     _net_encode(buf, family, ipnet.prefixlen, 1, ipnet.network_address.packed)
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_ipnet, __pyx_n_s_version); if (unlikely(!__pyx_t_1)) __PYX_ERR(16, 102, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(16, 102, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_family = __pyx_f_7asyncpg_7pgproto_7pgproto__ver_to_family(__pyx_t_4);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":103
+ *     ipnet = _ipnet(obj)
+ *     family = _ver_to_family(ipnet.version)
+ *     _net_encode(buf, family, ipnet.prefixlen, 1, ipnet.network_address.packed)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_ipnet, __pyx_n_s_prefixlen); if (unlikely(!__pyx_t_1)) __PYX_ERR(16, 103, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_5 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(16, 103, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_ipnet, __pyx_n_s_network_address); if (unlikely(!__pyx_t_1)) __PYX_ERR(16, 103, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_packed); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 103, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(16, 103, __pyx_L1_error)
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto__net_encode(__pyx_v_buf, __pyx_v_family, __pyx_t_5, 1, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(16, 103, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":96
+ * 
+ * 
+ * cdef cidr_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         object ipnet
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.cidr_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_ipnet);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/network.pyx":106
+ * 
+ * 
+ * cdef inet_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         object ipaddr
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_inet_encode(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_ipaddr = 0;
+  int8_t __pyx_v_family;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int32_t __pyx_t_7;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("inet_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/network.pyx":111
+ *         int8_t family
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         ipaddr = _ipaddr(obj)
+ *     except ValueError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_1);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/network.pyx":112
+ * 
+ *     try:
+ *         ipaddr = _ipaddr(obj)             # <<<<<<<<<<<<<<
+ *     except ValueError:
+ *         # PostgreSQL accepts *both* CIDR and host values
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ipaddr); if (unlikely(!__pyx_t_5)) __PYX_ERR(16, 112, __pyx_L3_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_obj);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 112, __pyx_L3_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_v_ipaddr = __pyx_t_4;
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/pgproto/codecs/network.pyx":111
+ *         int8_t family
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         ipaddr = _ipaddr(obj)
+ *     except ValueError:
+ */
+    }
+
+    /* "asyncpg/pgproto/codecs/network.pyx":118
+ *         cidr_encode(settings, buf, obj)
+ *     else:
+ *         family = _ver_to_family(ipaddr.version)             # <<<<<<<<<<<<<<
+ *         _net_encode(buf, family, _ip_max_prefix_len(family), 0, ipaddr.packed)
+ */
+    /*else:*/ {
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_ipaddr, __pyx_n_s_version); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 118, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_7 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(16, 118, __pyx_L5_except_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_v_family = __pyx_f_7asyncpg_7pgproto_7pgproto__ver_to_family(__pyx_t_7);
+
+      /* "asyncpg/pgproto/codecs/network.pyx":119
+ *     else:
+ *         family = _ver_to_family(ipaddr.version)
+ *         _net_encode(buf, family, _ip_max_prefix_len(family), 0, ipaddr.packed)             # <<<<<<<<<<<<<<
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_ipaddr, __pyx_n_s_packed); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 119, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(16, 119, __pyx_L5_except_error)
+      __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto__net_encode(__pyx_v_buf, __pyx_v_family, __pyx_f_7asyncpg_7pgproto_7pgproto__ip_max_prefix_len(__pyx_v_family), 0, ((PyObject*)__pyx_t_4)); if (unlikely(!__pyx_t_5)) __PYX_ERR(16, 119, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    }
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":113
+ *     try:
+ *         ipaddr = _ipaddr(obj)
+ *     except ValueError:             # <<<<<<<<<<<<<<
+ *         # PostgreSQL accepts *both* CIDR and host values
+ *         # for the host datatype.
+ */
+    __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
+    if (__pyx_t_8) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.inet_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(16, 113, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_GOTREF(__pyx_t_6);
+
+      /* "asyncpg/pgproto/codecs/network.pyx":116
+ *         # PostgreSQL accepts *both* CIDR and host values
+ *         # for the host datatype.
+ *         cidr_encode(settings, buf, obj)             # <<<<<<<<<<<<<<
+ *     else:
+ *         family = _ver_to_family(ipaddr.version)
+ */
+      __pyx_t_9 = __pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode(__pyx_v_settings, __pyx_v_buf, __pyx_v_obj); if (unlikely(!__pyx_t_9)) __PYX_ERR(16, 116, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/pgproto/codecs/network.pyx":111
+ *         int8_t family
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         ipaddr = _ipaddr(obj)
+ *     except ValueError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/network.pyx":106
+ * 
+ * 
+ * cdef inet_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         object ipaddr
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.inet_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_ipaddr);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/tid.pyx":8
+ * 
+ * 
+ * cdef tid_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef unsigned long block, offset
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_tid_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  int __pyx_v_overflow;
+  unsigned long __pyx_v_block;
+  unsigned long __pyx_v_offset;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  Py_ssize_t __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  unsigned long __pyx_t_10;
+  int __pyx_t_11;
+  __Pyx_RefNannySetupContext("tid_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":9
+ * 
+ * cdef tid_encode(CodecContext settings, WriteBuffer buf, obj):
+ *     cdef int overflow = 0             # <<<<<<<<<<<<<<
+ *     cdef unsigned long block, offset
+ * 
+ */
+  __pyx_v_overflow = 0;
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":12
+ *     cdef unsigned long block, offset
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ */
+  __pyx_t_2 = (PyTuple_Check(__pyx_v_obj) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = (PyList_Check(__pyx_v_obj) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  __pyx_t_2 = ((!__pyx_t_1) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":14
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+ *         raise TypeError(
+ *             'list or tuple expected (got type {})'.format(type(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     if len(obj) != 2:
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_list_or_tuple_expected_got_type, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 14, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, ((PyObject *)Py_TYPE(__pyx_v_obj))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)Py_TYPE(__pyx_v_obj)));
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(17, 14, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":13
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+ *         raise TypeError(             # <<<<<<<<<<<<<<
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(17, 13, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":12
+ *     cdef unsigned long block, offset
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":16
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ * 
+ *     if len(obj) != 2:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'invalid number of elements in tid tuple, expecting 2')
+ */
+  __pyx_t_6 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(17, 16, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_6 != 2) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":17
+ * 
+ *     if len(obj) != 2:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'invalid number of elements in tid tuple, expecting 2')
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 17, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(17, 17, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":16
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ * 
+ *     if len(obj) != 2:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'invalid number of elements in tid tuple, expecting 2')
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":20
+ *             'invalid number of elements in tid tuple, expecting 2')
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         block = cpython.PyLong_AsUnsignedLong(obj[0])
+ *     except OverflowError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+    __Pyx_XGOTREF(__pyx_t_7);
+    __Pyx_XGOTREF(__pyx_t_8);
+    __Pyx_XGOTREF(__pyx_t_9);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":21
+ * 
+ *     try:
+ *         block = cpython.PyLong_AsUnsignedLong(obj[0])             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = 1
+ */
+      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 21, __pyx_L7_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_10 = PyLong_AsUnsignedLong(__pyx_t_4); if (unlikely(__pyx_t_10 == ((unsigned long)-1L) && PyErr_Occurred())) __PYX_ERR(17, 21, __pyx_L7_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_v_block = __pyx_t_10;
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":20
+ *             'invalid number of elements in tid tuple, expecting 2')
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         block = cpython.PyLong_AsUnsignedLong(obj[0])
+ *     except OverflowError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+    goto __pyx_L12_try_end;
+    __pyx_L7_error:;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":22
+ *     try:
+ *         block = cpython.PyLong_AsUnsignedLong(obj[0])
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = 1
+ * 
+ */
+    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_11) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.tid_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_5) < 0) __PYX_ERR(17, 22, __pyx_L9_except_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_GOTREF(__pyx_t_5);
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":23
+ *         block = cpython.PyLong_AsUnsignedLong(obj[0])
+ *     except OverflowError:
+ *         overflow = 1             # <<<<<<<<<<<<<<
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      goto __pyx_L8_exception_handled;
+    }
+    goto __pyx_L9_except_error;
+    __pyx_L9_except_error:;
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":20
+ *             'invalid number of elements in tid tuple, expecting 2')
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         block = cpython.PyLong_AsUnsignedLong(obj[0])
+ *     except OverflowError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+    goto __pyx_L1_error;
+    __pyx_L8_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+    __pyx_L12_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":26
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(block) > 4 and block > UINT32_MAX):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('tuple id block value out of uint32 range')
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_1) {
+  } else {
+    __pyx_t_2 = __pyx_t_1;
+    goto __pyx_L16_bool_binop_done;
+  }
+  __pyx_t_1 = (((sizeof(__pyx_v_block)) > 4) != 0);
+  if (__pyx_t_1) {
+  } else {
+    __pyx_t_2 = __pyx_t_1;
+    goto __pyx_L16_bool_binop_done;
+  }
+  __pyx_t_1 = ((__pyx_v_block > UINT32_MAX) != 0);
+  __pyx_t_2 = __pyx_t_1;
+  __pyx_L16_bool_binop_done:;
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":27
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(block) > 4 and block > UINT32_MAX):
+ *         raise OverflowError('tuple id block value out of uint32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_OverflowError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(17, 27, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __PYX_ERR(17, 27, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":26
+ * 
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(block) > 4 and block > UINT32_MAX):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('tuple id block value out of uint32 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":29
+ *         raise OverflowError('tuple id block value out of uint32 range')
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         offset = cpython.PyLong_AsUnsignedLong(obj[1])
+ *         overflow = 0
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
+    __Pyx_XGOTREF(__pyx_t_9);
+    __Pyx_XGOTREF(__pyx_t_8);
+    __Pyx_XGOTREF(__pyx_t_7);
+    /*try:*/ {
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":30
+ * 
+ *     try:
+ *         offset = cpython.PyLong_AsUnsignedLong(obj[1])             # <<<<<<<<<<<<<<
+ *         overflow = 0
+ *     except OverflowError:
+ */
+      __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(17, 30, __pyx_L19_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_10 = PyLong_AsUnsignedLong(__pyx_t_5); if (unlikely(__pyx_t_10 == ((unsigned long)-1L) && PyErr_Occurred())) __PYX_ERR(17, 30, __pyx_L19_error)
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_v_offset = __pyx_t_10;
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":31
+ *     try:
+ *         offset = cpython.PyLong_AsUnsignedLong(obj[1])
+ *         overflow = 0             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = 1
+ */
+      __pyx_v_overflow = 0;
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":29
+ *         raise OverflowError('tuple id block value out of uint32 range')
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         offset = cpython.PyLong_AsUnsignedLong(obj[1])
+ *         overflow = 0
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    goto __pyx_L24_try_end;
+    __pyx_L19_error:;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":32
+ *         offset = cpython.PyLong_AsUnsignedLong(obj[1])
+ *         overflow = 0
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = 1
+ * 
+ */
+    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_11) {
+      __Pyx_AddTraceback("asyncpg.pgproto.pgproto.tid_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(17, 32, __pyx_L21_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_GOTREF(__pyx_t_4);
+
+      /* "asyncpg/pgproto/codecs/tid.pyx":33
+ *         overflow = 0
+ *     except OverflowError:
+ *         overflow = 1             # <<<<<<<<<<<<<<
+ * 
+ *     if overflow or offset > 65535:
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      goto __pyx_L20_exception_handled;
+    }
+    goto __pyx_L21_except_error;
+    __pyx_L21_except_error:;
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":29
+ *         raise OverflowError('tuple id block value out of uint32 range')
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         offset = cpython.PyLong_AsUnsignedLong(obj[1])
+ *         overflow = 0
+ */
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_8, __pyx_t_7);
+    goto __pyx_L1_error;
+    __pyx_L20_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_8, __pyx_t_7);
+    __pyx_L24_try_end:;
+  }
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":35
+ *         overflow = 1
+ * 
+ *     if overflow or offset > 65535:             # <<<<<<<<<<<<<<
+ *         raise OverflowError('tuple id offset value out of uint16 range')
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_1) {
+  } else {
+    __pyx_t_2 = __pyx_t_1;
+    goto __pyx_L28_bool_binop_done;
+  }
+  __pyx_t_1 = ((__pyx_v_offset > 0xFFFF) != 0);
+  __pyx_t_2 = __pyx_t_1;
+  __pyx_L28_bool_binop_done:;
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":36
+ * 
+ *     if overflow or offset > 65535:
+ *         raise OverflowError('tuple id offset value out of uint16 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(6)
+ */
+    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_OverflowError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 36, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(17, 36, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/tid.pyx":35
+ *         overflow = 1
+ * 
+ *     if overflow or offset > 65535:             # <<<<<<<<<<<<<<
+ *         raise OverflowError('tuple id offset value out of uint16 range')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":38
+ *         raise OverflowError('tuple id offset value out of uint16 range')
+ * 
+ *     buf.write_int32(6)             # <<<<<<<<<<<<<<
+ *     buf.write_int32(<int32_t>block)
+ *     buf.write_int16(<int16_t>offset)
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, 6); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":39
+ * 
+ *     buf.write_int32(6)
+ *     buf.write_int32(<int32_t>block)             # <<<<<<<<<<<<<<
+ *     buf.write_int16(<int16_t>offset)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, ((int32_t)__pyx_v_block)); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":40
+ *     buf.write_int32(6)
+ *     buf.write_int32(<int32_t>block)
+ *     buf.write_int16(<int16_t>offset)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16(__pyx_v_buf, ((int16_t)__pyx_v_offset)); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 40, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":8
+ * 
+ * 
+ * cdef tid_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef int overflow = 0
+ *     cdef unsigned long block, offset
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.tid_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/tid.pyx":43
+ * 
+ * 
+ * cdef tid_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint32_t block
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_tid_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  uint32_t __pyx_v_block;
+  uint16_t __pyx_v_offset;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("tid_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":48
+ *         uint16_t offset
+ * 
+ *     block = <uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     offset = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(17, 48, __pyx_L1_error)
+  __pyx_v_block = ((uint32_t)unpack_int32(__pyx_t_1));
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":49
+ * 
+ *     block = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *     offset = <uint16_t>hton.unpack_int16(frb_read(buf, 2))             # <<<<<<<<<<<<<<
+ * 
+ *     return (block, offset)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 2); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(17, 49, __pyx_L1_error)
+  __pyx_v_offset = ((uint16_t)unpack_int16(__pyx_t_1));
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":51
+ *     offset = <uint16_t>hton.unpack_int16(frb_read(buf, 2))
+ * 
+ *     return (block, offset)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_block); if (unlikely(!__pyx_t_2)) __PYX_ERR(17, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyInt_From_uint16_t(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(17, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(17, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
+  __pyx_t_2 = 0;
+  __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_4;
+  __pyx_t_4 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":43
+ * 
+ * 
+ * cdef tid_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint32_t block
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.tid_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/txid.pyx":8
+ * 
+ * 
+ * cdef txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ssize_t nxip
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_encode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  Py_ssize_t __pyx_v_nxip;
+  CYTHON_UNUSED int64_t __pyx_v_xmin;
+  CYTHON_UNUSED int64_t __pyx_v_xmax;
+  int __pyx_v_i;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_xip_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  Py_ssize_t __pyx_t_6;
+  int64_t __pyx_t_7;
+  Py_ssize_t __pyx_t_8;
+  Py_ssize_t __pyx_t_9;
+  int __pyx_t_10;
+  int32_t __pyx_t_11;
+  __Pyx_RefNannySetupContext("txid_snapshot_encode", 0);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":14
+ *         int64_t xmax
+ *         int i
+ *         WriteBuffer xip_buf = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new()); if (unlikely(!__pyx_t_1)) __PYX_ERR(18, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_xip_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":16
+ *         WriteBuffer xip_buf = WriteBuffer.new()
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ */
+  __pyx_t_3 = (PyTuple_Check(__pyx_v_obj) != 0);
+  if (!__pyx_t_3) {
+  } else {
+    __pyx_t_2 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_3 = (PyList_Check(__pyx_v_obj) != 0);
+  __pyx_t_2 = __pyx_t_3;
+  __pyx_L4_bool_binop_done:;
+  __pyx_t_3 = ((!__pyx_t_2) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":18
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+ *         raise TypeError(
+ *             'list or tuple expected (got type {})'.format(type(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     if len(obj) != 3:
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_list_or_tuple_expected_got_type, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 18, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, ((PyObject *)Py_TYPE(__pyx_v_obj))) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)Py_TYPE(__pyx_v_obj)));
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(18, 18, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":17
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
+ *         raise TypeError(             # <<<<<<<<<<<<<<
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 17, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(18, 17, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":16
+ *         WriteBuffer xip_buf = WriteBuffer.new()
+ * 
+ *     if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":20
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ * 
+ *     if len(obj) != 3:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'invalid number of elements in txid_snapshot tuple, expecting 4')
+ */
+  __pyx_t_6 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(18, 20, __pyx_L1_error)
+  __pyx_t_3 = ((__pyx_t_6 != 3) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":21
+ * 
+ *     if len(obj) != 3:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'invalid number of elements in txid_snapshot tuple, expecting 4')
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 21, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(18, 21, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":20
+ *             'list or tuple expected (got type {})'.format(type(obj)))
+ * 
+ *     if len(obj) != 3:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'invalid number of elements in txid_snapshot tuple, expecting 4')
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":24
+ *             'invalid number of elements in txid_snapshot tuple, expecting 4')
+ * 
+ *     nxip = len(obj[2])             # <<<<<<<<<<<<<<
+ *     if nxip > _MAXINT32:
+ *         raise ValueError('txid_snapshot value is too long')
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 24, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_6 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(18, 24, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_nxip = __pyx_t_6;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":25
+ * 
+ *     nxip = len(obj[2])
+ *     if nxip > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('txid_snapshot value is too long')
+ * 
+ */
+  __pyx_t_3 = ((__pyx_v_nxip > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":26
+ *     nxip = len(obj[2])
+ *     if nxip > _MAXINT32:
+ *         raise ValueError('txid_snapshot value is too long')             # <<<<<<<<<<<<<<
+ * 
+ *     xmin = obj[0]
+ */
+    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 26, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(18, 26, __pyx_L1_error)
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":25
+ * 
+ *     nxip = len(obj[2])
+ *     if nxip > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('txid_snapshot value is too long')
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":28
+ *         raise ValueError('txid_snapshot value is too long')
+ * 
+ *     xmin = obj[0]             # <<<<<<<<<<<<<<
+ *     xmax = obj[1]
+ * 
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(18, 28, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_xmin = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":29
+ * 
+ *     xmin = obj[0]
+ *     xmax = obj[1]             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(nxip):
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 29, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(18, 29, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_xmax = __pyx_t_7;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":31
+ *     xmax = obj[1]
+ * 
+ *     for i in range(nxip):             # <<<<<<<<<<<<<<
+ *         xip_buf.write_int64(obj[2][i])
+ * 
+ */
+  __pyx_t_8 = __pyx_v_nxip;
+  __pyx_t_9 = __pyx_t_8;
+  for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
+    __pyx_v_i = __pyx_t_10;
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":32
+ * 
+ *     for i in range(nxip):
+ *         xip_buf.write_int64(obj[2][i])             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(20 + xip_buf.len())
+ */
+    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 32, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(18, 32, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_1); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(18, 32, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_xip_buf, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(18, 32, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":34
+ *         xip_buf.write_int64(obj[2][i])
+ * 
+ *     buf.write_int32(20 + xip_buf.len())             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(<int32_t>nxip)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_xip_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(18, 34, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = __Pyx_PyInt_AddCObj(__pyx_int_20, __pyx_t_1, 20, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 34, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_11 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(18, 34, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 34, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":36
+ *     buf.write_int32(20 + xip_buf.len())
+ * 
+ *     buf.write_int32(<int32_t>nxip)             # <<<<<<<<<<<<<<
+ *     buf.write_int64(obj[0])
+ *     buf.write_int64(obj[1])
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32(__pyx_v_buf, ((int32_t)__pyx_v_nxip)); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":37
+ * 
+ *     buf.write_int32(<int32_t>nxip)
+ *     buf.write_int64(obj[0])             # <<<<<<<<<<<<<<
+ *     buf.write_int64(obj[1])
+ *     buf.write_buffer(xip_buf)
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(18, 37, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":38
+ *     buf.write_int32(<int32_t>nxip)
+ *     buf.write_int64(obj[0])
+ *     buf.write_int64(obj[1])             # <<<<<<<<<<<<<<
+ *     buf.write_buffer(xip_buf)
+ * 
+ */
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(18, 38, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64(__pyx_v_buf, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":39
+ *     buf.write_int64(obj[0])
+ *     buf.write_int64(obj[1])
+ *     buf.write_buffer(xip_buf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_buffer(__pyx_v_buf, __pyx_v_xip_buf); if (unlikely(!__pyx_t_4)) __PYX_ERR(18, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":8
+ * 
+ * 
+ * cdef txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ssize_t nxip
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.txid_snapshot_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_xip_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/codecs/txid.pyx":42
+ * 
+ * 
+ * cdef txid_snapshot_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t nxip
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  int32_t __pyx_v_nxip;
+  int64_t __pyx_v_xmin;
+  int64_t __pyx_v_xmax;
+  PyObject *__pyx_v_xip_tup = 0;
+  int32_t __pyx_v_i;
+  PyObject *__pyx_v_xip = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  int32_t __pyx_t_3;
+  int32_t __pyx_t_4;
+  int32_t __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("txid_snapshot_decode", 0);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":51
+ *         object xip
+ * 
+ *     nxip = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     xmin = hton.unpack_int64(frb_read(buf, 8))
+ *     xmax = hton.unpack_int64(frb_read(buf, 8))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(18, 51, __pyx_L1_error)
+  __pyx_v_nxip = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":52
+ * 
+ *     nxip = hton.unpack_int32(frb_read(buf, 4))
+ *     xmin = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ *     xmax = hton.unpack_int64(frb_read(buf, 8))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(18, 52, __pyx_L1_error)
+  __pyx_v_xmin = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":53
+ *     nxip = hton.unpack_int32(frb_read(buf, 4))
+ *     xmin = hton.unpack_int64(frb_read(buf, 8))
+ *     xmax = hton.unpack_int64(frb_read(buf, 8))             # <<<<<<<<<<<<<<
+ * 
+ *     xip_tup = cpython.PyTuple_New(nxip)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(18, 53, __pyx_L1_error)
+  __pyx_v_xmax = unpack_int64(__pyx_t_1);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":55
+ *     xmax = hton.unpack_int64(frb_read(buf, 8))
+ * 
+ *     xip_tup = cpython.PyTuple_New(nxip)             # <<<<<<<<<<<<<<
+ *     for i in range(nxip):
+ *         xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+ */
+  __pyx_t_2 = PyTuple_New(__pyx_v_nxip); if (unlikely(!__pyx_t_2)) __PYX_ERR(18, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_xip_tup = ((PyObject*)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":56
+ * 
+ *     xip_tup = cpython.PyTuple_New(nxip)
+ *     for i in range(nxip):             # <<<<<<<<<<<<<<
+ *         xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+ *         cpython.Py_INCREF(xip)
+ */
+  __pyx_t_3 = __pyx_v_nxip;
+  __pyx_t_4 = __pyx_t_3;
+  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
+    __pyx_v_i = __pyx_t_5;
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":57
+ *     xip_tup = cpython.PyTuple_New(nxip)
+ *     for i in range(nxip):
+ *         xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))             # <<<<<<<<<<<<<<
+ *         cpython.Py_INCREF(xip)
+ *         cpython.PyTuple_SET_ITEM(xip_tup, i, xip)
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 8); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(18, 57, __pyx_L1_error)
+    __pyx_t_2 = PyLong_FromLongLong(unpack_int64(__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(18, 57, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_XDECREF_SET(__pyx_v_xip, __pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":58
+ *     for i in range(nxip):
+ *         xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+ *         cpython.Py_INCREF(xip)             # <<<<<<<<<<<<<<
+ *         cpython.PyTuple_SET_ITEM(xip_tup, i, xip)
+ * 
+ */
+    Py_INCREF(__pyx_v_xip);
+
+    /* "asyncpg/pgproto/codecs/txid.pyx":59
+ *         xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
+ *         cpython.Py_INCREF(xip)
+ *         cpython.PyTuple_SET_ITEM(xip_tup, i, xip)             # <<<<<<<<<<<<<<
+ * 
+ *     return (xmin, xmax, xip_tup)
+ */
+    PyTuple_SET_ITEM(__pyx_v_xip_tup, __pyx_v_i, __pyx_v_xip);
+  }
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":61
+ *         cpython.PyTuple_SET_ITEM(xip_tup, i, xip)
+ * 
+ *     return (xmin, xmax, xip_tup)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_xmin); if (unlikely(!__pyx_t_2)) __PYX_ERR(18, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_6 = __Pyx_PyInt_From_int64_t(__pyx_v_xmax); if (unlikely(!__pyx_t_6)) __PYX_ERR(18, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(18, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_6);
+  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
+  __Pyx_INCREF(__pyx_v_xip_tup);
+  __Pyx_GIVEREF(__pyx_v_xip_tup);
+  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_xip_tup);
+  __pyx_t_2 = 0;
+  __pyx_t_6 = 0;
+  __pyx_r = __pyx_t_7;
+  __pyx_t_7 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":42
+ * 
+ * 
+ * cdef txid_snapshot_decode(CodecContext settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int32_t nxip
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.txid_snapshot_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_xip_tup);
+  __Pyx_XDECREF(__pyx_v_xip);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0xd41d8cd:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_1__pyx_unpickle_CodecContext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_7pgproto_7pgproto_1__pyx_unpickle_CodecContext = {"__pyx_unpickle_CodecContext", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_7pgproto_7pgproto_1__pyx_unpickle_CodecContext, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_7pgproto_7pgproto_1__pyx_unpickle_CodecContext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v___pyx_type = 0;
+  long __pyx_v___pyx_checksum;
+  PyObject *__pyx_v___pyx_state = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__pyx_unpickle_CodecContext (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CodecContext", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CodecContext", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_CodecContext") < 0)) __PYX_ERR(2, 1, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v___pyx_type = values[0];
+    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error)
+    __pyx_v___pyx_state = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CodecContext", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.__pyx_unpickle_CodecContext", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_v___pyx_PickleError = NULL;
+  PyObject *__pyx_v___pyx_result = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_CodecContext", 0);
+
+  /* "(tree fragment)":2
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0xd41d8cd:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)
+ */
+  __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xd41d8cd) != 0);
+  if (__pyx_t_1) {
+
+    /* "(tree fragment)":3
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0xd41d8cd:
+ *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)
+ *     __pyx_result = CodecContext.__new__(__pyx_type)
+ */
+    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_n_s_PickleError);
+    __Pyx_GIVEREF(__pyx_n_s_PickleError);
+    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
+    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_v___pyx_PickleError = __pyx_t_2;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":4
+ *     if __pyx_checksum != 0xd41d8cd:
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)             # <<<<<<<<<<<<<<
+ *     __pyx_result = CodecContext.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ */
+    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xd4, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_INCREF(__pyx_v___pyx_PickleError);
+    __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(2, 4, __pyx_L1_error)
+
+    /* "(tree fragment)":2
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0xd41d8cd:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)
+ */
+  }
+
+  /* "(tree fragment)":5
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)
+ *     __pyx_result = CodecContext.__new__(__pyx_type)             # <<<<<<<<<<<<<<
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v___pyx_result = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)
+ *     __pyx_result = CodecContext.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  __pyx_t_1 = (__pyx_v___pyx_state != Py_None);
+  __pyx_t_6 = (__pyx_t_1 != 0);
+  if (__pyx_t_6) {
+
+    /* "(tree fragment)":7
+ *     __pyx_result = CodecContext.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):
+ */
+    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error)
+    __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext__set_state(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum)
+ *     __pyx_result = CodecContext.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  }
+
+  /* "(tree fragment)":8
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)
+ *     return __pyx_result             # <<<<<<<<<<<<<<
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):
+ *     if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v___pyx_result);
+  __pyx_r = __pyx_v___pyx_result;
+  goto __pyx_L0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0xd41d8cd:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.__pyx_unpickle_CodecContext", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
+  __Pyx_XDECREF(__pyx_v___pyx_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":9
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[0])
+ */
+
+static PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto___pyx_unpickle_CodecContext__set_state(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  Py_ssize_t __pyx_t_2;
+  int __pyx_t_3;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_CodecContext__set_state", 0);
+
+  /* "(tree fragment)":10
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):
+ *     if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[0])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_2 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __pyx_t_3 = ((__pyx_t_2 > 0) != 0);
+  if (__pyx_t_3) {
+  } else {
+    __pyx_t_1 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_3 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __pyx_t_4 = (__pyx_t_3 != 0);
+  __pyx_t_1 = __pyx_t_4;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "(tree fragment)":11
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):
+ *     if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[0])             # <<<<<<<<<<<<<<
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(__pyx_v___pyx_state == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(2, 11, __pyx_L1_error)
+    }
+    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_8 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+      }
+    }
+    __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "(tree fragment)":10
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):
+ *     if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[0])
+ */
+  }
+
+  /* "(tree fragment)":9
+ *         __pyx_unpickle_CodecContext__set_state(<CodecContext> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CodecContext__set_state(CodecContext __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[0])
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.__pyx_unpickle_CodecContext__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":14
+ *         ssize_t len
+ * 
+ *     inline ssize_t frb_get_len(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         return frb.len
+ * 
+ */
+
+static CYTHON_INLINE Py_ssize_t __pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb) {
+  Py_ssize_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("frb_get_len", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":15
+ * 
+ *     inline ssize_t frb_get_len(FRBuffer *frb):
+ *         return frb.len             # <<<<<<<<<<<<<<
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):
+ */
+  __pyx_r = __pyx_v_frb->len;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":14
+ *         ssize_t len
+ * 
+ *     inline ssize_t frb_get_len(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         return frb.len
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":17
+ *         return frb.len
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):             # <<<<<<<<<<<<<<
+ *         frb.len = new_len
+ * 
+ */
+
+static CYTHON_INLINE void __pyx_f_7asyncpg_7pgproto_7pgproto_frb_set_len(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, Py_ssize_t __pyx_v_new_len) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("frb_set_len", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":18
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):
+ *         frb.len = new_len             # <<<<<<<<<<<<<<
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+ */
+  __pyx_v_frb->len = __pyx_v_new_len;
+
+  /* "asyncpg/pgproto/frb.pxd":17
+ *         return frb.len
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):             # <<<<<<<<<<<<<<
+ *         frb.len = new_len
+ * 
+ */
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "asyncpg/pgproto/frb.pxd":20
+ *         frb.len = new_len
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):             # <<<<<<<<<<<<<<
+ *         frb.buf = buf
+ *         frb.len = len
+ */
+
+static CYTHON_INLINE void __pyx_f_7asyncpg_7pgproto_7pgproto_frb_init(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, char const *__pyx_v_buf, Py_ssize_t __pyx_v_len) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("frb_init", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":21
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+ *         frb.buf = buf             # <<<<<<<<<<<<<<
+ *         frb.len = len
+ * 
+ */
+  __pyx_v_frb->buf = __pyx_v_buf;
+
+  /* "asyncpg/pgproto/frb.pxd":22
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+ *         frb.buf = buf
+ *         frb.len = len             # <<<<<<<<<<<<<<
+ * 
+ *     inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:
+ */
+  __pyx_v_frb->len = __pyx_v_len;
+
+  /* "asyncpg/pgproto/frb.pxd":20
+ *         frb.len = new_len
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):             # <<<<<<<<<<<<<<
+ *         frb.buf = buf
+ *         frb.len = len
+ */
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "asyncpg/pgproto/frb.pxd":24
+ *         frb.len = len
+ * 
+ *     inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ * 
+ */
+
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, Py_ssize_t __pyx_v_n) {
+  char const *__pyx_v_result;
+  char const *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  char const *__pyx_t_3;
+  __Pyx_RefNannySetupContext("frb_read", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":27
+ *         cdef const char *result
+ * 
+ *         if n > frb.len:             # <<<<<<<<<<<<<<
+ *             frb_check(frb, n)
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_n > __pyx_v_frb->len) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/frb.pxd":28
+ * 
+ *         if n > frb.len:
+ *             frb_check(frb, n)             # <<<<<<<<<<<<<<
+ * 
+ *         result = frb.buf
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_check(__pyx_v_frb, __pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 28, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/frb.pxd":27
+ *         cdef const char *result
+ * 
+ *         if n > frb.len:             # <<<<<<<<<<<<<<
+ *             frb_check(frb, n)
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/frb.pxd":30
+ *             frb_check(frb, n)
+ * 
+ *         result = frb.buf             # <<<<<<<<<<<<<<
+ *         frb.buf += n
+ *         frb.len -= n
+ */
+  __pyx_t_3 = __pyx_v_frb->buf;
+  __pyx_v_result = __pyx_t_3;
+
+  /* "asyncpg/pgproto/frb.pxd":31
+ * 
+ *         result = frb.buf
+ *         frb.buf += n             # <<<<<<<<<<<<<<
+ *         frb.len -= n
+ * 
+ */
+  __pyx_v_frb->buf = (__pyx_v_frb->buf + __pyx_v_n);
+
+  /* "asyncpg/pgproto/frb.pxd":32
+ *         result = frb.buf
+ *         frb.buf += n
+ *         frb.len -= n             # <<<<<<<<<<<<<<
+ * 
+ *         return result
+ */
+  __pyx_v_frb->len = (__pyx_v_frb->len - __pyx_v_n);
+
+  /* "asyncpg/pgproto/frb.pxd":34
+ *         frb.len -= n
+ * 
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     inline const char* frb_read_all(FRBuffer *frb):
+ */
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":24
+ *         frb.len = len
+ * 
+ *     inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.frb_read", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":36
+ *         return result
+ * 
+ *     inline const char* frb_read_all(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ *         result = frb.buf
+ */
+
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb) {
+  char const *__pyx_v_result;
+  char const *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  __Pyx_RefNannySetupContext("frb_read_all", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":38
+ *     inline const char* frb_read_all(FRBuffer *frb):
+ *         cdef const char *result
+ *         result = frb.buf             # <<<<<<<<<<<<<<
+ *         frb.buf += frb.len
+ *         frb.len = 0
+ */
+  __pyx_t_1 = __pyx_v_frb->buf;
+  __pyx_v_result = __pyx_t_1;
+
+  /* "asyncpg/pgproto/frb.pxd":39
+ *         cdef const char *result
+ *         result = frb.buf
+ *         frb.buf += frb.len             # <<<<<<<<<<<<<<
+ *         frb.len = 0
+ *         return result
+ */
+  __pyx_v_frb->buf = (__pyx_v_frb->buf + __pyx_v_frb->len);
+
+  /* "asyncpg/pgproto/frb.pxd":40
+ *         result = frb.buf
+ *         frb.buf += frb.len
+ *         frb.len = 0             # <<<<<<<<<<<<<<
+ *         return result
+ * 
+ */
+  __pyx_v_frb->len = 0;
+
+  /* "asyncpg/pgproto/frb.pxd":41
+ *         frb.buf += frb.len
+ *         frb.len = 0
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,
+ */
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":36
+ *         return result
+ * 
+ *     inline const char* frb_read_all(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ *         result = frb.buf
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":43
+ *         return result
+ * 
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,             # <<<<<<<<<<<<<<
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)
+ */
+
+static CYTHON_INLINE struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_source, Py_ssize_t __pyx_v_len) {
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  __Pyx_RefNannySetupContext("frb_slice_from", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":45
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)             # <<<<<<<<<<<<<<
+ *         frb.len = len
+ *         return frb
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_source, __pyx_v_len); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(19, 45, __pyx_L1_error)
+  __pyx_v_frb->buf = __pyx_t_1;
+
+  /* "asyncpg/pgproto/frb.pxd":46
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)
+ *         frb.len = len             # <<<<<<<<<<<<<<
+ *         return frb
+ * 
+ */
+  __pyx_v_frb->len = __pyx_v_len;
+
+  /* "asyncpg/pgproto/frb.pxd":47
+ *         frb.buf = frb_read(source, len)
+ *         frb.len = len
+ *         return frb             # <<<<<<<<<<<<<<
+ * 
+ *     object frb_check(FRBuffer *frb, ssize_t n)
+ */
+  __pyx_r = __pyx_v_frb;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":43
+ *         return result
+ * 
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,             # <<<<<<<<<<<<<<
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_WriteUnraisable("asyncpg.pgproto.pgproto.frb_slice_from", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":28
+ *         bint _message_mode
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("len", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":29
+ * 
+ *     cdef inline len(self):
+ *         return self._length             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _check_readonly(self)
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(20, 29, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":28
+ *         bint _message_mode
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.len", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":94
+ *         bint _current_message_ready
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("len", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":95
+ * 
+ *     cdef inline len(self):
+ *         return self._length             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline char get_message_type(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(20, 95, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":94
+ *         bint _current_message_ready
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.len", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":97
+ *         return self._length
+ * 
+ *     cdef inline char get_message_type(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_type
+ * 
+ */
+
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  char __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_message_type", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":98
+ * 
+ *     cdef inline char get_message_type(self):
+ *         return self._current_message_type             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline int32_t get_message_length(self):
+ */
+  __pyx_r = __pyx_v_self->_current_message_type;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":97
+ *         return self._length
+ * 
+ *     cdef inline char get_message_type(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_type
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":100
+ *         return self._current_message_type
+ * 
+ *     cdef inline int32_t get_message_length(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_len
+ * 
+ */
+
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_message_length", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":101
+ * 
+ *     cdef inline int32_t get_message_length(self):
+ *         return self._current_message_len             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline read_utf8(self):
+ */
+  __pyx_r = __pyx_v_self->_current_message_len;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":100
+ *         return self._current_message_type
+ * 
+ *     cdef inline int32_t get_message_length(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_len
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":103
+ *         return self._current_message_len
+ * 
+ *     cdef inline read_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self.read_cstr().decode('utf-8')
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("read_utf8", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":104
+ * 
+ *     cdef inline read_utf8(self):
+ *         return self.read_cstr().decode('utf-8')             # <<<<<<<<<<<<<<
+ * 
+ *     cdef feed_data(self, data)
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_cstr(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(20, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_decode); if (unlikely(!__pyx_t_3)) __PYX_ERR(20, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_utf_8);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(20, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":103
+ *         return self._current_message_len
+ * 
+ *     cdef inline read_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self.read_cstr().decode('utf-8')
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_utf8", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":104
+ * # Datetime C API initialization function.
+ * # You have to call it before any usage of DateTime CAPI functions.
+ * cdef inline void import_datetime():             # <<<<<<<<<<<<<<
+ *     PyDateTime_IMPORT
+ * 
+ */
+
+static CYTHON_INLINE void __pyx_f_7cpython_8datetime_import_datetime(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("import_datetime", 0);
+
+  /* "cpython/datetime.pxd":105
+ * # You have to call it before any usage of DateTime CAPI functions.
+ * cdef inline void import_datetime():
+ *     PyDateTime_IMPORT             # <<<<<<<<<<<<<<
+ * 
+ * # Create date object using DateTime CAPI factory function.
+ */
+  (void)(PyDateTime_IMPORT);
+
+  /* "cpython/datetime.pxd":104
+ * # Datetime C API initialization function.
+ * # You have to call it before any usage of DateTime CAPI functions.
+ * cdef inline void import_datetime():             # <<<<<<<<<<<<<<
+ *     PyDateTime_IMPORT
+ * 
+ */
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "cpython/datetime.pxd":109
+ * # Create date object using DateTime CAPI factory function.
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object date_new(int year, int month, int day):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType)
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_date_new(int __pyx_v_year, int __pyx_v_month, int __pyx_v_day) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("date_new", 0);
+
+  /* "cpython/datetime.pxd":110
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object date_new(int year, int month, int day):
+ *     return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType)             # <<<<<<<<<<<<<<
+ * 
+ * # Create time object using DateTime CAPI factory function
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyDateTimeAPI->Date_FromDate(__pyx_v_year, __pyx_v_month, __pyx_v_day, PyDateTimeAPI->DateType); if (unlikely(!__pyx_t_1)) __PYX_ERR(21, 110, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":109
+ * # Create date object using DateTime CAPI factory function.
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object date_new(int year, int month, int day):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cpython.datetime.date_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":114
+ * # Create time object using DateTime CAPI factory function
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object time_new(int hour, int minute, int second, int microsecond, object tz):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.Time_FromTime(hour, minute, second, microsecond, tz, PyDateTimeAPI.TimeType)
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_time_new(int __pyx_v_hour, int __pyx_v_minute, int __pyx_v_second, int __pyx_v_microsecond, PyObject *__pyx_v_tz) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("time_new", 0);
+
+  /* "cpython/datetime.pxd":115
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object time_new(int hour, int minute, int second, int microsecond, object tz):
+ *     return PyDateTimeAPI.Time_FromTime(hour, minute, second, microsecond, tz, PyDateTimeAPI.TimeType)             # <<<<<<<<<<<<<<
+ * 
+ * # Create datetime object using DateTime CAPI factory function.
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyDateTimeAPI->Time_FromTime(__pyx_v_hour, __pyx_v_minute, __pyx_v_second, __pyx_v_microsecond, __pyx_v_tz, PyDateTimeAPI->TimeType); if (unlikely(!__pyx_t_1)) __PYX_ERR(21, 115, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":114
+ * # Create time object using DateTime CAPI factory function
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object time_new(int hour, int minute, int second, int microsecond, object tz):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.Time_FromTime(hour, minute, second, microsecond, tz, PyDateTimeAPI.TimeType)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cpython.datetime.time_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":119
+ * # Create datetime object using DateTime CAPI factory function.
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.DateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond, tz, PyDateTimeAPI.DateTimeType)
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_datetime_new(int __pyx_v_year, int __pyx_v_month, int __pyx_v_day, int __pyx_v_hour, int __pyx_v_minute, int __pyx_v_second, int __pyx_v_microsecond, PyObject *__pyx_v_tz) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("datetime_new", 0);
+
+  /* "cpython/datetime.pxd":120
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz):
+ *     return PyDateTimeAPI.DateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond, tz, PyDateTimeAPI.DateTimeType)             # <<<<<<<<<<<<<<
+ * 
+ * # Create timedelta object using DateTime CAPI factory function.
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyDateTimeAPI->DateTime_FromDateAndTime(__pyx_v_year, __pyx_v_month, __pyx_v_day, __pyx_v_hour, __pyx_v_minute, __pyx_v_second, __pyx_v_microsecond, __pyx_v_tz, PyDateTimeAPI->DateTimeType); if (unlikely(!__pyx_t_1)) __PYX_ERR(21, 120, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":119
+ * # Create datetime object using DateTime CAPI factory function.
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object datetime_new(int year, int month, int day, int hour, int minute, int second, int microsecond, object tz):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.DateTime_FromDateAndTime(year, month, day, hour, minute, second, microsecond, tz, PyDateTimeAPI.DateTimeType)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cpython.datetime.datetime_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":124
+ * # Create timedelta object using DateTime CAPI factory function.
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object timedelta_new(int days, int seconds, int useconds):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, PyDateTimeAPI.DeltaType)
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_timedelta_new(int __pyx_v_days, int __pyx_v_seconds, int __pyx_v_useconds) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("timedelta_new", 0);
+
+  /* "cpython/datetime.pxd":125
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object timedelta_new(int days, int seconds, int useconds):
+ *     return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, PyDateTimeAPI.DeltaType)             # <<<<<<<<<<<<<<
+ * 
+ * # More recognizable getters for date/time/datetime/timedelta.
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyDateTimeAPI->Delta_FromDelta(__pyx_v_days, __pyx_v_seconds, __pyx_v_useconds, 1, PyDateTimeAPI->DeltaType); if (unlikely(!__pyx_t_1)) __PYX_ERR(21, 125, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":124
+ * # Create timedelta object using DateTime CAPI factory function.
+ * # Note, there are no range checks for any of the arguments.
+ * cdef inline object timedelta_new(int days, int seconds, int useconds):             # <<<<<<<<<<<<<<
+ *     return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, PyDateTimeAPI.DeltaType)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cpython.datetime.timedelta_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":133
+ * 
+ * # Get tzinfo of time
+ * cdef inline object time_tzinfo(object o):             # <<<<<<<<<<<<<<
+ *     if (<PyDateTime_Time*>o).hastzinfo:
+ *         return <object>(<PyDateTime_Time*>o).tzinfo
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_time_tzinfo(PyObject *__pyx_v_o) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("time_tzinfo", 0);
+
+  /* "cpython/datetime.pxd":134
+ * # Get tzinfo of time
+ * cdef inline object time_tzinfo(object o):
+ *     if (<PyDateTime_Time*>o).hastzinfo:             # <<<<<<<<<<<<<<
+ *         return <object>(<PyDateTime_Time*>o).tzinfo
+ *     else:
+ */
+  __pyx_t_1 = (((PyDateTime_Time *)__pyx_v_o)->hastzinfo != 0);
+  if (__pyx_t_1) {
+
+    /* "cpython/datetime.pxd":135
+ * cdef inline object time_tzinfo(object o):
+ *     if (<PyDateTime_Time*>o).hastzinfo:
+ *         return <object>(<PyDateTime_Time*>o).tzinfo             # <<<<<<<<<<<<<<
+ *     else:
+ *         return None
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(((PyObject *)((PyDateTime_Time *)__pyx_v_o)->tzinfo));
+    __pyx_r = ((PyObject *)((PyDateTime_Time *)__pyx_v_o)->tzinfo);
+    goto __pyx_L0;
+
+    /* "cpython/datetime.pxd":134
+ * # Get tzinfo of time
+ * cdef inline object time_tzinfo(object o):
+ *     if (<PyDateTime_Time*>o).hastzinfo:             # <<<<<<<<<<<<<<
+ *         return <object>(<PyDateTime_Time*>o).tzinfo
+ *     else:
+ */
+  }
+
+  /* "cpython/datetime.pxd":137
+ *         return <object>(<PyDateTime_Time*>o).tzinfo
+ *     else:
+ *         return None             # <<<<<<<<<<<<<<
+ * 
+ * # Get tzinfo of datetime
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+  }
+
+  /* "cpython/datetime.pxd":133
+ * 
+ * # Get tzinfo of time
+ * cdef inline object time_tzinfo(object o):             # <<<<<<<<<<<<<<
+ *     if (<PyDateTime_Time*>o).hastzinfo:
+ *         return <object>(<PyDateTime_Time*>o).tzinfo
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":140
+ * 
+ * # Get tzinfo of datetime
+ * cdef inline object datetime_tzinfo(object o):             # <<<<<<<<<<<<<<
+ *     if (<PyDateTime_DateTime*>o).hastzinfo:
+ *         return <object>(<PyDateTime_DateTime*>o).tzinfo
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7cpython_8datetime_datetime_tzinfo(PyObject *__pyx_v_o) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("datetime_tzinfo", 0);
+
+  /* "cpython/datetime.pxd":141
+ * # Get tzinfo of datetime
+ * cdef inline object datetime_tzinfo(object o):
+ *     if (<PyDateTime_DateTime*>o).hastzinfo:             # <<<<<<<<<<<<<<
+ *         return <object>(<PyDateTime_DateTime*>o).tzinfo
+ *     else:
+ */
+  __pyx_t_1 = (((PyDateTime_DateTime *)__pyx_v_o)->hastzinfo != 0);
+  if (__pyx_t_1) {
+
+    /* "cpython/datetime.pxd":142
+ * cdef inline object datetime_tzinfo(object o):
+ *     if (<PyDateTime_DateTime*>o).hastzinfo:
+ *         return <object>(<PyDateTime_DateTime*>o).tzinfo             # <<<<<<<<<<<<<<
+ *     else:
+ *         return None
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(((PyObject *)((PyDateTime_DateTime *)__pyx_v_o)->tzinfo));
+    __pyx_r = ((PyObject *)((PyDateTime_DateTime *)__pyx_v_o)->tzinfo);
+    goto __pyx_L0;
+
+    /* "cpython/datetime.pxd":141
+ * # Get tzinfo of datetime
+ * cdef inline object datetime_tzinfo(object o):
+ *     if (<PyDateTime_DateTime*>o).hastzinfo:             # <<<<<<<<<<<<<<
+ *         return <object>(<PyDateTime_DateTime*>o).tzinfo
+ *     else:
+ */
+  }
+
+  /* "cpython/datetime.pxd":144
+ *         return <object>(<PyDateTime_DateTime*>o).tzinfo
+ *     else:
+ *         return None             # <<<<<<<<<<<<<<
+ * 
+ * # Get year of date
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+  }
+
+  /* "cpython/datetime.pxd":140
+ * 
+ * # Get tzinfo of datetime
+ * cdef inline object datetime_tzinfo(object o):             # <<<<<<<<<<<<<<
+ *     if (<PyDateTime_DateTime*>o).hastzinfo:
+ *         return <object>(<PyDateTime_DateTime*>o).tzinfo
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":147
+ * 
+ * # Get year of date
+ * cdef inline int date_year(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_YEAR(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_date_year(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("date_year", 0);
+
+  /* "cpython/datetime.pxd":148
+ * # Get year of date
+ * cdef inline int date_year(object o):
+ *     return PyDateTime_GET_YEAR(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get month of date
+ */
+  __pyx_r = PyDateTime_GET_YEAR(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":147
+ * 
+ * # Get year of date
+ * cdef inline int date_year(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_YEAR(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":151
+ * 
+ * # Get month of date
+ * cdef inline int date_month(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_MONTH(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_date_month(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("date_month", 0);
+
+  /* "cpython/datetime.pxd":152
+ * # Get month of date
+ * cdef inline int date_month(object o):
+ *     return PyDateTime_GET_MONTH(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get day of date
+ */
+  __pyx_r = PyDateTime_GET_MONTH(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":151
+ * 
+ * # Get month of date
+ * cdef inline int date_month(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_MONTH(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":155
+ * 
+ * # Get day of date
+ * cdef inline int date_day(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_DAY(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_date_day(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("date_day", 0);
+
+  /* "cpython/datetime.pxd":156
+ * # Get day of date
+ * cdef inline int date_day(object o):
+ *     return PyDateTime_GET_DAY(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get year of datetime
+ */
+  __pyx_r = PyDateTime_GET_DAY(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":155
+ * 
+ * # Get day of date
+ * cdef inline int date_day(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_DAY(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":159
+ * 
+ * # Get year of datetime
+ * cdef inline int datetime_year(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_YEAR(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_year(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_year", 0);
+
+  /* "cpython/datetime.pxd":160
+ * # Get year of datetime
+ * cdef inline int datetime_year(object o):
+ *     return PyDateTime_GET_YEAR(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get month of datetime
+ */
+  __pyx_r = PyDateTime_GET_YEAR(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":159
+ * 
+ * # Get year of datetime
+ * cdef inline int datetime_year(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_YEAR(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":163
+ * 
+ * # Get month of datetime
+ * cdef inline int datetime_month(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_MONTH(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_month(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_month", 0);
+
+  /* "cpython/datetime.pxd":164
+ * # Get month of datetime
+ * cdef inline int datetime_month(object o):
+ *     return PyDateTime_GET_MONTH(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get day of datetime
+ */
+  __pyx_r = PyDateTime_GET_MONTH(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":163
+ * 
+ * # Get month of datetime
+ * cdef inline int datetime_month(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_MONTH(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":167
+ * 
+ * # Get day of datetime
+ * cdef inline int datetime_day(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_DAY(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_day(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_day", 0);
+
+  /* "cpython/datetime.pxd":168
+ * # Get day of datetime
+ * cdef inline int datetime_day(object o):
+ *     return PyDateTime_GET_DAY(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get hour of time
+ */
+  __pyx_r = PyDateTime_GET_DAY(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":167
+ * 
+ * # Get day of datetime
+ * cdef inline int datetime_day(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_GET_DAY(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":171
+ * 
+ * # Get hour of time
+ * cdef inline int time_hour(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_HOUR(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_hour(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("time_hour", 0);
+
+  /* "cpython/datetime.pxd":172
+ * # Get hour of time
+ * cdef inline int time_hour(object o):
+ *     return PyDateTime_TIME_GET_HOUR(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get minute of time
+ */
+  __pyx_r = PyDateTime_TIME_GET_HOUR(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":171
+ * 
+ * # Get hour of time
+ * cdef inline int time_hour(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_HOUR(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":175
+ * 
+ * # Get minute of time
+ * cdef inline int time_minute(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_MINUTE(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_minute(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("time_minute", 0);
+
+  /* "cpython/datetime.pxd":176
+ * # Get minute of time
+ * cdef inline int time_minute(object o):
+ *     return PyDateTime_TIME_GET_MINUTE(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get second of time
+ */
+  __pyx_r = PyDateTime_TIME_GET_MINUTE(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":175
+ * 
+ * # Get minute of time
+ * cdef inline int time_minute(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_MINUTE(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":179
+ * 
+ * # Get second of time
+ * cdef inline int time_second(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_SECOND(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_second(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("time_second", 0);
+
+  /* "cpython/datetime.pxd":180
+ * # Get second of time
+ * cdef inline int time_second(object o):
+ *     return PyDateTime_TIME_GET_SECOND(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get microsecond of time
+ */
+  __pyx_r = PyDateTime_TIME_GET_SECOND(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":179
+ * 
+ * # Get second of time
+ * cdef inline int time_second(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_SECOND(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":183
+ * 
+ * # Get microsecond of time
+ * cdef inline int time_microsecond(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_MICROSECOND(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_time_microsecond(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("time_microsecond", 0);
+
+  /* "cpython/datetime.pxd":184
+ * # Get microsecond of time
+ * cdef inline int time_microsecond(object o):
+ *     return PyDateTime_TIME_GET_MICROSECOND(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get hour of datetime
+ */
+  __pyx_r = PyDateTime_TIME_GET_MICROSECOND(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":183
+ * 
+ * # Get microsecond of time
+ * cdef inline int time_microsecond(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_TIME_GET_MICROSECOND(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":187
+ * 
+ * # Get hour of datetime
+ * cdef inline int datetime_hour(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_HOUR(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_hour(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_hour", 0);
+
+  /* "cpython/datetime.pxd":188
+ * # Get hour of datetime
+ * cdef inline int datetime_hour(object o):
+ *     return PyDateTime_DATE_GET_HOUR(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get minute of datetime
+ */
+  __pyx_r = PyDateTime_DATE_GET_HOUR(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":187
+ * 
+ * # Get hour of datetime
+ * cdef inline int datetime_hour(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_HOUR(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":191
+ * 
+ * # Get minute of datetime
+ * cdef inline int datetime_minute(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_MINUTE(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_minute(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_minute", 0);
+
+  /* "cpython/datetime.pxd":192
+ * # Get minute of datetime
+ * cdef inline int datetime_minute(object o):
+ *     return PyDateTime_DATE_GET_MINUTE(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get second of datetime
+ */
+  __pyx_r = PyDateTime_DATE_GET_MINUTE(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":191
+ * 
+ * # Get minute of datetime
+ * cdef inline int datetime_minute(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_MINUTE(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":195
+ * 
+ * # Get second of datetime
+ * cdef inline int datetime_second(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_SECOND(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_second(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_second", 0);
+
+  /* "cpython/datetime.pxd":196
+ * # Get second of datetime
+ * cdef inline int datetime_second(object o):
+ *     return PyDateTime_DATE_GET_SECOND(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get microsecond of datetime
+ */
+  __pyx_r = PyDateTime_DATE_GET_SECOND(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":195
+ * 
+ * # Get second of datetime
+ * cdef inline int datetime_second(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_SECOND(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":199
+ * 
+ * # Get microsecond of datetime
+ * cdef inline int datetime_microsecond(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_MICROSECOND(o)
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_datetime_microsecond(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("datetime_microsecond", 0);
+
+  /* "cpython/datetime.pxd":200
+ * # Get microsecond of datetime
+ * cdef inline int datetime_microsecond(object o):
+ *     return PyDateTime_DATE_GET_MICROSECOND(o)             # <<<<<<<<<<<<<<
+ * 
+ * # Get days of timedelta
+ */
+  __pyx_r = PyDateTime_DATE_GET_MICROSECOND(__pyx_v_o);
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":199
+ * 
+ * # Get microsecond of datetime
+ * cdef inline int datetime_microsecond(object o):             # <<<<<<<<<<<<<<
+ *     return PyDateTime_DATE_GET_MICROSECOND(o)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":203
+ * 
+ * # Get days of timedelta
+ * cdef inline int timedelta_days(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).days
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_timedelta_days(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("timedelta_days", 0);
+
+  /* "cpython/datetime.pxd":204
+ * # Get days of timedelta
+ * cdef inline int timedelta_days(object o):
+ *     return (<PyDateTime_Delta*>o).days             # <<<<<<<<<<<<<<
+ * 
+ * # Get seconds of timedelta
+ */
+  __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->days;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":203
+ * 
+ * # Get days of timedelta
+ * cdef inline int timedelta_days(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).days
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":207
+ * 
+ * # Get seconds of timedelta
+ * cdef inline int timedelta_seconds(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).seconds
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_timedelta_seconds(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("timedelta_seconds", 0);
+
+  /* "cpython/datetime.pxd":208
+ * # Get seconds of timedelta
+ * cdef inline int timedelta_seconds(object o):
+ *     return (<PyDateTime_Delta*>o).seconds             # <<<<<<<<<<<<<<
+ * 
+ * # Get microseconds of timedelta
+ */
+  __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->seconds;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":207
+ * 
+ * # Get seconds of timedelta
+ * cdef inline int timedelta_seconds(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).seconds
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cpython/datetime.pxd":211
+ * 
+ * # Get microseconds of timedelta
+ * cdef inline int timedelta_microseconds(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).microseconds
+ */
+
+static CYTHON_INLINE int __pyx_f_7cpython_8datetime_timedelta_microseconds(PyObject *__pyx_v_o) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("timedelta_microseconds", 0);
+
+  /* "cpython/datetime.pxd":212
+ * # Get microseconds of timedelta
+ * cdef inline int timedelta_microseconds(object o):
+ *     return (<PyDateTime_Delta*>o).microseconds             # <<<<<<<<<<<<<<
+ */
+  __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->microseconds;
+  goto __pyx_L0;
+
+  /* "cpython/datetime.pxd":211
+ * 
+ * # Get microseconds of timedelta
+ * cdef inline int timedelta_microseconds(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).microseconds
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_freelist_7asyncpg_7pgproto_7pgproto_WriteBuffer[256];
+static int __pyx_freecount_7asyncpg_7pgproto_7pgproto_WriteBuffer = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_7pgproto_7pgproto_WriteBuffer(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *p;
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_7pgproto_7pgproto_WriteBuffer > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_7pgproto_7pgproto_WriteBuffer[--__pyx_freecount_7asyncpg_7pgproto_7pgproto_WriteBuffer];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer));
+    (void) PyObject_INIT(o, t);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  p = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+  if (unlikely(__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad;
+  return o;
+  bad:
+  Py_DECREF(o); o = 0;
+  return NULL;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_7pgproto_7pgproto_WriteBuffer(PyObject *o) {
+  {
+    PyObject *etype, *eval, *etb;
+    PyErr_Fetch(&etype, &eval, &etb);
+    ++Py_REFCNT(o);
+    __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_3__dealloc__(o);
+    --Py_REFCNT(o);
+    PyErr_Restore(etype, eval, etb);
+  }
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_7pgproto_7pgproto_WriteBuffer < 256) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer)))) {
+    __pyx_freelist_7asyncpg_7pgproto_7pgproto_WriteBuffer[__pyx_freecount_7asyncpg_7pgproto_7pgproto_WriteBuffer++] = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_7pgproto_7pgproto_WriteBuffer[] = {
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_9__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_11__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_WriteBuffer = {
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getreadbuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getwritebuffer*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getsegcount*/
+  #endif
+  #if PY_MAJOR_VERSION < 3
+  0, /*bf_getcharbuffer*/
+  #endif
+  __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_5__getbuffer__, /*bf_getbuffer*/
+  __pyx_pw_7asyncpg_7pgproto_7pgproto_11WriteBuffer_7__releasebuffer__, /*bf_releasebuffer*/
+};
+
+static PyTypeObject __pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.pgproto.pgproto.WriteBuffer", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_7pgproto_7pgproto_WriteBuffer, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_WriteBuffer, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
+  0, /*tp_doc*/
+  0, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_7pgproto_7pgproto_WriteBuffer, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_7pgproto_7pgproto_WriteBuffer, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_freelist_7asyncpg_7pgproto_7pgproto_ReadBuffer[256];
+static int __pyx_freecount_7asyncpg_7pgproto_7pgproto_ReadBuffer = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_7pgproto_7pgproto_ReadBuffer(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *p;
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_7pgproto_7pgproto_ReadBuffer > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_7pgproto_7pgproto_ReadBuffer[--__pyx_freecount_7asyncpg_7pgproto_7pgproto_ReadBuffer];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  p = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+  p->_bufs = Py_None; Py_INCREF(Py_None);
+  p->_bufs_append = Py_None; Py_INCREF(Py_None);
+  p->_bufs_popleft = Py_None; Py_INCREF(Py_None);
+  p->_buf0 = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->_buf0_prev = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  if (unlikely(__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad;
+  return o;
+  bad:
+  Py_DECREF(o); o = 0;
+  return NULL;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_7pgproto_7pgproto_ReadBuffer(PyObject *o) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *p = (struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->_bufs);
+  Py_CLEAR(p->_bufs_append);
+  Py_CLEAR(p->_bufs_popleft);
+  Py_CLEAR(p->_buf0);
+  Py_CLEAR(p->_buf0_prev);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_7pgproto_7pgproto_ReadBuffer < 256) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer)))) {
+    __pyx_freelist_7asyncpg_7pgproto_7pgproto_ReadBuffer[__pyx_freecount_7asyncpg_7pgproto_7pgproto_ReadBuffer++] = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_7pgproto_7pgproto_ReadBuffer(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *p = (struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)o;
+  if (p->_bufs) {
+    e = (*v)(p->_bufs, a); if (e) return e;
+  }
+  if (p->_bufs_append) {
+    e = (*v)(p->_bufs_append, a); if (e) return e;
+  }
+  if (p->_bufs_popleft) {
+    e = (*v)(p->_bufs_popleft, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_7pgproto_7pgproto_ReadBuffer[] = {
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_3__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_10ReadBuffer_5__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.pgproto.pgproto.ReadBuffer", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_7pgproto_7pgproto_ReadBuffer, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_7pgproto_7pgproto_ReadBuffer, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_7pgproto_7pgproto_ReadBuffer, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_7pgproto_7pgproto_ReadBuffer, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext __pyx_vtable_7asyncpg_7pgproto_7pgproto_CodecContext;
+
+static PyObject *__pyx_tp_new_7asyncpg_7pgproto_7pgproto_CodecContext(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *p;
+  PyObject *o;
+  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
+    o = (*t->tp_alloc)(t, 0);
+  } else {
+    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
+  }
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext;
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_7pgproto_7pgproto_CodecContext(PyObject *o) {
+  #if CYTHON_USE_TP_FINALIZE
+  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
+    if (PyObject_CallFinalizerFromDealloc(o)) return;
+  }
+  #endif
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_7pgproto_7pgproto_CodecContext[] = {
+  {"get_text_codec", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_1get_text_codec, METH_NOARGS, 0},
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_3__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_7pgproto_7pgproto_12CodecContext_5__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.pgproto.pgproto.CodecContext", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_7pgproto_7pgproto_CodecContext, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+  0, /*tp_doc*/
+  0, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_7pgproto_7pgproto_CodecContext, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_7pgproto_7pgproto_CodecContext, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+  {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+#if CYTHON_PEP489_MULTI_PHASE_INIT
+static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
+static int __pyx_pymod_exec_pgproto(PyObject* module); /*proto*/
+static PyModuleDef_Slot __pyx_moduledef_slots[] = {
+  {Py_mod_create, (void*)__pyx_pymod_create},
+  {Py_mod_exec, (void*)__pyx_pymod_exec_pgproto},
+  {0, NULL}
+};
+#endif
+
+static struct PyModuleDef __pyx_moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "pgproto",
+    0, /* m_doc */
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+    0, /* m_size */
+  #else
+    -1, /* m_size */
+  #endif
+    __pyx_methods /* m_methods */,
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+    __pyx_moduledef_slots, /* m_slots */
+  #else
+    NULL, /* m_reload */
+  #endif
+    NULL, /* m_traverse */
+    NULL, /* m_clear */
+    NULL /* m_free */
+};
+#endif
+#ifndef CYTHON_SMALL_CODE
+#if defined(__clang__)
+    #define CYTHON_SMALL_CODE
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+    #define CYTHON_SMALL_CODE __attribute__((cold))
+#else
+    #define CYTHON_SMALL_CODE
+#endif
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+  {&__pyx_kp_u_0e, __pyx_k_0e, sizeof(__pyx_k_0e), 0, 1, 0, 0},
+  {&__pyx_n_s_AssertionError, __pyx_k_AssertionError, sizeof(__pyx_k_AssertionError), 0, 0, 1, 1},
+  {&__pyx_n_s_BitString, __pyx_k_BitString, sizeof(__pyx_k_BitString), 0, 0, 1, 1},
+  {&__pyx_n_s_Box, __pyx_k_Box, sizeof(__pyx_k_Box), 0, 0, 1, 1},
+  {&__pyx_n_s_BufferError, __pyx_k_BufferError, sizeof(__pyx_k_BufferError), 0, 0, 1, 1},
+  {&__pyx_n_s_Circle, __pyx_k_Circle, sizeof(__pyx_k_Circle), 0, 0, 1, 1},
+  {&__pyx_n_s_CodecContext, __pyx_k_CodecContext, sizeof(__pyx_k_CodecContext), 0, 0, 1, 1},
+  {&__pyx_kp_u_Deallocating_buffer_with_attache, __pyx_k_Deallocating_buffer_with_attache, sizeof(__pyx_k_Deallocating_buffer_with_attache), 0, 1, 0, 0},
+  {&__pyx_n_s_Dec, __pyx_k_Dec, sizeof(__pyx_k_Dec), 0, 0, 1, 1},
+  {&__pyx_n_s_Decimal, __pyx_k_Decimal, sizeof(__pyx_k_Decimal), 0, 0, 1, 1},
+  {&__pyx_n_u_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 1, 0, 1},
+  {&__pyx_kp_s_Incompatible_checksums_s_vs_0xd4, __pyx_k_Incompatible_checksums_s_vs_0xd4, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xd4), 0, 0, 1, 0},
+  {&__pyx_n_s_Line, __pyx_k_Line, sizeof(__pyx_k_Line), 0, 0, 1, 1},
+  {&__pyx_n_s_LineSegment, __pyx_k_LineSegment, sizeof(__pyx_k_LineSegment), 0, 0, 1, 1},
+  {&__pyx_n_s_MAXYEAR, __pyx_k_MAXYEAR, sizeof(__pyx_k_MAXYEAR), 0, 0, 1, 1},
+  {&__pyx_n_s_MINYEAR, __pyx_k_MINYEAR, sizeof(__pyx_k_MINYEAR), 0, 0, 1, 1},
+  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
+  {&__pyx_n_u_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 1, 0, 1},
+  {&__pyx_n_u_NaN, __pyx_k_NaN, sizeof(__pyx_k_NaN), 0, 1, 0, 1},
+  {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
+  {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1},
+  {&__pyx_n_s_Path, __pyx_k_Path, sizeof(__pyx_k_Path), 0, 0, 1, 1},
+  {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
+  {&__pyx_n_s_Point, __pyx_k_Point, sizeof(__pyx_k_Point), 0, 0, 1, 1},
+  {&__pyx_n_s_Polygon, __pyx_k_Polygon, sizeof(__pyx_k_Polygon), 0, 0, 1, 1},
+  {&__pyx_n_s_ReadBuffer, __pyx_k_ReadBuffer, sizeof(__pyx_k_ReadBuffer), 0, 0, 1, 1},
+  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
+  {&__pyx_n_s_UUID, __pyx_k_UUID, sizeof(__pyx_k_UUID), 0, 0, 1, 1},
+  {&__pyx_n_s_UUID_2, __pyx_k_UUID_2, sizeof(__pyx_k_UUID_2), 0, 0, 1, 1},
+  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
+  {&__pyx_n_s_WriteBuffer, __pyx_k_WriteBuffer, sizeof(__pyx_k_WriteBuffer), 0, 0, 1, 1},
+  {&__pyx_n_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 1},
+  {&__pyx_kp_b__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 0, 0},
+  {&__pyx_kp_b__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 0, 0},
+  {&__pyx_kp_u_a_boolean_is_required_got_type, __pyx_k_a_boolean_is_required_got_type, sizeof(__pyx_k_a_boolean_is_required_got_type), 0, 1, 0, 0},
+  {&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1},
+  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
+  {&__pyx_n_s_as_tuple, __pyx_k_as_tuple, sizeof(__pyx_k_as_tuple), 0, 0, 1, 1},
+  {&__pyx_n_s_astimezone, __pyx_k_astimezone, sizeof(__pyx_k_astimezone), 0, 0, 1, 1},
+  {&__pyx_n_s_asyncpg_pgproto_pgproto, __pyx_k_asyncpg_pgproto_pgproto, sizeof(__pyx_k_asyncpg_pgproto_pgproto), 0, 0, 1, 1},
+  {&__pyx_kp_u_bit_value_too_long, __pyx_k_bit_value_too_long, sizeof(__pyx_k_bit_value_too_long), 0, 1, 0, 0},
+  {&__pyx_kp_u_buffer_overread, __pyx_k_buffer_overread, sizeof(__pyx_k_buffer_overread), 0, 1, 0, 0},
+  {&__pyx_n_s_bytes, __pyx_k_bytes, sizeof(__pyx_k_bytes), 0, 0, 1, 1},
+  {&__pyx_kp_u_cannot_encode_Decimal_value_into, __pyx_k_cannot_encode_Decimal_value_into, sizeof(__pyx_k_cannot_encode_Decimal_value_into), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_encode_Decimal_value_into_2, __pyx_k_cannot_encode_Decimal_value_into_2, sizeof(__pyx_k_cannot_encode_Decimal_value_into_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_encode_Decimal_value_into_3, __pyx_k_cannot_encode_Decimal_value_into_3, sizeof(__pyx_k_cannot_encode_Decimal_value_into_3), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_put_message_no_message_ta, __pyx_k_cannot_put_message_no_message_ta, sizeof(__pyx_k_cannot_put_message_no_message_ta), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_start_message_for_a_non_e, __pyx_k_cannot_start_message_for_a_non_e, sizeof(__pyx_k_cannot_start_message_for_a_non_e), 0, 1, 0, 0},
+  {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1},
+  {&__pyx_n_u_cidr, __pyx_k_cidr, sizeof(__pyx_k_cidr), 0, 1, 0, 1},
+  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
+  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
+  {&__pyx_kp_u_consume_full_messages_called_on, __pyx_k_consume_full_messages_called_on, sizeof(__pyx_k_consume_full_messages_called_on), 0, 1, 0, 0},
+  {&__pyx_kp_u_consume_full_messages_called_on_2, __pyx_k_consume_full_messages_called_on_2, sizeof(__pyx_k_consume_full_messages_called_on_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_consume_full_messages_called_wit, __pyx_k_consume_full_messages_called_wit, sizeof(__pyx_k_consume_full_messages_called_wit), 0, 1, 0, 0},
+  {&__pyx_n_s_date, __pyx_k_date, sizeof(__pyx_k_date), 0, 0, 1, 1},
+  {&__pyx_n_s_date_from_ordinal, __pyx_k_date_from_ordinal, sizeof(__pyx_k_date_from_ordinal), 0, 0, 1, 1},
+  {&__pyx_kp_u_date_tuple_encoder_expecting_1_e, __pyx_k_date_tuple_encoder_expecting_1_e, sizeof(__pyx_k_date_tuple_encoder_expecting_1_e), 0, 1, 0, 0},
+  {&__pyx_n_s_datetime, __pyx_k_datetime, sizeof(__pyx_k_datetime), 0, 0, 1, 1},
+  {&__pyx_n_s_day, __pyx_k_day, sizeof(__pyx_k_day), 0, 0, 1, 1},
+  {&__pyx_n_s_days, __pyx_k_days, sizeof(__pyx_k_days), 0, 0, 1, 1},
+  {&__pyx_kp_u_debug_first_buffer_of_ReadBuffer, __pyx_k_debug_first_buffer_of_ReadBuffer, sizeof(__pyx_k_debug_first_buffer_of_ReadBuffer), 0, 1, 0, 0},
+  {&__pyx_kp_u_debug_second_buffer_of_ReadBuffe, __pyx_k_debug_second_buffer_of_ReadBuffe, sizeof(__pyx_k_debug_second_buffer_of_ReadBuffe), 0, 1, 0, 0},
+  {&__pyx_n_s_decimal, __pyx_k_decimal, sizeof(__pyx_k_decimal), 0, 0, 1, 1},
+  {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1},
+  {&__pyx_n_s_deque, __pyx_k_deque, sizeof(__pyx_k_deque), 0, 0, 1, 1},
+  {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
+  {&__pyx_n_s_digits, __pyx_k_digits, sizeof(__pyx_k_digits), 0, 0, 1, 1},
+  {&__pyx_kp_u_discarding_message_r_unread_dat, __pyx_k_discarding_message_r_unread_dat, sizeof(__pyx_k_discarding_message_r_unread_dat), 0, 1, 0, 0},
+  {&__pyx_kp_u_empty_first_buffer, __pyx_k_empty_first_buffer, sizeof(__pyx_k_empty_first_buffer), 0, 1, 0, 0},
+  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
+  {&__pyx_kp_u_end_message_buffer_is_too_small, __pyx_k_end_message_buffer_is_too_small, sizeof(__pyx_k_end_message_buffer_is_too_small), 0, 1, 0, 0},
+  {&__pyx_kp_u_end_message_can_only_be_called_w, __pyx_k_end_message_can_only_be_called_w, sizeof(__pyx_k_end_message_can_only_be_called_w), 0, 1, 0, 0},
+  {&__pyx_kp_u_end_message_message_is_too_large, __pyx_k_end_message_message_is_too_large, sizeof(__pyx_k_end_message_message_is_too_large), 0, 1, 0, 0},
+  {&__pyx_n_s_exceptions, __pyx_k_exceptions, sizeof(__pyx_k_exceptions), 0, 0, 1, 1},
+  {&__pyx_kp_u_expected_a_datetime_date_or_date, __pyx_k_expected_a_datetime_date_or_date, sizeof(__pyx_k_expected_a_datetime_date_or_date), 0, 1, 0, 0},
+  {&__pyx_kp_u_expected_str_got, __pyx_k_expected_str_got, sizeof(__pyx_k_expected_str_got), 0, 1, 0, 0},
+  {&__pyx_n_s_exponent, __pyx_k_exponent, sizeof(__pyx_k_exponent), 0, 0, 1, 1},
+  {&__pyx_kp_u_failed_to_read_one_byte_on_a_non, __pyx_k_failed_to_read_one_byte_on_a_non, sizeof(__pyx_k_failed_to_read_one_byte_on_a_non), 0, 1, 0, 0},
+  {&__pyx_kp_u_feed_data_bytes_object_expected, __pyx_k_feed_data_bytes_object_expected, sizeof(__pyx_k_feed_data_bytes_object_expected), 0, 1, 0, 0},
+  {&__pyx_n_s_find, __pyx_k_find, sizeof(__pyx_k_find), 0, 0, 1, 1},
+  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
+  {&__pyx_n_s_frombytes, __pyx_k_frombytes, sizeof(__pyx_k_frombytes), 0, 0, 1, 1},
+  {&__pyx_n_s_fromordinal, __pyx_k_fromordinal, sizeof(__pyx_k_fromordinal), 0, 0, 1, 1},
+  {&__pyx_n_s_get_text_codec, __pyx_k_get_text_codec, sizeof(__pyx_k_get_text_codec), 0, 0, 1, 1},
+  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
+  {&__pyx_n_s_hour, __pyx_k_hour, sizeof(__pyx_k_hour), 0, 0, 1, 1},
+  {&__pyx_kp_u_hstore_value_is_too_large, __pyx_k_hstore_value_is_too_large, sizeof(__pyx_k_hstore_value_is_too_large), 0, 1, 0, 0},
+  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
+  {&__pyx_n_u_inet, __pyx_k_inet, sizeof(__pyx_k_inet), 0, 1, 0, 1},
+  {&__pyx_n_s_infinity_date, __pyx_k_infinity_date, sizeof(__pyx_k_infinity_date), 0, 0, 1, 1},
+  {&__pyx_n_s_infinity_datetime, __pyx_k_infinity_datetime, sizeof(__pyx_k_infinity_datetime), 0, 0, 1, 1},
+  {&__pyx_kp_u_insufficient_data_in_buffer_requ, __pyx_k_insufficient_data_in_buffer_requ, sizeof(__pyx_k_insufficient_data_in_buffer_requ), 0, 1, 0, 0},
+  {&__pyx_kp_u_interval_tuple_encoder_expecting, __pyx_k_interval_tuple_encoder_expecting, sizeof(__pyx_k_interval_tuple_encoder_expecting), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_address_family_in_value, __pyx_k_invalid_address_family_in_value, sizeof(__pyx_k_invalid_address_family_in_value), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_address_length_in_value, __pyx_k_invalid_address_length_in_value, sizeof(__pyx_k_invalid_address_length_in_value), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_network_prefix_length_in, __pyx_k_invalid_network_prefix_length_in, sizeof(__pyx_k_invalid_network_prefix_length_in), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_number_of_elements_in_ti, __pyx_k_invalid_number_of_elements_in_ti, sizeof(__pyx_k_invalid_number_of_elements_in_ti), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_number_of_elements_in_tx, __pyx_k_invalid_number_of_elements_in_tx, sizeof(__pyx_k_invalid_number_of_elements_in_tx), 0, 1, 0, 0},
+  {&__pyx_n_s_ip_address, __pyx_k_ip_address, sizeof(__pyx_k_ip_address), 0, 0, 1, 1},
+  {&__pyx_n_s_ip_network, __pyx_k_ip_network, sizeof(__pyx_k_ip_network), 0, 0, 1, 1},
+  {&__pyx_n_s_ipaddr, __pyx_k_ipaddr, sizeof(__pyx_k_ipaddr), 0, 0, 1, 1},
+  {&__pyx_n_s_ipaddress, __pyx_k_ipaddress, sizeof(__pyx_k_ipaddress), 0, 0, 1, 1},
+  {&__pyx_n_s_ipnet, __pyx_k_ipnet, sizeof(__pyx_k_ipnet), 0, 0, 1, 1},
+  {&__pyx_n_s_is_closed, __pyx_k_is_closed, sizeof(__pyx_k_is_closed), 0, 0, 1, 1},
+  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
+  {&__pyx_n_u_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 1, 0, 1},
+  {&__pyx_n_s_len, __pyx_k_len, sizeof(__pyx_k_len), 0, 0, 1, 1},
+  {&__pyx_kp_u_list_or_tuple_expected_got_type, __pyx_k_list_or_tuple_expected_got_type, sizeof(__pyx_k_list_or_tuple_expected_got_type), 0, 1, 0, 0},
+  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
+  {&__pyx_n_s_microsecond, __pyx_k_microsecond, sizeof(__pyx_k_microsecond), 0, 0, 1, 1},
+  {&__pyx_n_s_microseconds, __pyx_k_microseconds, sizeof(__pyx_k_microseconds), 0, 0, 1, 1},
+  {&__pyx_n_s_minute, __pyx_k_minute, sizeof(__pyx_k_minute), 0, 0, 1, 1},
+  {&__pyx_n_s_minutes, __pyx_k_minutes, sizeof(__pyx_k_minutes), 0, 0, 1, 1},
+  {&__pyx_n_s_month, __pyx_k_month, sizeof(__pyx_k_month), 0, 0, 1, 1},
+  {&__pyx_n_u_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 1, 0, 1},
+  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
+  {&__pyx_n_s_negative_infinity_date, __pyx_k_negative_infinity_date, sizeof(__pyx_k_negative_infinity_date), 0, 0, 1, 1},
+  {&__pyx_n_s_negative_infinity_datetime, __pyx_k_negative_infinity_datetime, sizeof(__pyx_k_negative_infinity_datetime), 0, 0, 1, 1},
+  {&__pyx_n_s_network_address, __pyx_k_network_address, sizeof(__pyx_k_network_address), 0, 0, 1, 1},
+  {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
+  {&__pyx_n_s_new_prefix, __pyx_k_new_prefix, sizeof(__pyx_k_new_prefix), 0, 0, 1, 1},
+  {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
+  {&__pyx_kp_u_no_message_to_consume, __pyx_k_no_message_to_consume, sizeof(__pyx_k_no_message_to_consume), 0, 1, 0, 0},
+  {&__pyx_kp_u_no_message_to_discard, __pyx_k_no_message_to_discard, sizeof(__pyx_k_no_message_to_discard), 0, 1, 0, 0},
+  {&__pyx_kp_u_not_enough_data_to_read_bytes, __pyx_k_not_enough_data_to_read_bytes, sizeof(__pyx_k_not_enough_data_to_read_bytes), 0, 1, 0, 0},
+  {&__pyx_kp_u_not_enough_data_to_read_one_byte, __pyx_k_not_enough_data_to_read_one_byte, sizeof(__pyx_k_not_enough_data_to_read_one_byte), 0, 1, 0, 0},
+  {&__pyx_n_s_now, __pyx_k_now, sizeof(__pyx_k_now), 0, 0, 1, 1},
+  {&__pyx_kp_u_null_value_not_allowed_in_hstore, __pyx_k_null_value_not_allowed_in_hstore, sizeof(__pyx_k_null_value_not_allowed_in_hstore), 0, 1, 0, 0},
+  {&__pyx_kp_u_numeric_type_does_not_support_in, __pyx_k_numeric_type_does_not_support_in, sizeof(__pyx_k_numeric_type_does_not_support_in), 0, 1, 0, 0},
+  {&__pyx_n_s_packed, __pyx_k_packed, sizeof(__pyx_k_packed), 0, 0, 1, 1},
+  {&__pyx_kp_u_path_value_too_long, __pyx_k_path_value_too_long, sizeof(__pyx_k_path_value_too_long), 0, 1, 0, 0},
+  {&__pyx_n_s_pg_epoch_date, __pyx_k_pg_epoch_date, sizeof(__pyx_k_pg_epoch_date), 0, 0, 1, 1},
+  {&__pyx_n_s_pg_epoch_datetime, __pyx_k_pg_epoch_datetime, sizeof(__pyx_k_pg_epoch_datetime), 0, 0, 1, 1},
+  {&__pyx_n_s_pg_epoch_datetime_utc, __pyx_k_pg_epoch_datetime_utc, sizeof(__pyx_k_pg_epoch_datetime_utc), 0, 0, 1, 1},
+  {&__pyx_n_s_pgproto_types, __pyx_k_pgproto_types, sizeof(__pyx_k_pgproto_types), 0, 0, 1, 1},
+  {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1},
+  {&__pyx_kp_u_polygon_value_too_long, __pyx_k_polygon_value_too_long, sizeof(__pyx_k_polygon_value_too_long), 0, 1, 0, 0},
+  {&__pyx_n_s_popleft, __pyx_k_popleft, sizeof(__pyx_k_popleft), 0, 0, 1, 1},
+  {&__pyx_n_s_prefixlen, __pyx_k_prefixlen, sizeof(__pyx_k_prefixlen), 0, 0, 1, 1},
+  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_unpickle_CodecContext, __pyx_k_pyx_unpickle_CodecContext, sizeof(__pyx_k_pyx_unpickle_CodecContext), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
+  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
+  {&__pyx_kp_u_read_cstr_buffer_overread, __pyx_k_read_cstr_buffer_overread, sizeof(__pyx_k_read_cstr_buffer_overread), 0, 1, 0, 0},
+  {&__pyx_kp_u_read_cstr_only_works_when_the_me, __pyx_k_read_cstr_only_works_when_the_me, sizeof(__pyx_k_read_cstr_only_works_when_the_me), 0, 1, 0, 0},
+  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
+  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
+  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
+  {&__pyx_kp_u_remaining, __pyx_k_remaining, sizeof(__pyx_k_remaining), 0, 1, 0, 0},
+  {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
+  {&__pyx_n_s_second, __pyx_k_second, sizeof(__pyx_k_second), 0, 0, 1, 1},
+  {&__pyx_n_s_seconds, __pyx_k_seconds, sizeof(__pyx_k_seconds), 0, 0, 1, 1},
+  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
+  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
+  {&__pyx_n_s_sign, __pyx_k_sign, sizeof(__pyx_k_sign), 0, 0, 1, 1},
+  {&__pyx_kp_u_string_too_long, __pyx_k_string_too_long, sizeof(__pyx_k_string_too_long), 0, 1, 0, 0},
+  {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
+  {&__pyx_n_s_supernet, __pyx_k_supernet, sizeof(__pyx_k_supernet), 0, 0, 1, 1},
+  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
+  {&__pyx_kp_u_the_buffer_is_in_read_only_mode, __pyx_k_the_buffer_is_in_read_only_mode, sizeof(__pyx_k_the_buffer_is_in_read_only_mode), 0, 1, 0, 0},
+  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
+  {&__pyx_kp_u_time_tuple_encoder_expecting_1_e, __pyx_k_time_tuple_encoder_expecting_1_e, sizeof(__pyx_k_time_tuple_encoder_expecting_1_e), 0, 1, 0, 0},
+  {&__pyx_kp_u_time_tuple_encoder_expecting_2_e, __pyx_k_time_tuple_encoder_expecting_2_e, sizeof(__pyx_k_time_tuple_encoder_expecting_2_e), 0, 1, 0, 0},
+  {&__pyx_n_s_timedelta, __pyx_k_timedelta, sizeof(__pyx_k_timedelta), 0, 0, 1, 1},
+  {&__pyx_n_s_timestamp, __pyx_k_timestamp, sizeof(__pyx_k_timestamp), 0, 0, 1, 1},
+  {&__pyx_kp_u_timestamp_tuple_encoder_expectin, __pyx_k_timestamp_tuple_encoder_expectin, sizeof(__pyx_k_timestamp_tuple_encoder_expectin), 0, 1, 0, 0},
+  {&__pyx_n_s_timezone, __pyx_k_timezone, sizeof(__pyx_k_timezone), 0, 0, 1, 1},
+  {&__pyx_n_s_toordinal, __pyx_k_toordinal, sizeof(__pyx_k_toordinal), 0, 0, 1, 1},
+  {&__pyx_kp_u_tuple_id_block_value_out_of_uint, __pyx_k_tuple_id_block_value_out_of_uint, sizeof(__pyx_k_tuple_id_block_value_out_of_uint), 0, 1, 0, 0},
+  {&__pyx_kp_u_tuple_id_offset_value_out_of_uin, __pyx_k_tuple_id_offset_value_out_of_uin, sizeof(__pyx_k_tuple_id_offset_value_out_of_uin), 0, 1, 0, 0},
+  {&__pyx_kp_u_txid_snapshot_value_is_too_long, __pyx_k_txid_snapshot_value_is_too_long, sizeof(__pyx_k_txid_snapshot_value_is_too_long), 0, 1, 0, 0},
+  {&__pyx_n_s_types, __pyx_k_types, sizeof(__pyx_k_types), 0, 0, 1, 1},
+  {&__pyx_n_s_tzinfo, __pyx_k_tzinfo, sizeof(__pyx_k_tzinfo), 0, 0, 1, 1},
+  {&__pyx_kp_u_unexpected_JSONB_format, __pyx_k_unexpected_JSONB_format, sizeof(__pyx_k_unexpected_JSONB_format), 0, 1, 0, 0},
+  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
+  {&__pyx_n_s_utc, __pyx_k_utc, sizeof(__pyx_k_utc), 0, 0, 1, 1},
+  {&__pyx_n_s_utcoffset, __pyx_k_utcoffset, sizeof(__pyx_k_utcoffset), 0, 0, 1, 1},
+  {&__pyx_kp_u_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0, 0},
+  {&__pyx_n_s_uuid, __pyx_k_uuid, sizeof(__pyx_k_uuid), 0, 0, 1, 1},
+  {&__pyx_kp_u_value_out_of_float32_range, __pyx_k_value_out_of_float32_range, sizeof(__pyx_k_value_out_of_float32_range), 0, 1, 0, 0},
+  {&__pyx_kp_u_value_out_of_int16_range, __pyx_k_value_out_of_int16_range, sizeof(__pyx_k_value_out_of_int16_range), 0, 1, 0, 0},
+  {&__pyx_kp_u_value_out_of_int32_range, __pyx_k_value_out_of_int32_range, sizeof(__pyx_k_value_out_of_int32_range), 0, 1, 0, 0},
+  {&__pyx_kp_u_value_out_of_int64_range, __pyx_k_value_out_of_int64_range, sizeof(__pyx_k_value_out_of_int64_range), 0, 1, 0, 0},
+  {&__pyx_kp_u_value_out_of_uint32_range, __pyx_k_value_out_of_uint32_range, sizeof(__pyx_k_value_out_of_uint32_range), 0, 1, 0, 0},
+  {&__pyx_n_s_version, __pyx_k_version, sizeof(__pyx_k_version), 0, 0, 1, 1},
+  {&__pyx_n_s_year, __pyx_k_year, sizeof(__pyx_k_year), 0, 0, 1, 1},
+  {0, 0, 0, 0, 0, 0, 0}
+};
+static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
+  __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s_AssertionError); if (!__pyx_builtin_AssertionError) __PYX_ERR(0, 10, __pyx_L1_error)
+  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(1, 74, __pyx_L1_error)
+  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(2, 2, __pyx_L1_error)
+  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(1, 678, __pyx_L1_error)
+  __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_n_s_print); if (!__pyx_builtin_print) __PYX_ERR(1, 683, __pyx_L1_error)
+  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(3, 11, __pyx_L1_error)
+  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(4, 21, __pyx_L1_error)
+  __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(5, 27, __pyx_L1_error)
+  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(6, 120, __pyx_L1_error)
+  return 0;
+  __pyx_L1_error:;
+  return -1;
+}
+
+static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple_)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple_);
+  __Pyx_GIVEREF(__pyx_tuple_);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__2);
+  __Pyx_GIVEREF(__pyx_tuple__2);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__5);
+  __Pyx_GIVEREF(__pyx_tuple__5);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__6);
+  __Pyx_GIVEREF(__pyx_tuple__6);
+
+  /* "asyncpg/pgproto/codecs/text.pyx":21
+ * 
+ *     if size[0] > 0x7fffffff:
+ *         raise ValueError('string too long')             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_string_too_long); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(4, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__7);
+  __Pyx_GIVEREF(__pyx_tuple__7);
+
+  /* "asyncpg/pgproto/codecs/float.pyx":15
+ *     cdef float fval = <float>dval
+ *     if math.isinf(fval) and not math.isinf(dval):
+ *         raise ValueError('value out of float32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_u_value_out_of_float32_range); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(9, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__8);
+  __Pyx_GIVEREF(__pyx_tuple__8);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":31
+ * 
+ *     if overflow or val < INT16_MIN or val > INT16_MAX:
+ *         raise OverflowError('value out of int16 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(2)
+ */
+  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_u_value_out_of_int16_range); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(5, 31, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__9);
+  __Pyx_GIVEREF(__pyx_tuple__9);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":52
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and (val < INT32_MIN or val > INT32_MAX)):
+ *         raise OverflowError('value out of int32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_u_value_out_of_int32_range); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(5, 52, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__10);
+  __Pyx_GIVEREF(__pyx_tuple__10);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":73
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(val) > 4 and val > UINT32_MAX):
+ *         raise OverflowError('value out of uint32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(4)
+ */
+  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_u_value_out_of_uint32_range); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(5, 73, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__11);
+  __Pyx_GIVEREF(__pyx_tuple__11);
+
+  /* "asyncpg/pgproto/codecs/int.pyx":95
+ *     # Just in case for systems with "long long" bigger than 8 bytes
+ *     if overflow or (sizeof(val) > 8 and (val < INT64_MIN or val > INT64_MAX)):
+ *         raise OverflowError('value out of int64 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(8)
+ */
+  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_u_value_out_of_int64_range); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(5, 95, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__12);
+  __Pyx_GIVEREF(__pyx_tuple__12);
+
+  /* "asyncpg/pgproto/codecs/json.pyx":16
+ * 
+ *     if size > 0x7fffffff - 1:
+ *         raise ValueError('string too long')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(<int32_t>size + 1)
+ */
+  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_u_string_too_long); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(10, 16, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__7);
+  __Pyx_GIVEREF(__pyx_tuple__7);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":55
+ *     dt = dec.as_tuple()
+ *     if dt.exponent == 'F':
+ *         raise ValueError('numeric type does not support infinite values')             # <<<<<<<<<<<<<<
+ * 
+ *     if dt.exponent == 'n' or dt.exponent == 'N':
+ */
+  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_u_numeric_type_does_not_support_in); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(6, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__13);
+  __Pyx_GIVEREF(__pyx_tuple__13);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":66
+ *         exponent = dt.exponent
+ *         if exponent < 0 and -exponent > MAX_DSCALE:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                 'cannot encode Decimal value into numeric: '
+ *                 'exponent is too small')
+ */
+  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_u_cannot_encode_Decimal_value_into); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(6, 66, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__14);
+  __Pyx_GIVEREF(__pyx_tuple__14);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":85
+ * 
+ *         if weight > 2 ** 16 - 1:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'exponent is too large')
+ */
+  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_u_cannot_encode_Decimal_value_into_2); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(6, 85, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__15);
+  __Pyx_GIVEREF(__pyx_tuple__15);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":95
+ * 
+ *         if num_pgdigits > 2 ** 16 - 1:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'number of digits is too large')
+ */
+  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_u_cannot_encode_Decimal_value_into_3); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(6, 95, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__16);
+  __Pyx_GIVEREF(__pyx_tuple__16);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":101
+ *         # Pad decimal digits to provide room for correct Postgres
+ *         # digit alignment in the digit computation loop.
+ *         pydigits = (0,) * DEC_DIGITS + pydigits + (0,) * DEC_DIGITS             # <<<<<<<<<<<<<<
+ * 
+ *         if exponent < 0:
+ */
+  __pyx_tuple__17 = PyTuple_New(1 * 4); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(6, 101, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__17);
+  { Py_ssize_t __pyx_temp;
+    for (__pyx_temp=0; __pyx_temp < 4; __pyx_temp++) {
+      __Pyx_INCREF(__pyx_int_0);
+      __Pyx_GIVEREF(__pyx_int_0);
+      PyTuple_SET_ITEM(__pyx_tuple__17, __pyx_temp, __pyx_int_0);
+    }
+  }
+  __Pyx_GIVEREF(__pyx_tuple__17);
+  __pyx_tuple__17 = PyTuple_New(1 * 4); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(6, 101, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__17);
+  { Py_ssize_t __pyx_temp;
+    for (__pyx_temp=0; __pyx_temp < 4; __pyx_temp++) {
+      __Pyx_INCREF(__pyx_int_0);
+      __Pyx_GIVEREF(__pyx_int_0);
+      PyTuple_SET_ITEM(__pyx_tuple__17, __pyx_temp, __pyx_int_0);
+    }
+  }
+  __Pyx_GIVEREF(__pyx_tuple__17);
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":105
+ *         if exponent < 0:
+ *             if -exponent > MAX_DSCALE:
+ *                 raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'cannot encode Decimal value into numeric: '
+ *                     'exponent is too small')
+ */
+  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_u_cannot_encode_Decimal_value_into); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(6, 105, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__14);
+  __Pyx_GIVEREF(__pyx_tuple__14);
+
+  /* "asyncpg/pgproto/codecs/bits.pyx":32
+ *     try:
+ *         if bitlen > _MAXINT32:
+ *             raise ValueError('bit value too long')             # <<<<<<<<<<<<<<
+ *         wbuf.write_int32(4 + <int32_t>len)
+ *         wbuf.write_int32(<int32_t>bitlen)
+ */
+  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_u_bit_value_too_long); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(12, 32, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__18);
+  __Pyx_GIVEREF(__pyx_tuple__18);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":114
+ *     encoded_len = 1 + 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:
+ *         raise ValueError('path value too long')             # <<<<<<<<<<<<<<
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ */
+  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_u_path_value_too_long); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(13, 114, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__19);
+  __Pyx_GIVEREF(__pyx_tuple__19);
+
+  /* "asyncpg/pgproto/codecs/geometry.pyx":140
+ *     encoded_len = 4 + 16 * npts
+ *     if encoded_len > _MAXINT32:
+ *         raise ValueError('polygon value too long')             # <<<<<<<<<<<<<<
+ * 
+ *     wbuf.write_int32(<int32_t>encoded_len)
+ */
+  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_u_polygon_value_too_long); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(13, 140, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__20);
+  __Pyx_GIVEREF(__pyx_tuple__20);
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":18
+ *     count = len(obj)
+ *     if count > _MAXINT32:
+ *         raise ValueError('hstore value is too large')             # <<<<<<<<<<<<<<
+ *     item_buf.write_int32(<int32_t>count)
+ * 
+ */
+  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_u_hstore_value_is_too_large); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(14, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__21);
+  __Pyx_GIVEREF(__pyx_tuple__21);
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":28
+ *     for k, v in items:
+ *         if k is None:
+ *             raise ValueError('null value not allowed in hstore key')             # <<<<<<<<<<<<<<
+ *         as_pg_string_and_size(settings, k, &str, &size)
+ *         item_buf.write_int32(<int32_t>size)
+ */
+  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_u_null_value_not_allowed_in_hstore); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(14, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__22);
+  __Pyx_GIVEREF(__pyx_tuple__22);
+
+  /* "asyncpg/pgproto/codecs/hstore.pyx":61
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len < 0:
+ *             raise ValueError('null value not allowed in hstore key')             # <<<<<<<<<<<<<<
+ * 
+ *         k = decode_pg_string(settings, frb_read(buf, elem_len), elem_len)
+ */
+  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_u_null_value_not_allowed_in_hstore); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(14, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__22);
+  __Pyx_GIVEREF(__pyx_tuple__22);
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":17
+ * 
+ *     if len(obj) != 2:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'invalid number of elements in tid tuple, expecting 2')
+ * 
+ */
+  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_invalid_number_of_elements_in_ti); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(17, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__23);
+  __Pyx_GIVEREF(__pyx_tuple__23);
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":27
+ *     # "long" and "long long" have the same size for x86_64, need an extra check
+ *     if overflow or (sizeof(block) > 4 and block > UINT32_MAX):
+ *         raise OverflowError('tuple id block value out of uint32 range')             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_tuple_id_block_value_out_of_uint); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(17, 27, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__24);
+  __Pyx_GIVEREF(__pyx_tuple__24);
+
+  /* "asyncpg/pgproto/codecs/tid.pyx":36
+ * 
+ *     if overflow or offset > 65535:
+ *         raise OverflowError('tuple id offset value out of uint16 range')             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(6)
+ */
+  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_tuple_id_offset_value_out_of_uin); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(17, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__25);
+  __Pyx_GIVEREF(__pyx_tuple__25);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":21
+ * 
+ *     if len(obj) != 3:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'invalid number of elements in txid_snapshot tuple, expecting 4')
+ * 
+ */
+  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_u_invalid_number_of_elements_in_tx); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(18, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__26);
+  __Pyx_GIVEREF(__pyx_tuple__26);
+
+  /* "asyncpg/pgproto/codecs/txid.pyx":26
+ *     nxip = len(obj[2])
+ *     if nxip > _MAXINT32:
+ *         raise ValueError('txid_snapshot value is too long')             # <<<<<<<<<<<<<<
+ * 
+ *     xmin = obj[0]
+ */
+  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_u_txid_snapshot_value_is_too_long); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(18, 26, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__27);
+  __Pyx_GIVEREF(__pyx_tuple__27);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":17
+ * timedelta = datetime.timedelta
+ * 
+ * pg_epoch_datetime = datetime.datetime(2000, 1, 1)             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_epoch_datetime_ts = \
+ *     <int32_t>cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))
+ */
+  __pyx_tuple__28 = PyTuple_Pack(3, __pyx_int_2000, __pyx_int_1, __pyx_int_1); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(8, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__28);
+  __Pyx_GIVEREF(__pyx_tuple__28);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":21
+ *     <int32_t>cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))
+ * 
+ * pg_epoch_datetime_utc = datetime.datetime(2000, 1, 1, tzinfo=utc)             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_epoch_datetime_utc_ts = \
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())
+ */
+  __pyx_tuple__28 = PyTuple_Pack(3, __pyx_int_2000, __pyx_int_1, __pyx_int_1); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__28);
+  __Pyx_GIVEREF(__pyx_tuple__28);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":25
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())
+ * 
+ * pg_epoch_date = datetime.date(2000, 1, 1)             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_date_offset_ord = \
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())
+ */
+  __pyx_tuple__28 = PyTuple_Pack(3, __pyx_int_2000, __pyx_int_1, __pyx_int_1); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(8, 25, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__28);
+  __Pyx_GIVEREF(__pyx_tuple__28);
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0xd41d8cd:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+  __pyx_tuple__29 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__29);
+  __Pyx_GIVEREF(__pyx_tuple__29);
+  __pyx_codeobj__30 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_CodecContext, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__30)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
+  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(22, 1, __pyx_L1_error);
+  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_12 = PyInt_FromLong(12); if (unlikely(!__pyx_int_12)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_23 = PyInt_FromLong(23); if (unlikely(!__pyx_int_23)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_31 = PyInt_FromLong(31); if (unlikely(!__pyx_int_31)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_59 = PyInt_FromLong(59); if (unlikely(!__pyx_int_59)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_100 = PyInt_FromLong(100); if (unlikely(!__pyx_int_100)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_2000 = PyInt_FromLong(2000); if (unlikely(!__pyx_int_2000)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_999999 = PyInt_FromLong(999999L); if (unlikely(!__pyx_int_999999)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_int_222419149 = PyInt_FromLong(222419149L); if (unlikely(!__pyx_int_222419149)) __PYX_ERR(22, 1, __pyx_L1_error)
+  return 0;
+  __pyx_L1_error:;
+  return -1;
+}
+
+static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
+
+static int __Pyx_modinit_global_init_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
+  /*--- Global init code ---*/
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+static int __Pyx_modinit_variable_export_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
+  /*--- Variable export code ---*/
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+static int __Pyx_modinit_function_export_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
+  /*--- Function export code ---*/
+  if (__Pyx_ExportFunction("frb_check", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_frb_check, "PyObject *(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("date_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("date_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("date_encode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("date_decode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timestamp_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timestamp_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timestamp_encode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timestamp_decode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timestamptz_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timestamptz_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("time_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("time_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("time_encode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("time_decode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timetz_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timetz_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timetz_encode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("timetz_decode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("interval_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("interval_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("interval_encode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("interval_decode_tuple", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("bits_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_bits_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("bits_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_bits_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("bool_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_bool_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("bool_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_bool_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("box_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_box_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("box_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_box_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("line_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_line_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("line_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_line_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("lseg_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("lseg_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("point_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_point_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("point_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_point_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("path_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_path_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("path_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_path_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("poly_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_poly_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("poly_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_poly_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("circle_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_circle_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("circle_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_circle_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("hstore_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("hstore_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("int2_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_int2_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("int2_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_int2_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("int4_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_int4_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("int4_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_int4_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("uint4_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("uint4_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("int8_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_int8_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("int8_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_int8_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("float4_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_float4_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("float4_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_float4_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("float8_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_float8_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("float8_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_float8_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("jsonb_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("jsonb_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("as_pg_string_and_size", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, PyObject *, char **, Py_ssize_t *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("text_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("text_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("bytea_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("bytea_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("uuid_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("uuid_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("numeric_encode_text", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_text, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("numeric_decode_text", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_text, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("numeric_encode_binary", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_binary, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("numeric_decode_binary", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_binary, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("void_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_void_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("void_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_void_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("tid_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_tid_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("tid_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_tid_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("net_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_net_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("cidr_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("inet_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_inet_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("txid_snapshot_encode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  if (__Pyx_ExportFunction("txid_snapshot_decode", (void (*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static int __Pyx_modinit_type_init_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
+  /*--- Type init code ---*/
+  __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer = &__pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.len = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer._check_readonly = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__check_readonly;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer._ensure_alloced = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__ensure_alloced;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer._reallocate = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer__reallocate;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.start_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_start_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.end_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_end_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_buffer = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_buffer;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_byte = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_byte;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_bytes = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytes;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_bytestring = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_bytestring;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_str = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, PyObject *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_str;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_utf8 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_utf8;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_cstr = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char const *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_cstr;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_int16 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int16_t))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int16;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_int32 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int32;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_int64 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int64_t))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_int64;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_float = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, float))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_float;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.write_double = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, double))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_write_double;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.new_message = (struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*)(char))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_WriteBuffer.new = (struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*)(void))__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_new;
+  if (PyType_Ready(&__pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer) < 0) __PYX_ERR(1, 18, __pyx_L1_error)
+  __pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer.tp_dictoffset && __pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer.tp_dict, __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer) < 0) __PYX_ERR(1, 18, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_WriteBuffer, (PyObject *)&__pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer) < 0) __PYX_ERR(1, 18, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer) < 0) __PYX_ERR(1, 18, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer = &__pyx_type_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+  __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer = &__pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.len = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.get_message_type = (char (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.get_message_length = (int32_t (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.read_utf8 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.feed_data = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, PyObject *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_feed_data;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer._ensure_first_buf = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__ensure_first_buf;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer._switch_to_next_buf = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__switch_to_next_buf;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.read_byte = (char (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_byte;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer._try_read_bytes = (char const *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__try_read_bytes;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer._read_into = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_into;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer._read_and_discard = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__read_and_discard;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.read_bytes = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_bytes;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.read_int32 = (int32_t (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int32;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.read_int16 = (int16_t (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_int16;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.read_cstr = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_cstr;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.take_message = (int32_t (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.take_message_type = (int32_t (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_take_message_type;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.put_message = (int32_t (*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_put_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.try_consume_message = (char const *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_try_consume_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.consume_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.discard_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_discard_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.redirect_messages = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_redirect_messages;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.consume_messages = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_consume_messages;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.finish_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_finish_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer._finish_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer__finish_message;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_ReadBuffer.new_message_parser = (struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *(*)(PyObject *))__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_new_message_parser;
+  if (PyType_Ready(&__pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer) < 0) __PYX_ERR(1, 216, __pyx_L1_error)
+  __pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer.tp_dictoffset && __pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer.tp_dict, __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer) < 0) __PYX_ERR(1, 216, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ReadBuffer, (PyObject *)&__pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer) < 0) __PYX_ERR(1, 216, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer) < 0) __PYX_ERR(1, 216, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer = &__pyx_type_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+  __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext = &__pyx_vtable_7asyncpg_7pgproto_7pgproto_CodecContext;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_CodecContext.get_text_codec = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_get_text_codec;
+  __pyx_vtable_7asyncpg_7pgproto_7pgproto_CodecContext.is_encoding_utf8 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *))__pyx_f_7asyncpg_7pgproto_7pgproto_12CodecContext_is_encoding_utf8;
+  if (PyType_Ready(&__pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext) < 0) __PYX_ERR(3, 8, __pyx_L1_error)
+  __pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext.tp_dictoffset && __pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext.tp_getattro = __Pyx_PyObject_GenericGetAttr;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext.tp_dict, __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext) < 0) __PYX_ERR(3, 8, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CodecContext, (PyObject *)&__pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext) < 0) __PYX_ERR(3, 8, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext) < 0) __PYX_ERR(3, 8, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext = &__pyx_type_7asyncpg_7pgproto_7pgproto_CodecContext;
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static int __Pyx_modinit_type_import_code(void) {
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
+  /*--- Type import code ---*/
+  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(23, 9, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", 
+  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
+  sizeof(PyTypeObject),
+  #else
+  sizeof(PyHeapTypeObject),
+  #endif
+  __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(23, 9, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(24, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(24, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(25, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(25, 15, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyImport_ImportModule("datetime"); if (unlikely(!__pyx_t_1)) __PYX_ERR(21, 9, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_8datetime_date = __Pyx_ImportType(__pyx_t_1, "datetime", "date", sizeof(PyDateTime_Date), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_8datetime_date) __PYX_ERR(21, 9, __pyx_L1_error)
+  __pyx_ptype_7cpython_8datetime_time = __Pyx_ImportType(__pyx_t_1, "datetime", "time", sizeof(PyDateTime_Time), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_8datetime_time) __PYX_ERR(21, 12, __pyx_L1_error)
+  __pyx_ptype_7cpython_8datetime_datetime = __Pyx_ImportType(__pyx_t_1, "datetime", "datetime", sizeof(PyDateTime_DateTime), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_8datetime_datetime) __PYX_ERR(21, 15, __pyx_L1_error)
+  __pyx_ptype_7cpython_8datetime_timedelta = __Pyx_ImportType(__pyx_t_1, "datetime", "timedelta", sizeof(PyDateTime_Delta), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_8datetime_timedelta) __PYX_ERR(21, 18, __pyx_L1_error)
+  __pyx_ptype_7cpython_8datetime_tzinfo = __Pyx_ImportType(__pyx_t_1, "datetime", "tzinfo", sizeof(PyDateTime_TZInfo), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_8datetime_tzinfo) __PYX_ERR(21, 21, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static int __Pyx_modinit_variable_import_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
+  /*--- Variable import code ---*/
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+static int __Pyx_modinit_function_import_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
+  /*--- Function import code ---*/
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+
+#if PY_MAJOR_VERSION < 3
+#ifdef CYTHON_NO_PYINIT_EXPORT
+#define __Pyx_PyMODINIT_FUNC void
+#else
+#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
+#endif
+#else
+#ifdef CYTHON_NO_PYINIT_EXPORT
+#define __Pyx_PyMODINIT_FUNC PyObject *
+#else
+#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
+#endif
+#endif
+
+
+#if PY_MAJOR_VERSION < 3
+__Pyx_PyMODINIT_FUNC initpgproto(void) CYTHON_SMALL_CODE; /*proto*/
+__Pyx_PyMODINIT_FUNC initpgproto(void)
+#else
+__Pyx_PyMODINIT_FUNC PyInit_pgproto(void) CYTHON_SMALL_CODE; /*proto*/
+__Pyx_PyMODINIT_FUNC PyInit_pgproto(void)
+#if CYTHON_PEP489_MULTI_PHASE_INIT
+{
+  return PyModuleDef_Init(&__pyx_moduledef);
+}
+static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
+    #if PY_VERSION_HEX >= 0x030700A1
+    static PY_INT64_T main_interpreter_id = -1;
+    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
+    if (main_interpreter_id == -1) {
+        main_interpreter_id = current_id;
+        return (unlikely(current_id == -1)) ? -1 : 0;
+    } else if (unlikely(main_interpreter_id != current_id))
+    #else
+    static PyInterpreterState *main_interpreter = NULL;
+    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
+    if (!main_interpreter) {
+        main_interpreter = current_interpreter;
+    } else if (unlikely(main_interpreter != current_interpreter))
+    #endif
+    {
+        PyErr_SetString(
+            PyExc_ImportError,
+            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
+        return -1;
+    }
+    return 0;
+}
+static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
+    PyObject *value = PyObject_GetAttrString(spec, from_name);
+    int result = 0;
+    if (likely(value)) {
+        result = PyDict_SetItemString(moddict, to_name, value);
+        Py_DECREF(value);
+    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+        PyErr_Clear();
+    } else {
+        result = -1;
+    }
+    return result;
+}
+static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
+    PyObject *module = NULL, *moddict, *modname;
+    if (__Pyx_check_single_interpreter())
+        return NULL;
+    if (__pyx_m)
+        return __Pyx_NewRef(__pyx_m);
+    modname = PyObject_GetAttrString(spec, "name");
+    if (unlikely(!modname)) goto bad;
+    module = PyModule_NewObject(modname);
+    Py_DECREF(modname);
+    if (unlikely(!module)) goto bad;
+    moddict = PyModule_GetDict(module);
+    if (unlikely(!moddict)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
+    return module;
+bad:
+    Py_XDECREF(module);
+    return NULL;
+}
+
+
+static CYTHON_SMALL_CODE int __pyx_pymod_exec_pgproto(PyObject *__pyx_pyinit_module)
+#endif
+#endif
+{
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  long __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannyDeclarations
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+  if (__pyx_m) {
+    if (__pyx_m == __pyx_pyinit_module) return 0;
+    PyErr_SetString(PyExc_RuntimeError, "Module 'pgproto' has already been imported. Re-initialisation is not supported.");
+    return -1;
+  }
+  #elif PY_MAJOR_VERSION >= 3
+  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
+  #endif
+  #if CYTHON_REFNANNY
+__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+if (!__Pyx_RefNanny) {
+  PyErr_Clear();
+  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+  if (!__Pyx_RefNanny)
+      Py_FatalError("failed to import 'refnanny' module");
+}
+#endif
+  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_pgproto(void)", 0);
+  if (__Pyx_check_binary_version() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #ifdef __Pxy_PyFrame_Initialize_Offsets
+  __Pxy_PyFrame_Initialize_Offsets();
+  #endif
+  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(22, 1, __pyx_L1_error)
+  #ifdef __Pyx_CyFunction_USED
+  if (__pyx_CyFunction_init() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_FusedFunction_USED
+  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_Coroutine_USED
+  if (__pyx_Coroutine_init() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_Generator_USED
+  if (__pyx_Generator_init() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_AsyncGen_USED
+  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_StopAsyncIteration_USED
+  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  /*--- Library function declarations ---*/
+  /*--- Threads initialization code ---*/
+  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+  #ifdef WITH_THREAD /* Python build with threading support? */
+  PyEval_InitThreads();
+  #endif
+  #endif
+  /*--- Module creation code ---*/
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+  __pyx_m = __pyx_pyinit_module;
+  Py_INCREF(__pyx_m);
+  #else
+  #if PY_MAJOR_VERSION < 3
+  __pyx_m = Py_InitModule4("pgproto", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+  #else
+  __pyx_m = PyModule_Create(&__pyx_moduledef);
+  #endif
+  if (unlikely(!__pyx_m)) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(22, 1, __pyx_L1_error)
+  Py_INCREF(__pyx_d);
+  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(22, 1, __pyx_L1_error)
+  #if CYTHON_COMPILING_IN_PYPY
+  Py_INCREF(__pyx_b);
+  #endif
+  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(22, 1, __pyx_L1_error);
+  /*--- Initialize various global constants etc. ---*/
+  if (__Pyx_InitGlobals() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
+  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+  if (__pyx_module_is_main_asyncpg__pgproto__pgproto) {
+    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  }
+  #if PY_MAJOR_VERSION >= 3
+  {
+    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(22, 1, __pyx_L1_error)
+    if (!PyDict_GetItemString(modules, "asyncpg.pgproto.pgproto")) {
+      if (unlikely(PyDict_SetItemString(modules, "asyncpg.pgproto.pgproto", __pyx_m) < 0)) __PYX_ERR(22, 1, __pyx_L1_error)
+    }
+  }
+  #endif
+  /*--- Builtin init code ---*/
+  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  /*--- Constants init code ---*/
+  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  /*--- Global type/function init code ---*/
+  (void)__Pyx_modinit_global_init_code();
+  (void)__Pyx_modinit_variable_export_code();
+  if (unlikely(__Pyx_modinit_function_export_code() != 0)) goto __pyx_L1_error;
+  if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error;
+  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
+  (void)__Pyx_modinit_variable_import_code();
+  (void)__Pyx_modinit_function_import_code();
+  /*--- Execution code ---*/
+  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+  if (__Pyx_patch_abc() < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  #endif
+
+  /* "asyncpg/pgproto/pgproto.pyx":22
+ * 
+ * from .debug cimport PG_DEBUG
+ * from . import types as pgproto_types             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(22, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_types);
+  __Pyx_GIVEREF(__pyx_n_s_types);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_types);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s__3, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(22, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(22, 22, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pgproto_types, __pyx_t_1) < 0) __PYX_ERR(22, 22, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":10
+ * from libc.string cimport memcpy
+ * 
+ * import collections             # <<<<<<<<<<<<<<
+ * 
+ * from . import exceptions
+ */
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_collections, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_2) < 0) __PYX_ERR(1, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/buffer.pyx":12
+ * import collections
+ * 
+ * from . import exceptions             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s__3, __pyx_t_2, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exceptions, __pyx_t_2) < 0) __PYX_ERR(1, 12, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":9
+ * 
+ * cimport cpython.datetime
+ * import datetime             # <<<<<<<<<<<<<<
+ * 
+ * cpython.datetime.import_datetime()
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_datetime, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 9, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_datetime, __pyx_t_1) < 0) __PYX_ERR(8, 9, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":11
+ * import datetime
+ * 
+ * cpython.datetime.import_datetime()             # <<<<<<<<<<<<<<
+ * 
+ * utc = datetime.timezone.utc
+ */
+  __pyx_f_7cpython_8datetime_import_datetime();
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":13
+ * cpython.datetime.import_datetime()
+ * 
+ * utc = datetime.timezone.utc             # <<<<<<<<<<<<<<
+ * date_from_ordinal = datetime.date.fromordinal
+ * timedelta = datetime.timedelta
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_timezone); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_utc); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_utc, __pyx_t_1) < 0) __PYX_ERR(8, 13, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":14
+ * 
+ * utc = datetime.timezone.utc
+ * date_from_ordinal = datetime.date.fromordinal             # <<<<<<<<<<<<<<
+ * timedelta = datetime.timedelta
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_date); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_fromordinal); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_date_from_ordinal, __pyx_t_1) < 0) __PYX_ERR(8, 14, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":15
+ * utc = datetime.timezone.utc
+ * date_from_ordinal = datetime.date.fromordinal
+ * timedelta = datetime.timedelta             # <<<<<<<<<<<<<<
+ * 
+ * pg_epoch_datetime = datetime.datetime(2000, 1, 1)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_timedelta); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_timedelta, __pyx_t_2) < 0) __PYX_ERR(8, 15, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":17
+ * timedelta = datetime.timedelta
+ * 
+ * pg_epoch_datetime = datetime.datetime(2000, 1, 1)             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_epoch_datetime_ts = \
+ *     <int32_t>cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pg_epoch_datetime, __pyx_t_2) < 0) __PYX_ERR(8, 17, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":19
+ * pg_epoch_datetime = datetime.datetime(2000, 1, 1)
+ * cdef int32_t pg_epoch_datetime_ts = \
+ *     <int32_t>cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))             # <<<<<<<<<<<<<<
+ * 
+ * pg_epoch_datetime_utc = datetime.datetime(2000, 1, 1, tzinfo=utc)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pg_epoch_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_timestamp); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 19, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_epoch_datetime_ts = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":21
+ *     <int32_t>cpython.PyLong_AsLong(int(pg_epoch_datetime.timestamp()))
+ * 
+ * pg_epoch_datetime_utc = datetime.datetime(2000, 1, 1, tzinfo=utc)             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_epoch_datetime_utc_ts = \
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_utc); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_tzinfo, __pyx_t_4) < 0) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__28, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pg_epoch_datetime_utc, __pyx_t_4) < 0) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":23
+ * pg_epoch_datetime_utc = datetime.datetime(2000, 1, 1, tzinfo=utc)
+ * cdef int32_t pg_epoch_datetime_utc_ts = \
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())             # <<<<<<<<<<<<<<
+ * 
+ * pg_epoch_date = datetime.date(2000, 1, 1)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pg_epoch_datetime_utc); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 23, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_timestamp); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 23, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 23, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_4); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 23, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_epoch_datetime_utc_ts = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":25
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_datetime_utc.timestamp())
+ * 
+ * pg_epoch_date = datetime.date(2000, 1, 1)             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_date_offset_ord = \
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 25, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_date); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 25, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 25, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pg_epoch_date, __pyx_t_4) < 0) __PYX_ERR(8, 25, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":27
+ * pg_epoch_date = datetime.date(2000, 1, 1)
+ * cdef int32_t pg_date_offset_ord = \
+ *     <int32_t>cpython.PyLong_AsLong(pg_epoch_date.toordinal())             # <<<<<<<<<<<<<<
+ * 
+ * # Binary representations of infinity for datetimes.
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pg_epoch_date); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 27, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_toordinal); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 27, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 27, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_4); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 27, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_offset_ord = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":30
+ * 
+ * # Binary representations of infinity for datetimes.
+ * cdef int64_t pg_time64_infinity = 0x7fffffffffffffff             # <<<<<<<<<<<<<<
+ * cdef int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
+ * cdef int32_t pg_date_infinity = 0x7fffffff
+ */
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_infinity = 0x7fffffffffffffff;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":31
+ * # Binary representations of infinity for datetimes.
+ * cdef int64_t pg_time64_infinity = 0x7fffffffffffffff
+ * cdef int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_date_infinity = 0x7fffffff
+ * cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000
+ */
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_time64_negative_infinity = ((int64_t)0x8000000000000000);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":32
+ * cdef int64_t pg_time64_infinity = 0x7fffffffffffffff
+ * cdef int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
+ * cdef int32_t pg_date_infinity = 0x7fffffff             # <<<<<<<<<<<<<<
+ * cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000
+ * 
+ */
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_infinity = 0x7fffffff;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":33
+ * cdef int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
+ * cdef int32_t pg_date_infinity = 0x7fffffff
+ * cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000             # <<<<<<<<<<<<<<
+ * 
+ * infinity_datetime = datetime.datetime(
+ */
+  __pyx_v_7asyncpg_7pgproto_7pgproto_pg_date_negative_infinity = ((int32_t)0x80000000);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":35
+ * cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000
+ * 
+ * infinity_datetime = datetime.datetime(             # <<<<<<<<<<<<<<
+ *     datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":36
+ * 
+ * infinity_datetime = datetime.datetime(
+ *     datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)             # <<<<<<<<<<<<<<
+ * 
+ * cdef int32_t infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_MAXYEAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":35
+ * cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000
+ * 
+ * infinity_datetime = datetime.datetime(             # <<<<<<<<<<<<<<
+ *     datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
+ * 
+ */
+  __pyx_t_4 = PyTuple_New(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
+  __Pyx_INCREF(__pyx_int_12);
+  __Pyx_GIVEREF(__pyx_int_12);
+  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_12);
+  __Pyx_INCREF(__pyx_int_31);
+  __Pyx_GIVEREF(__pyx_int_31);
+  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_31);
+  __Pyx_INCREF(__pyx_int_23);
+  __Pyx_GIVEREF(__pyx_int_23);
+  PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_int_23);
+  __Pyx_INCREF(__pyx_int_59);
+  __Pyx_GIVEREF(__pyx_int_59);
+  PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_int_59);
+  __Pyx_INCREF(__pyx_int_59);
+  __Pyx_GIVEREF(__pyx_int_59);
+  PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_int_59);
+  __Pyx_INCREF(__pyx_int_999999);
+  __Pyx_GIVEREF(__pyx_int_999999);
+  PyTuple_SET_ITEM(__pyx_t_4, 6, __pyx_int_999999);
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_infinity_datetime, __pyx_t_2) < 0) __PYX_ERR(8, 35, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":39
+ * 
+ * cdef int32_t infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(
+ *     infinity_datetime.toordinal())             # <<<<<<<<<<<<<<
+ * 
+ * cdef int64_t infinity_datetime_ts = 252455615999999999
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_infinity_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_toordinal); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":38
+ *     datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
+ * 
+ * cdef int32_t infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(             # <<<<<<<<<<<<<<
+ *     infinity_datetime.toordinal())
+ * 
+ */
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_2); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 38, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_datetime_ord = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":41
+ *     infinity_datetime.toordinal())
+ * 
+ * cdef int64_t infinity_datetime_ts = 252455615999999999             # <<<<<<<<<<<<<<
+ * 
+ * negative_infinity_datetime = datetime.datetime(
+ */
+  __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_datetime_ts = 0x380E70B913B7FFF;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":43
+ * cdef int64_t infinity_datetime_ts = 252455615999999999
+ * 
+ * negative_infinity_datetime = datetime.datetime(             # <<<<<<<<<<<<<<
+ *     datetime.MINYEAR, 1, 1, 0, 0, 0, 0)
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":44
+ * 
+ * negative_infinity_datetime = datetime.datetime(
+ *     datetime.MINYEAR, 1, 1, 0, 0, 0, 0)             # <<<<<<<<<<<<<<
+ * 
+ * cdef int32_t negative_infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datetime); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 44, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_MINYEAR); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 44, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":43
+ * cdef int64_t infinity_datetime_ts = 252455615999999999
+ * 
+ * negative_infinity_datetime = datetime.datetime(             # <<<<<<<<<<<<<<
+ *     datetime.MINYEAR, 1, 1, 0, 0, 0, 0)
+ * 
+ */
+  __pyx_t_2 = PyTuple_New(7); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+  __Pyx_INCREF(__pyx_int_1);
+  __Pyx_GIVEREF(__pyx_int_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1);
+  __Pyx_INCREF(__pyx_int_1);
+  __Pyx_GIVEREF(__pyx_int_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_1);
+  __Pyx_INCREF(__pyx_int_0);
+  __Pyx_GIVEREF(__pyx_int_0);
+  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_0);
+  __Pyx_INCREF(__pyx_int_0);
+  __Pyx_GIVEREF(__pyx_int_0);
+  PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_int_0);
+  __Pyx_INCREF(__pyx_int_0);
+  __Pyx_GIVEREF(__pyx_int_0);
+  PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_int_0);
+  __Pyx_INCREF(__pyx_int_0);
+  __Pyx_GIVEREF(__pyx_int_0);
+  PyTuple_SET_ITEM(__pyx_t_2, 6, __pyx_int_0);
+  __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_negative_infinity_datetime, __pyx_t_1) < 0) __PYX_ERR(8, 43, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":47
+ * 
+ * cdef int32_t negative_infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(
+ *     negative_infinity_datetime.toordinal())             # <<<<<<<<<<<<<<
+ * 
+ * cdef int64_t negative_infinity_datetime_ts = -63082281600000000
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_negative_infinity_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_toordinal); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 47, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":46
+ *     datetime.MINYEAR, 1, 1, 0, 0, 0, 0)
+ * 
+ * cdef int32_t negative_infinity_datetime_ord = <int32_t>cpython.PyLong_AsLong(             # <<<<<<<<<<<<<<
+ *     negative_infinity_datetime.toordinal())
+ * 
+ */
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_1); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 46, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_datetime_ord = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":49
+ *     negative_infinity_datetime.toordinal())
+ * 
+ * cdef int64_t negative_infinity_datetime_ts = -63082281600000000             # <<<<<<<<<<<<<<
+ * 
+ * infinity_date = datetime.date(datetime.MAXYEAR, 12, 31)
+ */
+  __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_datetime_ts = -63082281600000000L;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":51
+ * cdef int64_t negative_infinity_datetime_ts = -63082281600000000
+ * 
+ * infinity_date = datetime.date(datetime.MAXYEAR, 12, 31)             # <<<<<<<<<<<<<<
+ * 
+ * cdef int32_t infinity_date_ord = <int32_t>cpython.PyLong_AsLong(
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_date); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_datetime); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_MAXYEAR); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_4);
+  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
+  __Pyx_INCREF(__pyx_int_12);
+  __Pyx_GIVEREF(__pyx_int_12);
+  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_12);
+  __Pyx_INCREF(__pyx_int_31);
+  __Pyx_GIVEREF(__pyx_int_31);
+  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_31);
+  __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_infinity_date, __pyx_t_4) < 0) __PYX_ERR(8, 51, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":54
+ * 
+ * cdef int32_t infinity_date_ord = <int32_t>cpython.PyLong_AsLong(
+ *     infinity_date.toordinal())             # <<<<<<<<<<<<<<
+ * 
+ * negative_infinity_date = datetime.date(datetime.MINYEAR, 1, 1)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_infinity_date); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_toordinal); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 54, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":53
+ * infinity_date = datetime.date(datetime.MAXYEAR, 12, 31)
+ * 
+ * cdef int32_t infinity_date_ord = <int32_t>cpython.PyLong_AsLong(             # <<<<<<<<<<<<<<
+ *     infinity_date.toordinal())
+ * 
+ */
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_4); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 53, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_infinity_date_ord = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":56
+ *     infinity_date.toordinal())
+ * 
+ * negative_infinity_date = datetime.date(datetime.MINYEAR, 1, 1)             # <<<<<<<<<<<<<<
+ * 
+ * cdef int32_t negative_infinity_date_ord = <int32_t>cpython.PyLong_AsLong(
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_date); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_MINYEAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
+  __Pyx_INCREF(__pyx_int_1);
+  __Pyx_GIVEREF(__pyx_int_1);
+  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
+  __Pyx_INCREF(__pyx_int_1);
+  __Pyx_GIVEREF(__pyx_int_1);
+  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_1);
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_negative_infinity_date, __pyx_t_2) < 0) __PYX_ERR(8, 56, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":59
+ * 
+ * cdef int32_t negative_infinity_date_ord = <int32_t>cpython.PyLong_AsLong(
+ *     negative_infinity_date.toordinal())             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_negative_infinity_date); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_toordinal); if (unlikely(!__pyx_t_4)) __PYX_ERR(8, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(8, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/datetime.pyx":58
+ * negative_infinity_date = datetime.date(datetime.MINYEAR, 1, 1)
+ * 
+ * cdef int32_t negative_infinity_date_ord = <int32_t>cpython.PyLong_AsLong(             # <<<<<<<<<<<<<<
+ *     negative_infinity_date.toordinal())
+ * 
+ */
+  __pyx_t_3 = PyLong_AsLong(__pyx_t_2); if (unlikely(__pyx_t_3 == ((long)-1L) && PyErr_Occurred())) __PYX_ERR(8, 58, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_7asyncpg_7pgproto_7pgproto_negative_infinity_date_ord = ((int32_t)__pyx_t_3);
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":8
+ * 
+ * 
+ * import uuid             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_uuid, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(11, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_uuid, __pyx_t_2) < 0) __PYX_ERR(11, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/uuid.pyx":11
+ * 
+ * 
+ * _UUID = uuid.UUID             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_uuid); if (unlikely(!__pyx_t_2)) __PYX_ERR(11, 11, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_UUID_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(11, 11, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_UUID, __pyx_t_4) < 0) __PYX_ERR(11, 11, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":11
+ * from libc.stdio cimport snprintf
+ * 
+ * import decimal             # <<<<<<<<<<<<<<
+ * 
+ * # defined in postgresql/src/backend/utils/adt/numeric.c
+ */
+  __pyx_t_4 = __Pyx_Import(__pyx_n_s_decimal, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 11, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_decimal, __pyx_t_4) < 0) __PYX_ERR(6, 11, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/numeric.pyx":20
+ * DEF NUMERIC_NAN = 0xC000
+ * 
+ * _Dec = decimal.Decimal             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_decimal); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 20, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_2)) __PYX_ERR(6, 20, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Dec, __pyx_t_2) < 0) __PYX_ERR(6, 20, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":8
+ * 
+ * 
+ * import ipaddress             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_ipaddress, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ipaddress, __pyx_t_2) < 0) __PYX_ERR(16, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":17
+ * 
+ * 
+ * _ipaddr = ipaddress.ip_address             # <<<<<<<<<<<<<<
+ * _ipnet = ipaddress.ip_network
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ipaddress); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ip_address); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ipaddr, __pyx_t_4) < 0) __PYX_ERR(16, 17, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/pgproto/codecs/network.pyx":18
+ * 
+ * _ipaddr = ipaddress.ip_address
+ * _ipnet = ipaddress.ip_network             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ipaddress); if (unlikely(!__pyx_t_4)) __PYX_ERR(16, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ip_network); if (unlikely(!__pyx_t_2)) __PYX_ERR(16, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ipnet, __pyx_t_2) < 0) __PYX_ERR(16, 18, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_CodecContext(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0xd41d8cd:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_7asyncpg_7pgproto_7pgproto_1__pyx_unpickle_CodecContext, NULL, __pyx_n_s_asyncpg_pgproto_pgproto); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_CodecContext, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/pgproto/pgproto.pyx":1
+ * # Copyright (C) 2016-present the asyncpg authors and contributors             # <<<<<<<<<<<<<<
+ * # <see AUTHORS file>
+ * #
+ */
+  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(22, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(22, 1, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "cpython/datetime.pxd":211
+ * 
+ * # Get microseconds of timedelta
+ * cdef inline int timedelta_microseconds(object o):             # <<<<<<<<<<<<<<
+ *     return (<PyDateTime_Delta*>o).microseconds
+ */
+
+  /*--- Wrapped vars code ---*/
+
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_4);
+  if (__pyx_m) {
+    if (__pyx_d) {
+      __Pyx_AddTraceback("init asyncpg.pgproto.pgproto", __pyx_clineno, __pyx_lineno, __pyx_filename);
+    }
+    Py_CLEAR(__pyx_m);
+  } else if (!PyErr_Occurred()) {
+    PyErr_SetString(PyExc_ImportError, "init asyncpg.pgproto.pgproto");
+  }
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+  return (__pyx_m != NULL) ? 0 : -1;
+  #elif PY_MAJOR_VERSION >= 3
+  return __pyx_m;
+  #else
+  return;
+  #endif
+}
+
+/* --- Runtime support code --- */
+/* Refnanny */
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+    PyObject *m = NULL, *p = NULL;
+    void *r = NULL;
+    m = PyImport_ImportModule(modname);
+    if (!m) goto end;
+    p = PyObject_GetAttrString(m, "RefNannyAPI");
+    if (!p) goto end;
+    r = PyLong_AsVoidPtr(p);
+end:
+    Py_XDECREF(p);
+    Py_XDECREF(m);
+    return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif
+
+/* PyObjectGetAttrStr */
+#if CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
+    PyTypeObject* tp = Py_TYPE(obj);
+    if (likely(tp->tp_getattro))
+        return tp->tp_getattro(obj, attr_name);
+#if PY_MAJOR_VERSION < 3
+    if (likely(tp->tp_getattr))
+        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
+#endif
+    return PyObject_GetAttr(obj, attr_name);
+}
+#endif
+
+/* GetBuiltinName */
+static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
+    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
+    if (unlikely(!result)) {
+        PyErr_Format(PyExc_NameError,
+#if PY_MAJOR_VERSION >= 3
+            "name '%U' is not defined", name);
+#else
+            "name '%.200s' is not defined", PyString_AS_STRING(name));
+#endif
+    }
+    return result;
+}
+
+/* CIntToDigits */
+static const char DIGIT_PAIRS_10[2*10*10+1] = {
+    "00010203040506070809"
+    "10111213141516171819"
+    "20212223242526272829"
+    "30313233343536373839"
+    "40414243444546474849"
+    "50515253545556575859"
+    "60616263646566676869"
+    "70717273747576777879"
+    "80818283848586878889"
+    "90919293949596979899"
+};
+static const char DIGIT_PAIRS_8[2*8*8+1] = {
+    "0001020304050607"
+    "1011121314151617"
+    "2021222324252627"
+    "3031323334353637"
+    "4041424344454647"
+    "5051525354555657"
+    "6061626364656667"
+    "7071727374757677"
+};
+static const char DIGITS_HEX[2*16+1] = {
+    "0123456789abcdef"
+    "0123456789ABCDEF"
+};
+
+/* BuildPyUnicode */
+static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
+                                                int prepend_sign, char padding_char) {
+    PyObject *uval;
+    Py_ssize_t uoffset = ulength - clength;
+#if CYTHON_USE_UNICODE_INTERNALS
+    Py_ssize_t i;
+#if CYTHON_PEP393_ENABLED
+    void *udata;
+    uval = PyUnicode_New(ulength, 127);
+    if (unlikely(!uval)) return NULL;
+    udata = PyUnicode_DATA(uval);
+#else
+    Py_UNICODE *udata;
+    uval = PyUnicode_FromUnicode(NULL, ulength);
+    if (unlikely(!uval)) return NULL;
+    udata = PyUnicode_AS_UNICODE(uval);
+#endif
+    if (uoffset > 0) {
+        i = 0;
+        if (prepend_sign) {
+            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
+            i++;
+        }
+        for (; i < uoffset; i++) {
+            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
+        }
+    }
+    for (i=0; i < clength; i++) {
+        __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
+    }
+#else
+    {
+        uval = NULL;
+        PyObject *sign = NULL, *padding = NULL;
+        if (uoffset > 0) {
+            prepend_sign = !!prepend_sign;
+            if (uoffset > prepend_sign) {
+                padding = PyUnicode_FromOrdinal(padding_char);
+                if (likely(padding) && uoffset > prepend_sign + 1) {
+                    PyObject *tmp;
+                    PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign);
+                    if (unlikely(!repeat)) goto done_or_error;
+                    tmp = PyNumber_Multiply(padding, repeat);
+                    Py_DECREF(repeat);
+                    Py_DECREF(padding);
+                    padding = tmp;
+                }
+                if (unlikely(!padding)) goto done_or_error;
+            }
+            if (prepend_sign) {
+                sign = PyUnicode_FromOrdinal('-');
+                if (unlikely(!sign)) goto done_or_error;
+            }
+        }
+        uval = PyUnicode_DecodeASCII(chars, clength, NULL);
+        if (likely(uval) && padding) {
+            PyObject *tmp = PyNumber_Add(padding, uval);
+            Py_DECREF(uval);
+            uval = tmp;
+        }
+        if (likely(uval) && sign) {
+            PyObject *tmp = PyNumber_Add(sign, uval);
+            Py_DECREF(uval);
+            uval = tmp;
+        }
+done_or_error:
+        Py_XDECREF(padding);
+        Py_XDECREF(sign);
+    }
+#endif
+    return uval;
+}
+
+/* CIntToPyUnicode */
+#ifdef _MSC_VER
+    #ifndef _MSC_STDINT_H_
+        #if _MSC_VER < 1300
+           typedef unsigned short    uint16_t;
+        #else
+           typedef unsigned __int16  uint16_t;
+        #endif
+    #endif
+#else
+   #include <stdint.h>
+#endif
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char) {
+    char digits[sizeof(Py_ssize_t)*3+2];
+    char *dpos, *end = digits + sizeof(Py_ssize_t)*3+2;
+    const char *hex_digits = DIGITS_HEX;
+    Py_ssize_t length, ulength;
+    int prepend_sign, last_one_off;
+    Py_ssize_t remaining;
+    const Py_ssize_t neg_one = (Py_ssize_t) ((Py_ssize_t) 0 - (Py_ssize_t) 1), const_zero = (Py_ssize_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (format_char == 'X') {
+        hex_digits += 16;
+        format_char = 'x';
+    }
+    remaining = value;
+    last_one_off = 0;
+    dpos = end;
+    do {
+        int digit_pos;
+        switch (format_char) {
+        case 'o':
+            digit_pos = abs((int)(remaining % (8*8)));
+            remaining = (Py_ssize_t) (remaining / (8*8));
+            dpos -= 2;
+            *(uint16_t*)dpos = ((uint16_t*)DIGIT_PAIRS_8)[digit_pos];
+            last_one_off = (digit_pos < 8);
+            break;
+        case 'd':
+            digit_pos = abs((int)(remaining % (10*10)));
+            remaining = (Py_ssize_t) (remaining / (10*10));
+            dpos -= 2;
+            *(uint16_t*)dpos = ((uint16_t*)DIGIT_PAIRS_10)[digit_pos];
+            last_one_off = (digit_pos < 10);
+            break;
+        case 'x':
+            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
+            remaining = (Py_ssize_t) (remaining / 16);
+            break;
+        default:
+            assert(0);
+            break;
+        }
+    } while (unlikely(remaining != 0));
+    if (last_one_off) {
+        assert(*dpos == '0');
+        dpos++;
+    }
+    length = end - dpos;
+    ulength = length;
+    prepend_sign = 0;
+    if (!is_unsigned && value <= neg_one) {
+        if (padding_char == ' ' || width <= length + 1) {
+            *(--dpos) = '-';
+            ++length;
+        } else {
+            prepend_sign = 1;
+        }
+        ++ulength;
+    }
+    if (width > ulength) {
+        ulength = width;
+    }
+    if (ulength == 1) {
+        return PyUnicode_FromOrdinal(*dpos);
+    }
+    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
+}
+
+/* JoinPyUnicode */
+static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
+                                      CYTHON_UNUSED Py_UCS4 max_char) {
+#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    PyObject *result_uval;
+    int result_ukind;
+    Py_ssize_t i, char_pos;
+    void *result_udata;
+#if CYTHON_PEP393_ENABLED
+    result_uval = PyUnicode_New(result_ulength, max_char);
+    if (unlikely(!result_uval)) return NULL;
+    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
+    result_udata = PyUnicode_DATA(result_uval);
+#else
+    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
+    if (unlikely(!result_uval)) return NULL;
+    result_ukind = sizeof(Py_UNICODE);
+    result_udata = PyUnicode_AS_UNICODE(result_uval);
+#endif
+    char_pos = 0;
+    for (i=0; i < value_count; i++) {
+        int ukind;
+        Py_ssize_t ulength;
+        void *udata;
+        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
+        if (unlikely(__Pyx_PyUnicode_READY(uval)))
+            goto bad;
+        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
+        if (unlikely(!ulength))
+            continue;
+        if (unlikely(char_pos + ulength < 0))
+            goto overflow;
+        ukind = __Pyx_PyUnicode_KIND(uval);
+        udata = __Pyx_PyUnicode_DATA(uval);
+        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
+            memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind));
+        } else {
+            #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
+            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
+            #else
+            Py_ssize_t j;
+            for (j=0; j < ulength; j++) {
+                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
+                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
+            }
+            #endif
+        }
+        char_pos += ulength;
+    }
+    return result_uval;
+overflow:
+    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
+bad:
+    Py_DECREF(result_uval);
+    return NULL;
+#else
+    result_ulength++;
+    value_count++;
+    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
+#endif
+}
+
+/* PyCFunctionFastCall */
+#if CYTHON_FAST_PYCCALL
+static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
+    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
+    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
+    PyObject *self = PyCFunction_GET_SELF(func);
+    int flags = PyCFunction_GET_FLAGS(func);
+    assert(PyCFunction_Check(func));
+    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
+    assert(nargs >= 0);
+    assert(nargs == 0 || args != NULL);
+    /* _PyCFunction_FastCallDict() must not be called with an exception set,
+       because it may clear it (directly or indirectly) and so the
+       caller loses its exception */
+    assert(!PyErr_Occurred());
+    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
+        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
+    } else {
+        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
+    }
+}
+#endif
+
+/* PyFunctionFastCall */
+#if CYTHON_FAST_PYCALL
+static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
+                                               PyObject *globals) {
+    PyFrameObject *f;
+    PyThreadState *tstate = __Pyx_PyThreadState_Current;
+    PyObject **fastlocals;
+    Py_ssize_t i;
+    PyObject *result;
+    assert(globals != NULL);
+    /* XXX Perhaps we should create a specialized
+       PyFrame_New() that doesn't take locals, but does
+       take builtins without sanity checking them.
+       */
+    assert(tstate != NULL);
+    f = PyFrame_New(tstate, co, globals, NULL);
+    if (f == NULL) {
+        return NULL;
+    }
+    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
+    for (i = 0; i < na; i++) {
+        Py_INCREF(*args);
+        fastlocals[i] = *args++;
+    }
+    result = PyEval_EvalFrameEx(f,0);
+    ++tstate->recursion_depth;
+    Py_DECREF(f);
+    --tstate->recursion_depth;
+    return result;
+}
+#if 1 || PY_VERSION_HEX < 0x030600B1
+static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
+    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
+    PyObject *globals = PyFunction_GET_GLOBALS(func);
+    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
+    PyObject *closure;
+#if PY_MAJOR_VERSION >= 3
+    PyObject *kwdefs;
+#endif
+    PyObject *kwtuple, **k;
+    PyObject **d;
+    Py_ssize_t nd;
+    Py_ssize_t nk;
+    PyObject *result;
+    assert(kwargs == NULL || PyDict_Check(kwargs));
+    nk = kwargs ? PyDict_Size(kwargs) : 0;
+    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
+        return NULL;
+    }
+    if (
+#if PY_MAJOR_VERSION >= 3
+            co->co_kwonlyargcount == 0 &&
+#endif
+            likely(kwargs == NULL || nk == 0) &&
+            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
+        if (argdefs == NULL && co->co_argcount == nargs) {
+            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
+            goto done;
+        }
+        else if (nargs == 0 && argdefs != NULL
+                 && co->co_argcount == Py_SIZE(argdefs)) {
+            /* function called with no arguments, but all parameters have
+               a default value: use default values as arguments .*/
+            args = &PyTuple_GET_ITEM(argdefs, 0);
+            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
+            goto done;
+        }
+    }
+    if (kwargs != NULL) {
+        Py_ssize_t pos, i;
+        kwtuple = PyTuple_New(2 * nk);
+        if (kwtuple == NULL) {
+            result = NULL;
+            goto done;
+        }
+        k = &PyTuple_GET_ITEM(kwtuple, 0);
+        pos = i = 0;
+        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
+            Py_INCREF(k[i]);
+            Py_INCREF(k[i+1]);
+            i += 2;
+        }
+        nk = i / 2;
+    }
+    else {
+        kwtuple = NULL;
+        k = NULL;
+    }
+    closure = PyFunction_GET_CLOSURE(func);
+#if PY_MAJOR_VERSION >= 3
+    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
+#endif
+    if (argdefs != NULL) {
+        d = &PyTuple_GET_ITEM(argdefs, 0);
+        nd = Py_SIZE(argdefs);
+    }
+    else {
+        d = NULL;
+        nd = 0;
+    }
+#if PY_MAJOR_VERSION >= 3
+    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
+                               args, nargs,
+                               k, (int)nk,
+                               d, (int)nd, kwdefs, closure);
+#else
+    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
+                               args, nargs,
+                               k, (int)nk,
+                               d, (int)nd, closure);
+#endif
+    Py_XDECREF(kwtuple);
+done:
+    Py_LeaveRecursiveCall();
+    return result;
+}
+#endif
+#endif
+
+/* PyObjectCall */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
+    PyObject *result;
+    ternaryfunc call = func->ob_type->tp_call;
+    if (unlikely(!call))
+        return PyObject_Call(func, arg, kw);
+    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
+        return NULL;
+    result = (*call)(func, arg, kw);
+    Py_LeaveRecursiveCall();
+    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
+        PyErr_SetString(
+            PyExc_SystemError,
+            "NULL result without error in PyObject_Call");
+    }
+    return result;
+}
+#endif
+
+/* PyObjectCallMethO */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
+    PyObject *self, *result;
+    PyCFunction cfunc;
+    cfunc = PyCFunction_GET_FUNCTION(func);
+    self = PyCFunction_GET_SELF(func);
+    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
+        return NULL;
+    result = cfunc(self, arg);
+    Py_LeaveRecursiveCall();
+    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
+        PyErr_SetString(
+            PyExc_SystemError,
+            "NULL result without error in PyObject_Call");
+    }
+    return result;
+}
+#endif
+
+/* PyObjectCallOneArg */
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+    PyObject *result;
+    PyObject *args = PyTuple_New(1);
+    if (unlikely(!args)) return NULL;
+    Py_INCREF(arg);
+    PyTuple_SET_ITEM(args, 0, arg);
+    result = __Pyx_PyObject_Call(func, args, NULL);
+    Py_DECREF(args);
+    return result;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+#if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(func)) {
+        return __Pyx_PyFunction_FastCall(func, &arg, 1);
+    }
+#endif
+    if (likely(PyCFunction_Check(func))) {
+        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
+            return __Pyx_PyObject_CallMethO(func, arg);
+#if CYTHON_FAST_PYCCALL
+        } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
+            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
+#endif
+        }
+    }
+    return __Pyx__PyObject_CallOneArg(func, arg);
+}
+#else
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+    PyObject *result;
+    PyObject *args = PyTuple_Pack(1, arg);
+    if (unlikely(!args)) return NULL;
+    result = __Pyx_PyObject_Call(func, args, NULL);
+    Py_DECREF(args);
+    return result;
+}
+#endif
+
+/* PyErrFetchRestore */
+#if CYTHON_FAST_THREAD_STATE
+static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    tmp_type = tstate->curexc_type;
+    tmp_value = tstate->curexc_value;
+    tmp_tb = tstate->curexc_traceback;
+    tstate->curexc_type = type;
+    tstate->curexc_value = value;
+    tstate->curexc_traceback = tb;
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+}
+static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
+    *type = tstate->curexc_type;
+    *value = tstate->curexc_value;
+    *tb = tstate->curexc_traceback;
+    tstate->curexc_type = 0;
+    tstate->curexc_value = 0;
+    tstate->curexc_traceback = 0;
+}
+#endif
+
+/* RaiseException */
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
+                        CYTHON_UNUSED PyObject *cause) {
+    __Pyx_PyThreadState_declare
+    Py_XINCREF(type);
+    if (!value || value == Py_None)
+        value = NULL;
+    else
+        Py_INCREF(value);
+    if (!tb || tb == Py_None)
+        tb = NULL;
+    else {
+        Py_INCREF(tb);
+        if (!PyTraceBack_Check(tb)) {
+            PyErr_SetString(PyExc_TypeError,
+                "raise: arg 3 must be a traceback or None");
+            goto raise_error;
+        }
+    }
+    if (PyType_Check(type)) {
+#if CYTHON_COMPILING_IN_PYPY
+        if (!value) {
+            Py_INCREF(Py_None);
+            value = Py_None;
+        }
+#endif
+        PyErr_NormalizeException(&type, &value, &tb);
+    } else {
+        if (value) {
+            PyErr_SetString(PyExc_TypeError,
+                "instance exception may not have a separate value");
+            goto raise_error;
+        }
+        value = type;
+        type = (PyObject*) Py_TYPE(type);
+        Py_INCREF(type);
+        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+            PyErr_SetString(PyExc_TypeError,
+                "raise: exception class must be a subclass of BaseException");
+            goto raise_error;
+        }
+    }
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrRestore(type, value, tb);
+    return;
+raise_error:
+    Py_XDECREF(value);
+    Py_XDECREF(type);
+    Py_XDECREF(tb);
+    return;
+}
+#else
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+    PyObject* owned_instance = NULL;
+    if (tb == Py_None) {
+        tb = 0;
+    } else if (tb && !PyTraceBack_Check(tb)) {
+        PyErr_SetString(PyExc_TypeError,
+            "raise: arg 3 must be a traceback or None");
+        goto bad;
+    }
+    if (value == Py_None)
+        value = 0;
+    if (PyExceptionInstance_Check(type)) {
+        if (value) {
+            PyErr_SetString(PyExc_TypeError,
+                "instance exception may not have a separate value");
+            goto bad;
+        }
+        value = type;
+        type = (PyObject*) Py_TYPE(value);
+    } else if (PyExceptionClass_Check(type)) {
+        PyObject *instance_class = NULL;
+        if (value && PyExceptionInstance_Check(value)) {
+            instance_class = (PyObject*) Py_TYPE(value);
+            if (instance_class != type) {
+                int is_subclass = PyObject_IsSubclass(instance_class, type);
+                if (!is_subclass) {
+                    instance_class = NULL;
+                } else if (unlikely(is_subclass == -1)) {
+                    goto bad;
+                } else {
+                    type = instance_class;
+                }
+            }
+        }
+        if (!instance_class) {
+            PyObject *args;
+            if (!value)
+                args = PyTuple_New(0);
+            else if (PyTuple_Check(value)) {
+                Py_INCREF(value);
+                args = value;
+            } else
+                args = PyTuple_Pack(1, value);
+            if (!args)
+                goto bad;
+            owned_instance = PyObject_Call(type, args, NULL);
+            Py_DECREF(args);
+            if (!owned_instance)
+                goto bad;
+            value = owned_instance;
+            if (!PyExceptionInstance_Check(value)) {
+                PyErr_Format(PyExc_TypeError,
+                             "calling %R should have returned an instance of "
+                             "BaseException, not %R",
+                             type, Py_TYPE(value));
+                goto bad;
+            }
+        }
+    } else {
+        PyErr_SetString(PyExc_TypeError,
+            "raise: exception class must be a subclass of BaseException");
+        goto bad;
+    }
+    if (cause) {
+        PyObject *fixed_cause;
+        if (cause == Py_None) {
+            fixed_cause = NULL;
+        } else if (PyExceptionClass_Check(cause)) {
+            fixed_cause = PyObject_CallObject(cause, NULL);
+            if (fixed_cause == NULL)
+                goto bad;
+        } else if (PyExceptionInstance_Check(cause)) {
+            fixed_cause = cause;
+            Py_INCREF(fixed_cause);
+        } else {
+            PyErr_SetString(PyExc_TypeError,
+                            "exception causes must derive from "
+                            "BaseException");
+            goto bad;
+        }
+        PyException_SetCause(value, fixed_cause);
+    }
+    PyErr_SetObject(type, value);
+    if (tb) {
+#if CYTHON_COMPILING_IN_PYPY
+        PyObject *tmp_type, *tmp_value, *tmp_tb;
+        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
+        Py_INCREF(tb);
+        PyErr_Restore(tmp_type, tmp_value, tb);
+        Py_XDECREF(tmp_tb);
+#else
+        PyThreadState *tstate = __Pyx_PyThreadState_Current;
+        PyObject* tmp_tb = tstate->curexc_traceback;
+        if (tb != tmp_tb) {
+            Py_INCREF(tb);
+            tstate->curexc_traceback = tb;
+            Py_XDECREF(tmp_tb);
+        }
+#endif
+    }
+bad:
+    Py_XDECREF(owned_instance);
+    return;
+}
+#endif
+
+/* RaiseArgTupleInvalid */
+static void __Pyx_RaiseArgtupleInvalid(
+    const char* func_name,
+    int exact,
+    Py_ssize_t num_min,
+    Py_ssize_t num_max,
+    Py_ssize_t num_found)
+{
+    Py_ssize_t num_expected;
+    const char *more_or_less;
+    if (num_found < num_min) {
+        num_expected = num_min;
+        more_or_less = "at least";
+    } else {
+        num_expected = num_max;
+        more_or_less = "at most";
+    }
+    if (exact) {
+        more_or_less = "exactly";
+    }
+    PyErr_Format(PyExc_TypeError,
+                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
+                 func_name, more_or_less, num_expected,
+                 (num_expected == 1) ? "" : "s", num_found);
+}
+
+/* KeywordStringCheck */
+static int __Pyx_CheckKeywordStrings(
+    PyObject *kwdict,
+    const char* function_name,
+    int kw_allowed)
+{
+    PyObject* key = 0;
+    Py_ssize_t pos = 0;
+#if CYTHON_COMPILING_IN_PYPY
+    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
+        goto invalid_keyword;
+    return 1;
+#else
+    while (PyDict_Next(kwdict, &pos, &key, 0)) {
+        #if PY_MAJOR_VERSION < 3
+        if (unlikely(!PyString_Check(key)))
+        #endif
+            if (unlikely(!PyUnicode_Check(key)))
+                goto invalid_keyword_type;
+    }
+    if ((!kw_allowed) && unlikely(key))
+        goto invalid_keyword;
+    return 1;
+invalid_keyword_type:
+    PyErr_Format(PyExc_TypeError,
+        "%.200s() keywords must be strings", function_name);
+    return 0;
+#endif
+invalid_keyword:
+    PyErr_Format(PyExc_TypeError,
+    #if PY_MAJOR_VERSION < 3
+        "%.200s() got an unexpected keyword argument '%.200s'",
+        function_name, PyString_AsString(key));
+    #else
+        "%s() got an unexpected keyword argument '%U'",
+        function_name, key);
+    #endif
+    return 0;
+}
+
+/* GetModuleGlobalName */
+#if CYTHON_USE_DICT_VERSIONS
+static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
+#else
+static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
+#endif
+{
+    PyObject *result;
+#if !CYTHON_AVOID_BORROWED_REFS
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
+    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
+    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
+    if (likely(result)) {
+        return __Pyx_NewRef(result);
+    } else if (unlikely(PyErr_Occurred())) {
+        return NULL;
+    }
+#else
+    result = PyDict_GetItem(__pyx_d, name);
+    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
+    if (likely(result)) {
+        return __Pyx_NewRef(result);
+    }
+#endif
+#else
+    result = PyObject_GetItem(__pyx_d, name);
+    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
+    if (likely(result)) {
+        return __Pyx_NewRef(result);
+    }
+    PyErr_Clear();
+#endif
+    return __Pyx_GetBuiltinName(name);
+}
+
+/* PyObjectCall2Args */
+static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
+    PyObject *args, *result = NULL;
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(function)) {
+        PyObject *args[2] = {arg1, arg2};
+        return __Pyx_PyFunction_FastCall(function, args, 2);
+    }
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(function)) {
+        PyObject *args[2] = {arg1, arg2};
+        return __Pyx_PyCFunction_FastCall(function, args, 2);
+    }
+    #endif
+    args = PyTuple_New(2);
+    if (unlikely(!args)) goto done;
+    Py_INCREF(arg1);
+    PyTuple_SET_ITEM(args, 0, arg1);
+    Py_INCREF(arg2);
+    PyTuple_SET_ITEM(args, 1, arg2);
+    Py_INCREF(function);
+    result = __Pyx_PyObject_Call(function, args, NULL);
+    Py_DECREF(args);
+    Py_DECREF(function);
+done:
+    return result;
+}
+
+/* WriteUnraisableException */
+static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
+                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
+                                  int full_traceback, CYTHON_UNUSED int nogil) {
+    PyObject *old_exc, *old_val, *old_tb;
+    PyObject *ctx;
+    __Pyx_PyThreadState_declare
+#ifdef WITH_THREAD
+    PyGILState_STATE state;
+    if (nogil)
+        state = PyGILState_Ensure();
+#ifdef _MSC_VER
+    else state = (PyGILState_STATE)-1;
+#endif
+#endif
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
+    if (full_traceback) {
+        Py_XINCREF(old_exc);
+        Py_XINCREF(old_val);
+        Py_XINCREF(old_tb);
+        __Pyx_ErrRestore(old_exc, old_val, old_tb);
+        PyErr_PrintEx(1);
+    }
+    #if PY_MAJOR_VERSION < 3
+    ctx = PyString_FromString(name);
+    #else
+    ctx = PyUnicode_FromString(name);
+    #endif
+    __Pyx_ErrRestore(old_exc, old_val, old_tb);
+    if (!ctx) {
+        PyErr_WriteUnraisable(Py_None);
+    } else {
+        PyErr_WriteUnraisable(ctx);
+        Py_DECREF(ctx);
+    }
+#ifdef WITH_THREAD
+    if (nogil)
+        PyGILState_Release(state);
+#endif
+}
+
+/* PyObjectCallNoArg */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
+#if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(func)) {
+        return __Pyx_PyFunction_FastCall(func, NULL, 0);
+    }
+#endif
+#ifdef __Pyx_CyFunction_USED
+    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
+#else
+    if (likely(PyCFunction_Check(func)))
+#endif
+    {
+        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
+            return __Pyx_PyObject_CallMethO(func, NULL);
+        }
+    }
+    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
+}
+#endif
+
+/* GetItemInt */
+static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+    PyObject *r;
+    if (!j) return NULL;
+    r = PyObject_GetItem(o, j);
+    Py_DECREF(j);
+    return r;
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    Py_ssize_t wrapped_i = i;
+    if (wraparound & unlikely(i < 0)) {
+        wrapped_i += PyList_GET_SIZE(o);
+    }
+    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
+        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    Py_ssize_t wrapped_i = i;
+    if (wraparound & unlikely(i < 0)) {
+        wrapped_i += PyTuple_GET_SIZE(o);
+    }
+    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
+        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
+                                                     CYTHON_NCP_UNUSED int wraparound,
+                                                     CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
+    if (is_list || PyList_CheckExact(o)) {
+        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
+            PyObject *r = PyList_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    }
+    else if (PyTuple_CheckExact(o)) {
+        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
+            PyObject *r = PyTuple_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    } else {
+        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+        if (likely(m && m->sq_item)) {
+            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
+                Py_ssize_t l = m->sq_length(o);
+                if (likely(l >= 0)) {
+                    i += l;
+                } else {
+                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
+                        return NULL;
+                    PyErr_Clear();
+                }
+            }
+            return m->sq_item(o, i);
+        }
+    }
+#else
+    if (is_list || PySequence_Check(o)) {
+        return PySequence_GetItem(o, i);
+    }
+#endif
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+/* None */
+static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
+    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
+}
+
+/* PyErrExceptionMatches */
+#if CYTHON_FAST_THREAD_STATE
+static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
+    Py_ssize_t i, n;
+    n = PyTuple_GET_SIZE(tuple);
+#if PY_MAJOR_VERSION >= 3
+    for (i=0; i<n; i++) {
+        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
+    }
+#endif
+    for (i=0; i<n; i++) {
+        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
+    }
+    return 0;
+}
+static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
+    PyObject *exc_type = tstate->curexc_type;
+    if (exc_type == err) return 1;
+    if (unlikely(!exc_type)) return 0;
+    if (unlikely(PyTuple_Check(err)))
+        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
+    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
+}
+#endif
+
+/* GetAttr */
+static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
+#if CYTHON_USE_TYPE_SLOTS
+#if PY_MAJOR_VERSION >= 3
+    if (likely(PyUnicode_Check(n)))
+#else
+    if (likely(PyString_Check(n)))
+#endif
+        return __Pyx_PyObject_GetAttrStr(o, n);
+#endif
+    return PyObject_GetAttr(o, n);
+}
+
+/* GetAttr3 */
+static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
+        return NULL;
+    __Pyx_PyErr_Clear();
+    Py_INCREF(d);
+    return d;
+}
+static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
+    PyObject *r = __Pyx_GetAttr(o, n);
+    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
+}
+
+/* GetException */
+#if CYTHON_FAST_THREAD_STATE
+static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
+#else
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
+#endif
+{
+    PyObject *local_type, *local_value, *local_tb;
+#if CYTHON_FAST_THREAD_STATE
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    local_type = tstate->curexc_type;
+    local_value = tstate->curexc_value;
+    local_tb = tstate->curexc_traceback;
+    tstate->curexc_type = 0;
+    tstate->curexc_value = 0;
+    tstate->curexc_traceback = 0;
+#else
+    PyErr_Fetch(&local_type, &local_value, &local_tb);
+#endif
+    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
+#if CYTHON_FAST_THREAD_STATE
+    if (unlikely(tstate->curexc_type))
+#else
+    if (unlikely(PyErr_Occurred()))
+#endif
+        goto bad;
+    #if PY_MAJOR_VERSION >= 3
+    if (local_tb) {
+        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
+            goto bad;
+    }
+    #endif
+    Py_XINCREF(local_tb);
+    Py_XINCREF(local_type);
+    Py_XINCREF(local_value);
+    *type = local_type;
+    *value = local_value;
+    *tb = local_tb;
+#if CYTHON_FAST_THREAD_STATE
+    #if CYTHON_USE_EXC_INFO_STACK
+    {
+        _PyErr_StackItem *exc_info = tstate->exc_info;
+        tmp_type = exc_info->exc_type;
+        tmp_value = exc_info->exc_value;
+        tmp_tb = exc_info->exc_traceback;
+        exc_info->exc_type = local_type;
+        exc_info->exc_value = local_value;
+        exc_info->exc_traceback = local_tb;
+    }
+    #else
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = local_type;
+    tstate->exc_value = local_value;
+    tstate->exc_traceback = local_tb;
+    #endif
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+#else
+    PyErr_SetExcInfo(local_type, local_value, local_tb);
+#endif
+    return 0;
+bad:
+    *type = 0;
+    *value = 0;
+    *tb = 0;
+    Py_XDECREF(local_type);
+    Py_XDECREF(local_value);
+    Py_XDECREF(local_tb);
+    return -1;
+}
+
+/* SwapException */
+#if CYTHON_FAST_THREAD_STATE
+static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    #if CYTHON_USE_EXC_INFO_STACK
+    _PyErr_StackItem *exc_info = tstate->exc_info;
+    tmp_type = exc_info->exc_type;
+    tmp_value = exc_info->exc_value;
+    tmp_tb = exc_info->exc_traceback;
+    exc_info->exc_type = *type;
+    exc_info->exc_value = *value;
+    exc_info->exc_traceback = *tb;
+    #else
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = *type;
+    tstate->exc_value = *value;
+    tstate->exc_traceback = *tb;
+    #endif
+    *type = tmp_type;
+    *value = tmp_value;
+    *tb = tmp_tb;
+}
+#else
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
+    PyErr_SetExcInfo(*type, *value, *tb);
+    *type = tmp_type;
+    *value = tmp_value;
+    *tb = tmp_tb;
+}
+#endif
+
+/* GetTopmostException */
+#if CYTHON_USE_EXC_INFO_STACK
+static _PyErr_StackItem *
+__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
+{
+    _PyErr_StackItem *exc_info = tstate->exc_info;
+    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
+           exc_info->previous_item != NULL)
+    {
+        exc_info = exc_info->previous_item;
+    }
+    return exc_info;
+}
+#endif
+
+/* SaveResetException */
+#if CYTHON_FAST_THREAD_STATE
+static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
+    #if CYTHON_USE_EXC_INFO_STACK
+    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
+    *type = exc_info->exc_type;
+    *value = exc_info->exc_value;
+    *tb = exc_info->exc_traceback;
+    #else
+    *type = tstate->exc_type;
+    *value = tstate->exc_value;
+    *tb = tstate->exc_traceback;
+    #endif
+    Py_XINCREF(*type);
+    Py_XINCREF(*value);
+    Py_XINCREF(*tb);
+}
+static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    #if CYTHON_USE_EXC_INFO_STACK
+    _PyErr_StackItem *exc_info = tstate->exc_info;
+    tmp_type = exc_info->exc_type;
+    tmp_value = exc_info->exc_value;
+    tmp_tb = exc_info->exc_traceback;
+    exc_info->exc_type = type;
+    exc_info->exc_value = value;
+    exc_info->exc_traceback = tb;
+    #else
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = type;
+    tstate->exc_value = value;
+    tstate->exc_traceback = tb;
+    #endif
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+}
+#endif
+
+/* None */
+static CYTHON_INLINE int64_t __Pyx_div_int64_t(int64_t a, int64_t b) {
+    int64_t q = a / b;
+    int64_t r = a - q*b;
+    q -= ((r != 0) & ((r ^ b) < 0));
+    return q;
+}
+
+/* None */
+static CYTHON_INLINE int64_t __Pyx_mod_int64_t(int64_t a, int64_t b) {
+    int64_t r = a % b;
+    r += ((r != 0) & ((r ^ b) < 0)) * b;
+    return r;
+}
+
+/* None */
+static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
+    long q = a / b;
+    long r = a - q*b;
+    q -= ((r != 0) & ((r ^ b) < 0));
+    return q;
+}
+
+/* None */
+static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
+    long r = a % b;
+    r += ((r != 0) & ((r ^ b) < 0)) * b;
+    return r;
+}
+
+/* BytesEquals */
+static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
+#if CYTHON_COMPILING_IN_PYPY
+    return PyObject_RichCompareBool(s1, s2, equals);
+#else
+    if (s1 == s2) {
+        return (equals == Py_EQ);
+    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
+        const char *ps1, *ps2;
+        Py_ssize_t length = PyBytes_GET_SIZE(s1);
+        if (length != PyBytes_GET_SIZE(s2))
+            return (equals == Py_NE);
+        ps1 = PyBytes_AS_STRING(s1);
+        ps2 = PyBytes_AS_STRING(s2);
+        if (ps1[0] != ps2[0]) {
+            return (equals == Py_NE);
+        } else if (length == 1) {
+            return (equals == Py_EQ);
+        } else {
+            int result;
+#if CYTHON_USE_UNICODE_INTERNALS
+            Py_hash_t hash1, hash2;
+            hash1 = ((PyBytesObject*)s1)->ob_shash;
+            hash2 = ((PyBytesObject*)s2)->ob_shash;
+            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
+                return (equals == Py_NE);
+            }
+#endif
+            result = memcmp(ps1, ps2, (size_t)length);
+            return (equals == Py_EQ) ? (result == 0) : (result != 0);
+        }
+    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
+        return (equals == Py_NE);
+    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
+        return (equals == Py_NE);
+    } else {
+        int result;
+        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
+        if (!py_result)
+            return -1;
+        result = __Pyx_PyObject_IsTrue(py_result);
+        Py_DECREF(py_result);
+        return result;
+    }
+#endif
+}
+
+/* UnicodeEquals */
+static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
+#if CYTHON_COMPILING_IN_PYPY
+    return PyObject_RichCompareBool(s1, s2, equals);
+#else
+#if PY_MAJOR_VERSION < 3
+    PyObject* owned_ref = NULL;
+#endif
+    int s1_is_unicode, s2_is_unicode;
+    if (s1 == s2) {
+        goto return_eq;
+    }
+    s1_is_unicode = PyUnicode_CheckExact(s1);
+    s2_is_unicode = PyUnicode_CheckExact(s2);
+#if PY_MAJOR_VERSION < 3
+    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
+        owned_ref = PyUnicode_FromObject(s2);
+        if (unlikely(!owned_ref))
+            return -1;
+        s2 = owned_ref;
+        s2_is_unicode = 1;
+    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
+        owned_ref = PyUnicode_FromObject(s1);
+        if (unlikely(!owned_ref))
+            return -1;
+        s1 = owned_ref;
+        s1_is_unicode = 1;
+    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
+        return __Pyx_PyBytes_Equals(s1, s2, equals);
+    }
+#endif
+    if (s1_is_unicode & s2_is_unicode) {
+        Py_ssize_t length;
+        int kind;
+        void *data1, *data2;
+        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
+            return -1;
+        length = __Pyx_PyUnicode_GET_LENGTH(s1);
+        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
+            goto return_ne;
+        }
+#if CYTHON_USE_UNICODE_INTERNALS
+        {
+            Py_hash_t hash1, hash2;
+        #if CYTHON_PEP393_ENABLED
+            hash1 = ((PyASCIIObject*)s1)->hash;
+            hash2 = ((PyASCIIObject*)s2)->hash;
+        #else
+            hash1 = ((PyUnicodeObject*)s1)->hash;
+            hash2 = ((PyUnicodeObject*)s2)->hash;
+        #endif
+            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
+                goto return_ne;
+            }
+        }
+#endif
+        kind = __Pyx_PyUnicode_KIND(s1);
+        if (kind != __Pyx_PyUnicode_KIND(s2)) {
+            goto return_ne;
+        }
+        data1 = __Pyx_PyUnicode_DATA(s1);
+        data2 = __Pyx_PyUnicode_DATA(s2);
+        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
+            goto return_ne;
+        } else if (length == 1) {
+            goto return_eq;
+        } else {
+            int result = memcmp(data1, data2, (size_t)(length * kind));
+            #if PY_MAJOR_VERSION < 3
+            Py_XDECREF(owned_ref);
+            #endif
+            return (equals == Py_EQ) ? (result == 0) : (result != 0);
+        }
+    } else if ((s1 == Py_None) & s2_is_unicode) {
+        goto return_ne;
+    } else if ((s2 == Py_None) & s1_is_unicode) {
+        goto return_ne;
+    } else {
+        int result;
+        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
+        #if PY_MAJOR_VERSION < 3
+        Py_XDECREF(owned_ref);
+        #endif
+        if (!py_result)
+            return -1;
+        result = __Pyx_PyObject_IsTrue(py_result);
+        Py_DECREF(py_result);
+        return result;
+    }
+return_eq:
+    #if PY_MAJOR_VERSION < 3
+    Py_XDECREF(owned_ref);
+    #endif
+    return (equals == Py_EQ);
+return_ne:
+    #if PY_MAJOR_VERSION < 3
+    Py_XDECREF(owned_ref);
+    #endif
+    return (equals == Py_NE);
+#endif
+}
+
+/* py_abs */
+#if CYTHON_USE_PYLONG_INTERNALS
+static PyObject *__Pyx_PyLong_AbsNeg(PyObject *n) {
+    if (likely(Py_SIZE(n) == -1)) {
+        return PyLong_FromLong(((PyLongObject*)n)->ob_digit[0]);
+    }
+#if CYTHON_COMPILING_IN_CPYTHON
+    {
+        PyObject *copy = _PyLong_Copy((PyLongObject*)n);
+        if (likely(copy)) {
+            Py_SIZE(copy) = -(Py_SIZE(copy));
+        }
+        return copy;
+    }
+#else
+    return PyNumber_Negative(n);
+#endif
+}
+#endif
+
+/* HasAttr */
+static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
+    PyObject *r;
+    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
+        PyErr_SetString(PyExc_TypeError,
+                        "hasattr(): attribute name must be string");
+        return -1;
+    }
+    r = __Pyx_GetAttr(o, n);
+    if (unlikely(!r)) {
+        PyErr_Clear();
+        return 0;
+    } else {
+        Py_DECREF(r);
+        return 1;
+    }
+}
+
+/* RaiseTooManyValuesToUnpack */
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
+    PyErr_Format(PyExc_ValueError,
+                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
+}
+
+/* RaiseNeedMoreValuesToUnpack */
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
+    PyErr_Format(PyExc_ValueError,
+                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
+                 index, (index == 1) ? "" : "s");
+}
+
+/* IterFinish */
+static CYTHON_INLINE int __Pyx_IterFinish(void) {
+#if CYTHON_FAST_THREAD_STATE
+    PyThreadState *tstate = __Pyx_PyThreadState_Current;
+    PyObject* exc_type = tstate->curexc_type;
+    if (unlikely(exc_type)) {
+        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
+            PyObject *exc_value, *exc_tb;
+            exc_value = tstate->curexc_value;
+            exc_tb = tstate->curexc_traceback;
+            tstate->curexc_type = 0;
+            tstate->curexc_value = 0;
+            tstate->curexc_traceback = 0;
+            Py_DECREF(exc_type);
+            Py_XDECREF(exc_value);
+            Py_XDECREF(exc_tb);
+            return 0;
+        } else {
+            return -1;
+        }
+    }
+    return 0;
+#else
+    if (unlikely(PyErr_Occurred())) {
+        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
+            PyErr_Clear();
+            return 0;
+        } else {
+            return -1;
+        }
+    }
+    return 0;
+#endif
+}
+
+/* UnpackItemEndCheck */
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
+    if (unlikely(retval)) {
+        Py_DECREF(retval);
+        __Pyx_RaiseTooManyValuesError(expected);
+        return -1;
+    } else {
+        return __Pyx_IterFinish();
+    }
+    return 0;
+}
+
+/* PyIntBinop */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_CheckExact(op2))) {
+        const long a = intval;
+        long x;
+        long b = PyInt_AS_LONG(op2);
+            x = (long)((unsigned long)a + b);
+            if (likely((x^a) >= 0 || (x^b) >= 0))
+                return PyInt_FromLong(x);
+            return PyLong_Type.tp_as_number->nb_add(op1, op2);
+    }
+    #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    if (likely(PyLong_CheckExact(op2))) {
+        const long a = intval;
+        long b, x;
+#ifdef HAVE_LONG_LONG
+        const PY_LONG_LONG lla = intval;
+        PY_LONG_LONG llb, llx;
+#endif
+        const digit* digits = ((PyLongObject*)op2)->ob_digit;
+        const Py_ssize_t size = Py_SIZE(op2);
+        if (likely(__Pyx_sst_abs(size) <= 1)) {
+            b = likely(size) ? digits[0] : 0;
+            if (size == -1) b = -b;
+        } else {
+            switch (size) {
+                case -2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        llb = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        llb = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        llb = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        llb = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
+            }
+        }
+                x = a + b;
+            return PyLong_FromLong(x);
+#ifdef HAVE_LONG_LONG
+        long_long:
+                llx = lla + llb;
+            return PyLong_FromLongLong(llx);
+#endif
+        
+        
+    }
+    #endif
+    if (PyFloat_CheckExact(op2)) {
+        const long a = intval;
+        double b = PyFloat_AS_DOUBLE(op2);
+            double result;
+            PyFPE_START_PROTECT("add", return NULL)
+            result = ((double)a) + (double)b;
+            PyFPE_END_PROTECT(result)
+            return PyFloat_FromDouble(result);
+    }
+    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
+}
+#endif
+
+/* RaiseDoubleKeywords */
+static void __Pyx_RaiseDoubleKeywordsError(
+    const char* func_name,
+    PyObject* kw_name)
+{
+    PyErr_Format(PyExc_TypeError,
+        #if PY_MAJOR_VERSION >= 3
+        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+        #else
+        "%s() got multiple values for keyword argument '%s'", func_name,
+        PyString_AsString(kw_name));
+        #endif
+}
+
+/* ParseKeywords */
+static int __Pyx_ParseOptionalKeywords(
+    PyObject *kwds,
+    PyObject **argnames[],
+    PyObject *kwds2,
+    PyObject *values[],
+    Py_ssize_t num_pos_args,
+    const char* function_name)
+{
+    PyObject *key = 0, *value = 0;
+    Py_ssize_t pos = 0;
+    PyObject*** name;
+    PyObject*** first_kw_arg = argnames + num_pos_args;
+    while (PyDict_Next(kwds, &pos, &key, &value)) {
+        name = first_kw_arg;
+        while (*name && (**name != key)) name++;
+        if (*name) {
+            values[name-argnames] = value;
+            continue;
+        }
+        name = first_kw_arg;
+        #if PY_MAJOR_VERSION < 3
+        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
+            while (*name) {
+                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
+                        && _PyString_Eq(**name, key)) {
+                    values[name-argnames] = value;
+                    break;
+                }
+                name++;
+            }
+            if (*name) continue;
+            else {
+                PyObject*** argname = argnames;
+                while (argname != first_kw_arg) {
+                    if ((**argname == key) || (
+                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
+                             && _PyString_Eq(**argname, key))) {
+                        goto arg_passed_twice;
+                    }
+                    argname++;
+                }
+            }
+        } else
+        #endif
+        if (likely(PyUnicode_Check(key))) {
+            while (*name) {
+                int cmp = (**name == key) ? 0 :
+                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
+                #endif
+                    PyUnicode_Compare(**name, key);
+                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+                if (cmp == 0) {
+                    values[name-argnames] = value;
+                    break;
+                }
+                name++;
+            }
+            if (*name) continue;
+            else {
+                PyObject*** argname = argnames;
+                while (argname != first_kw_arg) {
+                    int cmp = (**argname == key) ? 0 :
+                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
+                    #endif
+                        PyUnicode_Compare(**argname, key);
+                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+                    if (cmp == 0) goto arg_passed_twice;
+                    argname++;
+                }
+            }
+        } else
+            goto invalid_keyword_type;
+        if (kwds2) {
+            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+        } else {
+            goto invalid_keyword;
+        }
+    }
+    return 0;
+arg_passed_twice:
+    __Pyx_RaiseDoubleKeywordsError(function_name, key);
+    goto bad;
+invalid_keyword_type:
+    PyErr_Format(PyExc_TypeError,
+        "%.200s() keywords must be strings", function_name);
+    goto bad;
+invalid_keyword:
+    PyErr_Format(PyExc_TypeError,
+    #if PY_MAJOR_VERSION < 3
+        "%.200s() got an unexpected keyword argument '%.200s'",
+        function_name, PyString_AsString(key));
+    #else
+        "%s() got an unexpected keyword argument '%U'",
+        function_name, key);
+    #endif
+bad:
+    return -1;
+}
+
+/* Import */
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
+    PyObject *empty_list = 0;
+    PyObject *module = 0;
+    PyObject *global_dict = 0;
+    PyObject *empty_dict = 0;
+    PyObject *list;
+    #if PY_MAJOR_VERSION < 3
+    PyObject *py_import;
+    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
+    if (!py_import)
+        goto bad;
+    #endif
+    if (from_list)
+        list = from_list;
+    else {
+        empty_list = PyList_New(0);
+        if (!empty_list)
+            goto bad;
+        list = empty_list;
+    }
+    global_dict = PyModule_GetDict(__pyx_m);
+    if (!global_dict)
+        goto bad;
+    empty_dict = PyDict_New();
+    if (!empty_dict)
+        goto bad;
+    {
+        #if PY_MAJOR_VERSION >= 3
+        if (level == -1) {
+            if (strchr(__Pyx_MODULE_NAME, '.')) {
+                module = PyImport_ImportModuleLevelObject(
+                    name, global_dict, empty_dict, list, 1);
+                if (!module) {
+                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
+                        goto bad;
+                    PyErr_Clear();
+                }
+            }
+            level = 0;
+        }
+        #endif
+        if (!module) {
+            #if PY_MAJOR_VERSION < 3
+            PyObject *py_level = PyInt_FromLong(level);
+            if (!py_level)
+                goto bad;
+            module = PyObject_CallFunctionObjArgs(py_import,
+                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
+            Py_DECREF(py_level);
+            #else
+            module = PyImport_ImportModuleLevelObject(
+                name, global_dict, empty_dict, list, level);
+            #endif
+        }
+    }
+bad:
+    #if PY_MAJOR_VERSION < 3
+    Py_XDECREF(py_import);
+    #endif
+    Py_XDECREF(empty_list);
+    Py_XDECREF(empty_dict);
+    return module;
+}
+
+/* ImportFrom */
+static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
+    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
+    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+        PyErr_Format(PyExc_ImportError,
+        #if PY_MAJOR_VERSION < 3
+            "cannot import name %.230s", PyString_AS_STRING(name));
+        #else
+            "cannot import name %S", name);
+        #endif
+    }
+    return value;
+}
+
+/* PyObject_GenericGetAttrNoDict */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
+    PyErr_Format(PyExc_AttributeError,
+#if PY_MAJOR_VERSION >= 3
+                 "'%.50s' object has no attribute '%U'",
+                 tp->tp_name, attr_name);
+#else
+                 "'%.50s' object has no attribute '%.400s'",
+                 tp->tp_name, PyString_AS_STRING(attr_name));
+#endif
+    return NULL;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
+    PyObject *descr;
+    PyTypeObject *tp = Py_TYPE(obj);
+    if (unlikely(!PyString_Check(attr_name))) {
+        return PyObject_GenericGetAttr(obj, attr_name);
+    }
+    assert(!tp->tp_dictoffset);
+    descr = _PyType_Lookup(tp, attr_name);
+    if (unlikely(!descr)) {
+        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
+    }
+    Py_INCREF(descr);
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
+    #endif
+    {
+        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
+        if (unlikely(f)) {
+            PyObject *res = f(descr, obj, (PyObject *)tp);
+            Py_DECREF(descr);
+            return res;
+        }
+    }
+    return descr;
+}
+#endif
+
+/* SetVTable */
+static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
+#if PY_VERSION_HEX >= 0x02070000
+    PyObject *ob = PyCapsule_New(vtable, 0, 0);
+#else
+    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
+#endif
+    if (!ob)
+        goto bad;
+    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
+        goto bad;
+    Py_DECREF(ob);
+    return 0;
+bad:
+    Py_XDECREF(ob);
+    return -1;
+}
+
+/* SetupReduce */
+static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
+  int ret;
+  PyObject *name_attr;
+  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name);
+  if (likely(name_attr)) {
+      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
+  } else {
+      ret = -1;
+  }
+  if (unlikely(ret < 0)) {
+      PyErr_Clear();
+      ret = 0;
+  }
+  Py_XDECREF(name_attr);
+  return ret;
+}
+static int __Pyx_setup_reduce(PyObject* type_obj) {
+    int ret = 0;
+    PyObject *object_reduce = NULL;
+    PyObject *object_reduce_ex = NULL;
+    PyObject *reduce = NULL;
+    PyObject *reduce_ex = NULL;
+    PyObject *reduce_cython = NULL;
+    PyObject *setstate = NULL;
+    PyObject *setstate_cython = NULL;
+#if CYTHON_USE_PYTYPE_LOOKUP
+    if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD;
+#else
+    if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD;
+#endif
+#if CYTHON_USE_PYTYPE_LOOKUP
+    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD;
+#else
+    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD;
+#endif
+    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD;
+    if (reduce_ex == object_reduce_ex) {
+#if CYTHON_USE_PYTYPE_LOOKUP
+        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD;
+#else
+        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD;
+#endif
+        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD;
+        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
+            reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD;
+            ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD;
+            ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD;
+            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
+            if (!setstate) PyErr_Clear();
+            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
+                setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD;
+                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD;
+                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD;
+            }
+            PyType_Modified((PyTypeObject*)type_obj);
+        }
+    }
+    goto GOOD;
+BAD:
+    if (!PyErr_Occurred())
+        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
+    ret = -1;
+GOOD:
+#if !CYTHON_USE_PYTYPE_LOOKUP
+    Py_XDECREF(object_reduce);
+    Py_XDECREF(object_reduce_ex);
+#endif
+    Py_XDECREF(reduce);
+    Py_XDECREF(reduce_ex);
+    Py_XDECREF(reduce_cython);
+    Py_XDECREF(setstate);
+    Py_XDECREF(setstate_cython);
+    return ret;
+}
+
+/* PyObject_GenericGetAttr */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
+    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
+        return PyObject_GenericGetAttr(obj, attr_name);
+    }
+    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
+}
+#endif
+
+/* TypeImport */
+#ifndef __PYX_HAVE_RT_ImportType
+#define __PYX_HAVE_RT_ImportType
+static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
+    size_t size, enum __Pyx_ImportType_CheckSize check_size)
+{
+    PyObject *result = 0;
+    char warning[200];
+    Py_ssize_t basicsize;
+#ifdef Py_LIMITED_API
+    PyObject *py_basicsize;
+#endif
+    result = PyObject_GetAttrString(module, class_name);
+    if (!result)
+        goto bad;
+    if (!PyType_Check(result)) {
+        PyErr_Format(PyExc_TypeError,
+            "%.200s.%.200s is not a type object",
+            module_name, class_name);
+        goto bad;
+    }
+#ifndef Py_LIMITED_API
+    basicsize = ((PyTypeObject *)result)->tp_basicsize;
+#else
+    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
+    if (!py_basicsize)
+        goto bad;
+    basicsize = PyLong_AsSsize_t(py_basicsize);
+    Py_DECREF(py_basicsize);
+    py_basicsize = 0;
+    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
+        goto bad;
+#endif
+    if ((size_t)basicsize < size) {
+        PyErr_Format(PyExc_ValueError,
+            "%.200s.%.200s size changed, may indicate binary incompatibility. "
+            "Expected %zd from C header, got %zd from PyObject",
+            module_name, class_name, size, basicsize);
+        goto bad;
+    }
+    if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
+        PyErr_Format(PyExc_ValueError,
+            "%.200s.%.200s size changed, may indicate binary incompatibility. "
+            "Expected %zd from C header, got %zd from PyObject",
+            module_name, class_name, size, basicsize);
+        goto bad;
+    }
+    else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
+        PyOS_snprintf(warning, sizeof(warning),
+            "%s.%s size changed, may indicate binary incompatibility. "
+            "Expected %zd from C header, got %zd from PyObject",
+            module_name, class_name, size, basicsize);
+        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
+    }
+    return (PyTypeObject *)result;
+bad:
+    Py_XDECREF(result);
+    return NULL;
+}
+#endif
+
+/* CLineInTraceback */
+#ifndef CYTHON_CLINE_IN_TRACEBACK
+static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) {
+    PyObject *use_cline;
+    PyObject *ptype, *pvalue, *ptraceback;
+#if CYTHON_COMPILING_IN_CPYTHON
+    PyObject **cython_runtime_dict;
+#endif
+    if (unlikely(!__pyx_cython_runtime)) {
+        return c_line;
+    }
+    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
+#if CYTHON_COMPILING_IN_CPYTHON
+    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
+    if (likely(cython_runtime_dict)) {
+        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
+            use_cline, *cython_runtime_dict,
+            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
+    } else
+#endif
+    {
+      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
+      if (use_cline_obj) {
+        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
+        Py_DECREF(use_cline_obj);
+      } else {
+        PyErr_Clear();
+        use_cline = NULL;
+      }
+    }
+    if (!use_cline) {
+        c_line = 0;
+        PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
+    }
+    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
+        c_line = 0;
+    }
+    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
+    return c_line;
+}
+#endif
+
+/* CodeObjectCache */
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+    int start = 0, mid = 0, end = count - 1;
+    if (end >= 0 && code_line > entries[end].code_line) {
+        return count;
+    }
+    while (start < end) {
+        mid = start + (end - start) / 2;
+        if (code_line < entries[mid].code_line) {
+            end = mid;
+        } else if (code_line > entries[mid].code_line) {
+             start = mid + 1;
+        } else {
+            return mid;
+        }
+    }
+    if (code_line <= entries[mid].code_line) {
+        return mid;
+    } else {
+        return mid + 1;
+    }
+}
+static PyCodeObject *__pyx_find_code_object(int code_line) {
+    PyCodeObject* code_object;
+    int pos;
+    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
+        return NULL;
+    }
+    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
+        return NULL;
+    }
+    code_object = __pyx_code_cache.entries[pos].code_object;
+    Py_INCREF(code_object);
+    return code_object;
+}
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
+    int pos, i;
+    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
+    if (unlikely(!code_line)) {
+        return;
+    }
+    if (unlikely(!entries)) {
+        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
+        if (likely(entries)) {
+            __pyx_code_cache.entries = entries;
+            __pyx_code_cache.max_count = 64;
+            __pyx_code_cache.count = 1;
+            entries[0].code_line = code_line;
+            entries[0].code_object = code_object;
+            Py_INCREF(code_object);
+        }
+        return;
+    }
+    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
+        PyCodeObject* tmp = entries[pos].code_object;
+        entries[pos].code_object = code_object;
+        Py_DECREF(tmp);
+        return;
+    }
+    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
+        int new_max = __pyx_code_cache.max_count + 64;
+        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
+            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
+        if (unlikely(!entries)) {
+            return;
+        }
+        __pyx_code_cache.entries = entries;
+        __pyx_code_cache.max_count = new_max;
+    }
+    for (i=__pyx_code_cache.count; i>pos; i--) {
+        entries[i] = entries[i-1];
+    }
+    entries[pos].code_line = code_line;
+    entries[pos].code_object = code_object;
+    __pyx_code_cache.count++;
+    Py_INCREF(code_object);
+}
+
+/* AddTraceback */
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
+            const char *funcname, int c_line,
+            int py_line, const char *filename) {
+    PyCodeObject *py_code = 0;
+    PyObject *py_srcfile = 0;
+    PyObject *py_funcname = 0;
+    #if PY_MAJOR_VERSION < 3
+    py_srcfile = PyString_FromString(filename);
+    #else
+    py_srcfile = PyUnicode_FromString(filename);
+    #endif
+    if (!py_srcfile) goto bad;
+    if (c_line) {
+        #if PY_MAJOR_VERSION < 3
+        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+        #else
+        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+        #endif
+    }
+    else {
+        #if PY_MAJOR_VERSION < 3
+        py_funcname = PyString_FromString(funcname);
+        #else
+        py_funcname = PyUnicode_FromString(funcname);
+        #endif
+    }
+    if (!py_funcname) goto bad;
+    py_code = __Pyx_PyCode_New(
+        0,
+        0,
+        0,
+        0,
+        0,
+        __pyx_empty_bytes, /*PyObject *code,*/
+        __pyx_empty_tuple, /*PyObject *consts,*/
+        __pyx_empty_tuple, /*PyObject *names,*/
+        __pyx_empty_tuple, /*PyObject *varnames,*/
+        __pyx_empty_tuple, /*PyObject *freevars,*/
+        __pyx_empty_tuple, /*PyObject *cellvars,*/
+        py_srcfile,   /*PyObject *filename,*/
+        py_funcname,  /*PyObject *name,*/
+        py_line,
+        __pyx_empty_bytes  /*PyObject *lnotab*/
+    );
+    Py_DECREF(py_srcfile);
+    Py_DECREF(py_funcname);
+    return py_code;
+bad:
+    Py_XDECREF(py_srcfile);
+    Py_XDECREF(py_funcname);
+    return NULL;
+}
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+                               int py_line, const char *filename) {
+    PyCodeObject *py_code = 0;
+    PyFrameObject *py_frame = 0;
+    PyThreadState *tstate = __Pyx_PyThreadState_Current;
+    if (c_line) {
+        c_line = __Pyx_CLineForTraceback(tstate, c_line);
+    }
+    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
+    if (!py_code) {
+        py_code = __Pyx_CreateCodeObjectForTraceback(
+            funcname, c_line, py_line, filename);
+        if (!py_code) goto bad;
+        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
+    }
+    py_frame = PyFrame_New(
+        tstate,            /*PyThreadState *tstate,*/
+        py_code,           /*PyCodeObject *code,*/
+        __pyx_d,    /*PyObject *globals,*/
+        0                  /*PyObject *locals*/
+    );
+    if (!py_frame) goto bad;
+    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
+    PyTraceBack_Here(py_frame);
+bad:
+    Py_XDECREF(py_code);
+    Py_XDECREF(py_frame);
+}
+
+/* CIntFromPyVerify */
+#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
+#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
+#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
+    {\
+        func_type value = func_value;\
+        if (sizeof(target_type) < sizeof(func_type)) {\
+            if (unlikely(value != (func_type) (target_type) value)) {\
+                func_type zero = 0;\
+                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
+                    return (target_type) -1;\
+                if (is_unsigned && unlikely(value < zero))\
+                    goto raise_neg_overflow;\
+                else\
+                    goto raise_overflow;\
+            }\
+        }\
+        return (target_type) value;\
+    }
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
+    const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(long) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(long) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(long) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(long),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
+    const int32_t neg_one = (int32_t) ((int32_t) 0 - (int32_t) 1), const_zero = (int32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int32_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int32_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int32_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
+    const char neg_one = (char) ((char) 0 - (char) 1), const_zero = (char) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(char) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(char) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(char) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(char),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value) {
+    const int64_t neg_one = (int64_t) ((int64_t) 0 - (int64_t) 1), const_zero = (int64_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int64_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int64_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int64_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int64_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
+    const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value) {
+    const uint8_t neg_one = (uint8_t) ((uint8_t) 0 - (uint8_t) 1), const_zero = (uint8_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(uint8_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(uint8_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint8_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(uint8_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint8_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(uint8_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) {
+    const uint16_t neg_one = (uint16_t) ((uint16_t) 0 - (uint16_t) 1), const_zero = (uint16_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(uint16_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(uint16_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint16_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(uint16_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint16_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(uint16_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
+    const uint32_t neg_one = (uint32_t) ((uint32_t) 0 - (uint32_t) 1), const_zero = (uint32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(uint32_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(uint32_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(uint32_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
+    const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
+                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
+                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
+                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int) -1;
+        }
+    } else {
+        int val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int) -1;
+        val = __Pyx_PyInt_As_int(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int");
+    return (int) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int");
+    return (int) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) {
+    const int64_t neg_one = (int64_t) ((int64_t) 0 - (int64_t) 1), const_zero = (int64_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int64_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int64_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int64_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int64_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int64_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int64_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) >= 2 * PyLong_SHIFT) {
+                            return (int64_t) (((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int64_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) >= 3 * PyLong_SHIFT) {
+                            return (int64_t) (((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int64_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) >= 4 * PyLong_SHIFT) {
+                            return (int64_t) (((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int64_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int64_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int64_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int64_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int64_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int64_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int64_t) (((int64_t)-1)*(((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int64_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int64_t) ((((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int64_t) (((int64_t)-1)*(((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int64_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int64_t) ((((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int64_t) (((int64_t)-1)*(((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int64_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int64_t) ((((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int64_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int64_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int64_t) -1;
+        }
+    } else {
+        int64_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int64_t) -1;
+        val = __Pyx_PyInt_As_int64_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int64_t");
+    return (int64_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int64_t");
+    return (int64_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
+    const int32_t neg_one = (int32_t) ((int32_t) 0 - (int32_t) 1), const_zero = (int32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int32_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int32_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int32_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int32_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) >= 2 * PyLong_SHIFT) {
+                            return (int32_t) (((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) >= 3 * PyLong_SHIFT) {
+                            return (int32_t) (((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) >= 4 * PyLong_SHIFT) {
+                            return (int32_t) (((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int32_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int32_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int32_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int32_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int32_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int32_t) (((int32_t)-1)*(((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int32_t) ((((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int32_t) (((int32_t)-1)*(((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int32_t) ((((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int32_t) (((int32_t)-1)*(((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int32_t) ((((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int32_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int32_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int32_t) -1;
+        }
+    } else {
+        int32_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int32_t) -1;
+        val = __Pyx_PyInt_As_int32_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int32_t");
+    return (int32_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int32_t");
+    return (int32_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
+    const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(long) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (long) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (long) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
+                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
+                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
+                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (long) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(long) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (long) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(long) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            long val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (long) -1;
+        }
+    } else {
+        long val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (long) -1;
+        val = __Pyx_PyInt_As_long(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to long");
+    return (long) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to long");
+    return (long) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int16_t __Pyx_PyInt_As_int16_t(PyObject *x) {
+    const int16_t neg_one = (int16_t) ((int16_t) 0 - (int16_t) 1), const_zero = (int16_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int16_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int16_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int16_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int16_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int16_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int16_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) >= 2 * PyLong_SHIFT) {
+                            return (int16_t) (((((int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int16_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) >= 3 * PyLong_SHIFT) {
+                            return (int16_t) (((((((int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int16_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) >= 4 * PyLong_SHIFT) {
+                            return (int16_t) (((((((((int16_t)digits[3]) << PyLong_SHIFT) | (int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int16_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int16_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int16_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int16_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int16_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int16_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int16_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int16_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int16_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int16_t) (((int16_t)-1)*(((((int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int16_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int16_t) ((((((int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int16_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int16_t) (((int16_t)-1)*(((((((int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int16_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int16_t) ((((((((int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int16_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int16_t) (((int16_t)-1)*(((((((((int16_t)digits[3]) << PyLong_SHIFT) | (int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int16_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int16_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int16_t) ((((((((((int16_t)digits[3]) << PyLong_SHIFT) | (int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int16_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int16_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int16_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int16_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int16_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int16_t) -1;
+        }
+    } else {
+        int16_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int16_t) -1;
+        val = __Pyx_PyInt_As_int16_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int16_t");
+    return (int16_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int16_t");
+    return (int16_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
+    const char neg_one = (char) ((char) 0 - (char) 1), const_zero = (char) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(char) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (char) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (char) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) {
+                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) {
+                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) {
+                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (char) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(char) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (char) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(char,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
+                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
+                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
+                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
+                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
+                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
+                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(char) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            char val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (char) -1;
+        }
+    } else {
+        char val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (char) -1;
+        val = __Pyx_PyInt_As_char(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to char");
+    return (char) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to char");
+    return (char) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int8_t __Pyx_PyInt_As_int8_t(PyObject *x) {
+    const int8_t neg_one = (int8_t) ((int8_t) 0 - (int8_t) 1), const_zero = (int8_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int8_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int8_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int8_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int8_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int8_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int8_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) >= 2 * PyLong_SHIFT) {
+                            return (int8_t) (((((int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int8_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) >= 3 * PyLong_SHIFT) {
+                            return (int8_t) (((((((int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int8_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) >= 4 * PyLong_SHIFT) {
+                            return (int8_t) (((((((((int8_t)digits[3]) << PyLong_SHIFT) | (int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int8_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int8_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int8_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int8_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int8_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int8_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int8_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int8_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int8_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int8_t) (((int8_t)-1)*(((((int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int8_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int8_t) ((((((int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int8_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int8_t) (((int8_t)-1)*(((((((int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int8_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int8_t) ((((((((int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int8_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int8_t) (((int8_t)-1)*(((((((((int8_t)digits[3]) << PyLong_SHIFT) | (int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int8_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int8_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int8_t) ((((((((((int8_t)digits[3]) << PyLong_SHIFT) | (int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int8_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int8_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int8_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int8_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int8_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int8_t) -1;
+        }
+    } else {
+        int8_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int8_t) -1;
+        val = __Pyx_PyInt_As_int8_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int8_t");
+    return (int8_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int8_t");
+    return (int8_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
+    const uint32_t neg_one = (uint32_t) ((uint32_t) 0 - (uint32_t) 1), const_zero = (uint32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(uint32_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(uint32_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (uint32_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (uint32_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(uint32_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(uint32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) >= 2 * PyLong_SHIFT) {
+                            return (uint32_t) (((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(uint32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) >= 3 * PyLong_SHIFT) {
+                            return (uint32_t) (((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(uint32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) >= 4 * PyLong_SHIFT) {
+                            return (uint32_t) (((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (uint32_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(uint32_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (uint32_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(uint32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(uint32_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(uint32_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (uint32_t) (((uint32_t)-1)*(((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(uint32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (uint32_t) ((((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (uint32_t) (((uint32_t)-1)*(((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(uint32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (uint32_t) ((((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (uint32_t) (((uint32_t)-1)*(((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(uint32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (uint32_t) ((((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(uint32_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            uint32_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (uint32_t) -1;
+        }
+    } else {
+        uint32_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (uint32_t) -1;
+        val = __Pyx_PyInt_As_uint32_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to uint32_t");
+    return (uint32_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to uint32_t");
+    return (uint32_t) -1;
+}
+
+/* FastTypeChecks */
+#if CYTHON_COMPILING_IN_CPYTHON
+static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
+    while (a) {
+        a = a->tp_base;
+        if (a == b)
+            return 1;
+    }
+    return b == &PyBaseObject_Type;
+}
+static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
+    PyObject *mro;
+    if (a == b) return 1;
+    mro = a->tp_mro;
+    if (likely(mro)) {
+        Py_ssize_t i, n;
+        n = PyTuple_GET_SIZE(mro);
+        for (i = 0; i < n; i++) {
+            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
+                return 1;
+        }
+        return 0;
+    }
+    return __Pyx_InBases(a, b);
+}
+#if PY_MAJOR_VERSION == 2
+static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
+    PyObject *exception, *value, *tb;
+    int res;
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrFetch(&exception, &value, &tb);
+    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
+    if (unlikely(res == -1)) {
+        PyErr_WriteUnraisable(err);
+        res = 0;
+    }
+    if (!res) {
+        res = PyObject_IsSubclass(err, exc_type2);
+        if (unlikely(res == -1)) {
+            PyErr_WriteUnraisable(err);
+            res = 0;
+        }
+    }
+    __Pyx_ErrRestore(exception, value, tb);
+    return res;
+}
+#else
+static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
+    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
+    if (!res) {
+        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
+    }
+    return res;
+}
+#endif
+static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
+    Py_ssize_t i, n;
+    assert(PyExceptionClass_Check(exc_type));
+    n = PyTuple_GET_SIZE(tuple);
+#if PY_MAJOR_VERSION >= 3
+    for (i=0; i<n; i++) {
+        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
+    }
+#endif
+    for (i=0; i<n; i++) {
+        PyObject *t = PyTuple_GET_ITEM(tuple, i);
+        #if PY_MAJOR_VERSION < 3
+        if (likely(exc_type == t)) return 1;
+        #endif
+        if (likely(PyExceptionClass_Check(t))) {
+            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
+        } else {
+        }
+    }
+    return 0;
+}
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
+    if (likely(err == exc_type)) return 1;
+    if (likely(PyExceptionClass_Check(err))) {
+        if (likely(PyExceptionClass_Check(exc_type))) {
+            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
+        } else if (likely(PyTuple_Check(exc_type))) {
+            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
+        } else {
+        }
+    }
+    return PyErr_GivenExceptionMatches(err, exc_type);
+}
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
+    assert(PyExceptionClass_Check(exc_type1));
+    assert(PyExceptionClass_Check(exc_type2));
+    if (likely(err == exc_type1 || err == exc_type2)) return 1;
+    if (likely(PyExceptionClass_Check(err))) {
+        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
+    }
+    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
+}
+#endif
+
+/* CheckBinaryVersion */
+static int __Pyx_check_binary_version(void) {
+    char ctversion[4], rtversion[4];
+    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+        char message[200];
+        PyOS_snprintf(message, sizeof(message),
+                      "compiletime version %s of module '%.100s' "
+                      "does not match runtime version %s",
+                      ctversion, __Pyx_MODULE_NAME, rtversion);
+        return PyErr_WarnEx(NULL, message, 1);
+    }
+    return 0;
+}
+
+/* FunctionExport */
+static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
+    PyObject *d = 0;
+    PyObject *cobj = 0;
+    union {
+        void (*fp)(void);
+        void *p;
+    } tmp;
+    d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
+    if (!d) {
+        PyErr_Clear();
+        d = PyDict_New();
+        if (!d)
+            goto bad;
+        Py_INCREF(d);
+        if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
+            goto bad;
+    }
+    tmp.fp = f;
+#if PY_VERSION_HEX >= 0x02070000
+    cobj = PyCapsule_New(tmp.p, sig, 0);
+#else
+    cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
+#endif
+    if (!cobj)
+        goto bad;
+    if (PyDict_SetItemString(d, name, cobj) < 0)
+        goto bad;
+    Py_DECREF(cobj);
+    Py_DECREF(d);
+    return 0;
+bad:
+    Py_XDECREF(cobj);
+    Py_XDECREF(d);
+    return -1;
+}
+
+/* InitStrings */
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+    while (t->p) {
+        #if PY_MAJOR_VERSION < 3
+        if (t->is_unicode) {
+            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+        } else if (t->intern) {
+            *t->p = PyString_InternFromString(t->s);
+        } else {
+            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+        }
+        #else
+        if (t->is_unicode | t->is_str) {
+            if (t->intern) {
+                *t->p = PyUnicode_InternFromString(t->s);
+            } else if (t->encoding) {
+                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+            } else {
+                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+            }
+        } else {
+            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+        }
+        #endif
+        if (!*t->p)
+            return -1;
+        if (PyObject_Hash(*t->p) == -1)
+            return -1;
+        ++t;
+    }
+    return 0;
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
+    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
+}
+static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
+    Py_ssize_t ignore;
+    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
+}
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+#if !CYTHON_PEP393_ENABLED
+static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
+    char* defenc_c;
+    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
+    if (!defenc) return NULL;
+    defenc_c = PyBytes_AS_STRING(defenc);
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+    {
+        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
+        char* c;
+        for (c = defenc_c; c < end; c++) {
+            if ((unsigned char) (*c) >= 128) {
+                PyUnicode_AsASCIIString(o);
+                return NULL;
+            }
+        }
+    }
+#endif
+    *length = PyBytes_GET_SIZE(defenc);
+    return defenc_c;
+}
+#else
+static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
+    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+    if (likely(PyUnicode_IS_ASCII(o))) {
+        *length = PyUnicode_GET_LENGTH(o);
+        return PyUnicode_AsUTF8(o);
+    } else {
+        PyUnicode_AsASCIIString(o);
+        return NULL;
+    }
+#else
+    return PyUnicode_AsUTF8AndSize(o, length);
+#endif
+}
+#endif
+#endif
+static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+    if (
+#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+            __Pyx_sys_getdefaultencoding_not_ascii &&
+#endif
+            PyUnicode_Check(o)) {
+        return __Pyx_PyUnicode_AsStringAndSize(o, length);
+    } else
+#endif
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
+    if (PyByteArray_Check(o)) {
+        *length = PyByteArray_GET_SIZE(o);
+        return PyByteArray_AS_STRING(o);
+    } else
+#endif
+    {
+        char* result;
+        int r = PyBytes_AsStringAndSize(o, &result, length);
+        if (unlikely(r < 0)) {
+            return NULL;
+        } else {
+            return result;
+        }
+    }
+}
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+   int is_true = x == Py_True;
+   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+   else return PyObject_IsTrue(x);
+}
+static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
+    int retval;
+    if (unlikely(!x)) return -1;
+    retval = __Pyx_PyObject_IsTrue(x);
+    Py_DECREF(x);
+    return retval;
+}
+static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
+#if PY_MAJOR_VERSION >= 3
+    if (PyLong_Check(result)) {
+        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
+                "__int__ returned non-int (type %.200s).  "
+                "The ability to return an instance of a strict subclass of int "
+                "is deprecated, and may be removed in a future version of Python.",
+                Py_TYPE(result)->tp_name)) {
+            Py_DECREF(result);
+            return NULL;
+        }
+        return result;
+    }
+#endif
+    PyErr_Format(PyExc_TypeError,
+                 "__%.4s__ returned non-%.4s (type %.200s)",
+                 type_name, type_name, Py_TYPE(result)->tp_name);
+    Py_DECREF(result);
+    return NULL;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
+#if CYTHON_USE_TYPE_SLOTS
+  PyNumberMethods *m;
+#endif
+  const char *name = NULL;
+  PyObject *res = NULL;
+#if PY_MAJOR_VERSION < 3
+  if (likely(PyInt_Check(x) || PyLong_Check(x)))
+#else
+  if (likely(PyLong_Check(x)))
+#endif
+    return __Pyx_NewRef(x);
+#if CYTHON_USE_TYPE_SLOTS
+  m = Py_TYPE(x)->tp_as_number;
+  #if PY_MAJOR_VERSION < 3
+  if (m && m->nb_int) {
+    name = "int";
+    res = m->nb_int(x);
+  }
+  else if (m && m->nb_long) {
+    name = "long";
+    res = m->nb_long(x);
+  }
+  #else
+  if (likely(m && m->nb_int)) {
+    name = "int";
+    res = m->nb_int(x);
+  }
+  #endif
+#else
+  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
+    res = PyNumber_Int(x);
+  }
+#endif
+  if (likely(res)) {
+#if PY_MAJOR_VERSION < 3
+    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
+#else
+    if (unlikely(!PyLong_CheckExact(res))) {
+#endif
+        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
+    }
+  }
+  else if (!PyErr_Occurred()) {
+    PyErr_SetString(PyExc_TypeError,
+                    "an integer is required");
+  }
+  return res;
+}
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+  Py_ssize_t ival;
+  PyObject *x;
+#if PY_MAJOR_VERSION < 3
+  if (likely(PyInt_CheckExact(b))) {
+    if (sizeof(Py_ssize_t) >= sizeof(long))
+        return PyInt_AS_LONG(b);
+    else
+        return PyInt_AsSsize_t(b);
+  }
+#endif
+  if (likely(PyLong_CheckExact(b))) {
+    #if CYTHON_USE_PYLONG_INTERNALS
+    const digit* digits = ((PyLongObject*)b)->ob_digit;
+    const Py_ssize_t size = Py_SIZE(b);
+    if (likely(__Pyx_sst_abs(size) <= 1)) {
+        ival = likely(size) ? digits[0] : 0;
+        if (size == -1) ival = -ival;
+        return ival;
+    } else {
+      switch (size) {
+         case 2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+      }
+    }
+    #endif
+    return PyLong_AsSsize_t(b);
+  }
+  x = PyNumber_Index(b);
+  if (!x) return -1;
+  ival = PyInt_AsSsize_t(x);
+  Py_DECREF(x);
+  return ival;
+}
+static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
+  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
+}
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+    return PyInt_FromSize_t(ival);
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/asyncpg/pgproto/pgproto.pxd b/asyncpg/pgproto/pgproto.pxd
new file mode 100644 (file)
index 0000000..ee9ec45
--- /dev/null
@@ -0,0 +1,19 @@
+# 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
+
+
+cimport cython
+cimport cpython
+
+from libc.stdint cimport int16_t, int32_t, uint16_t, uint32_t, int64_t, uint64_t
+
+
+include "./consts.pxi"
+include "./frb.pxd"
+include "./buffer.pxd"
+
+
+include "./codecs/__init__.pxd"
diff --git a/asyncpg/pgproto/pgproto.pyx b/asyncpg/pgproto/pgproto.pyx
new file mode 100644 (file)
index 0000000..b4d0a87
--- /dev/null
@@ -0,0 +1,46 @@
+# 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
+
+
+cimport cython
+cimport cpython
+
+from . cimport cpythonx
+
+from libc.stdint cimport int8_t, uint8_t, int16_t, uint16_t, \
+                         int32_t, uint32_t, int64_t, uint64_t, \
+                         INT16_MIN, INT16_MAX, INT32_MIN, INT32_MAX, \
+                         UINT32_MAX, INT64_MIN, INT64_MAX
+
+
+from . cimport hton
+
+from .debug cimport PG_DEBUG
+from . import types as pgproto_types
+
+
+include "./consts.pxi"
+include "./frb.pyx"
+include "./buffer.pyx"
+
+include "./codecs/context.pyx"
+
+include "./codecs/bytea.pyx"
+include "./codecs/text.pyx"
+
+include "./codecs/datetime.pyx"
+include "./codecs/float.pyx"
+include "./codecs/int.pyx"
+include "./codecs/json.pyx"
+include "./codecs/uuid.pyx"
+include "./codecs/numeric.pyx"
+include "./codecs/bits.pyx"
+include "./codecs/geometry.pyx"
+include "./codecs/hstore.pyx"
+include "./codecs/misc.pyx"
+include "./codecs/network.pyx"
+include "./codecs/tid.pyx"
+include "./codecs/txid.pyx"
diff --git a/asyncpg/pgproto/types.py b/asyncpg/pgproto/types.py
new file mode 100644 (file)
index 0000000..9232ae0
--- /dev/null
@@ -0,0 +1,376 @@
+# 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
+
+
+__all__ = (
+    'BitString', 'Point', 'Path', 'Polygon',
+    'Box', 'Line', 'LineSegment', 'Circle',
+)
+
+
+class BitString:
+    """Immutable representation of PostgreSQL `bit` and `varbit` types."""
+
+    __slots__ = '_bytes', '_bitlength'
+
+    def __init__(self, bitstring=None):
+        if not bitstring:
+            self._bytes = bytes()
+            self._bitlength = 0
+        else:
+            bytelen = len(bitstring) // 8 + 1
+            bytes_ = bytearray(bytelen)
+            byte = 0
+            byte_pos = 0
+            bit_pos = 0
+
+            for i, bit in enumerate(bitstring):
+                if bit == ' ':
+                    continue
+                bit = int(bit)
+                if bit != 0 and bit != 1:
+                    raise ValueError(
+                        'invalid bit value at position {}'.format(i))
+
+                byte |= bit << (8 - bit_pos - 1)
+                bit_pos += 1
+                if bit_pos == 8:
+                    bytes_[byte_pos] = byte
+                    byte = 0
+                    byte_pos += 1
+                    bit_pos = 0
+
+            if bit_pos != 0:
+                bytes_[byte_pos] = byte
+
+            bitlen = byte_pos * 8 + bit_pos
+            bytelen = byte_pos + (1 if bit_pos else 0)
+
+            self._bytes = bytes(bytes_[:bytelen])
+            self._bitlength = bitlen
+
+    @classmethod
+    def frombytes(cls, bytes_=None, bitlength=None):
+        if bitlength is None and bytes_ is None:
+            bytes_ = bytes()
+            bitlength = 0
+
+        elif bitlength is None:
+            bitlength = len(bytes_) * 8
+
+        else:
+            if bytes_ is None:
+                bytes_ = bytes(bitlength // 8 + 1)
+                bitlength = bitlength
+            else:
+                bytes_len = len(bytes_) * 8
+
+                if bytes_len == 0 and bitlength != 0:
+                    raise ValueError('invalid bit length specified')
+
+                if bytes_len != 0 and bitlength == 0:
+                    raise ValueError('invalid bit length specified')
+
+                if bitlength < bytes_len - 8:
+                    raise ValueError('invalid bit length specified')
+
+                if bitlength > bytes_len:
+                    raise ValueError('invalid bit length specified')
+
+        result = cls()
+        result._bytes = bytes_
+        result._bitlength = bitlength
+
+        return result
+
+    @property
+    def bytes(self):
+        return self._bytes
+
+    def as_string(self):
+        s = ''
+
+        for i in range(self._bitlength):
+            s += str(self._getitem(i))
+            if i % 4 == 3:
+                s += ' '
+
+        return s.strip()
+
+    def to_int(self, bitorder='big', *, signed=False):
+        """Interpret the BitString as a Python int.
+        Acts similarly to int.from_bytes.
+
+        :param bitorder:
+            Determines the bit order used to interpret the BitString. By
+            default, this function uses Postgres conventions for casting bits
+            to ints. If bitorder is 'big', the most significant bit is at the
+            start of the string (this is the same as the default). If bitorder
+            is 'little', the most significant bit is at the end of the string.
+
+        :param bool signed:
+            Determines whether two's complement is used to interpret the
+            BitString. If signed is False, the returned value is always
+            non-negative.
+
+        :return int: An integer representing the BitString. Information about
+                     the BitString's exact length is lost.
+
+        .. versionadded:: 0.18.0
+        """
+        x = int.from_bytes(self._bytes, byteorder='big')
+        x >>= -self._bitlength % 8
+        if bitorder == 'big':
+            pass
+        elif bitorder == 'little':
+            x = int(bin(x)[:1:-1].ljust(self._bitlength, '0'), 2)
+        else:
+            raise ValueError("bitorder must be either 'big' or 'little'")
+
+        if signed and self._bitlength > 0 and x & (1 << (self._bitlength - 1)):
+            x -= 1 << self._bitlength
+        return x
+
+    @classmethod
+    def from_int(cls, x, length, bitorder='big', *, signed=False):
+        """Represent the Python int x as a BitString.
+        Acts similarly to int.to_bytes.
+
+        :param int x:
+            An integer to represent. Negative integers are represented in two's
+            complement form, unless the argument signed is False, in which case
+            negative integers raise an OverflowError.
+
+        :param int length:
+            The length of the resulting BitString. An OverflowError is raised
+            if the integer is not representable in this many bits.
+
+        :param bitorder:
+            Determines the bit order used in the BitString representation. By
+            default, this function uses Postgres conventions for casting ints
+            to bits. If bitorder is 'big', the most significant bit is at the
+            start of the string (this is the same as the default). If bitorder
+            is 'little', the most significant bit is at the end of the string.
+
+        :param bool signed:
+            Determines whether two's complement is used in the BitString
+            representation. If signed is False and a negative integer is given,
+            an OverflowError is raised.
+
+        :return BitString: A BitString representing the input integer, in the
+                           form specified by the other input args.
+
+        .. versionadded:: 0.18.0
+        """
+        # Exception types are by analogy to int.to_bytes
+        if length < 0:
+            raise ValueError("length argument must be non-negative")
+        elif length < x.bit_length():
+            raise OverflowError("int too big to convert")
+
+        if x < 0:
+            if not signed:
+                raise OverflowError("can't convert negative int to unsigned")
+            x &= (1 << length) - 1
+
+        if bitorder == 'big':
+            pass
+        elif bitorder == 'little':
+            x = int(bin(x)[:1:-1].ljust(length, '0'), 2)
+        else:
+            raise ValueError("bitorder must be either 'big' or 'little'")
+
+        x <<= (-length % 8)
+        bytes_ = x.to_bytes((length + 7) // 8, byteorder='big')
+        return cls.frombytes(bytes_, length)
+
+    def __repr__(self):
+        return '<BitString {}>'.format(self.as_string())
+
+    __str__ = __repr__
+
+    def __eq__(self, other):
+        if not isinstance(other, BitString):
+            return NotImplemented
+
+        return (self._bytes == other._bytes and
+                self._bitlength == other._bitlength)
+
+    def __hash__(self):
+        return hash((self._bytes, self._bitlength))
+
+    def _getitem(self, i):
+        byte = self._bytes[i // 8]
+        shift = 8 - i % 8 - 1
+        return (byte >> shift) & 0x1
+
+    def __getitem__(self, i):
+        if isinstance(i, slice):
+            raise NotImplementedError('BitString does not support slices')
+
+        if i >= self._bitlength:
+            raise IndexError('index out of range')
+
+        return self._getitem(i)
+
+    def __len__(self):
+        return self._bitlength
+
+
+class Point(tuple):
+    """Immutable representation of PostgreSQL `point` type."""
+
+    __slots__ = ()
+
+    def __new__(cls, x, y):
+        return super().__new__(cls, (float(x), float(y)))
+
+    def __repr__(self):
+        return '{}.{}({})'.format(
+            type(self).__module__,
+            type(self).__name__,
+            tuple.__repr__(self)
+        )
+
+    @property
+    def x(self):
+        return self[0]
+
+    @property
+    def y(self):
+        return self[1]
+
+
+class Box(tuple):
+    """Immutable representation of PostgreSQL `box` type."""
+
+    __slots__ = ()
+
+    def __new__(cls, high, low):
+        return super().__new__(cls, (Point(*high), Point(*low)))
+
+    def __repr__(self):
+        return '{}.{}({})'.format(
+            type(self).__module__,
+            type(self).__name__,
+            tuple.__repr__(self)
+        )
+
+    @property
+    def high(self):
+        return self[0]
+
+    @property
+    def low(self):
+        return self[1]
+
+
+class Line(tuple):
+    """Immutable representation of PostgreSQL `line` type."""
+
+    __slots__ = ()
+
+    def __new__(cls, A, B, C):
+        return super().__new__(cls, (A, B, C))
+
+    @property
+    def A(self):
+        return self[0]
+
+    @property
+    def B(self):
+        return self[1]
+
+    @property
+    def C(self):
+        return self[2]
+
+
+class LineSegment(tuple):
+    """Immutable representation of PostgreSQL `lseg` type."""
+
+    __slots__ = ()
+
+    def __new__(cls, p1, p2):
+        return super().__new__(cls, (Point(*p1), Point(*p2)))
+
+    def __repr__(self):
+        return '{}.{}({})'.format(
+            type(self).__module__,
+            type(self).__name__,
+            tuple.__repr__(self)
+        )
+
+    @property
+    def p1(self):
+        return self[0]
+
+    @property
+    def p2(self):
+        return self[1]
+
+
+class Path:
+    """Immutable representation of PostgreSQL `path` type."""
+
+    __slots__ = '_is_closed', 'points'
+
+    def __init__(self, *points, is_closed=False):
+        self.points = tuple(Point(*p) for p in points)
+        self._is_closed = is_closed
+
+    @property
+    def is_closed(self):
+        return self._is_closed
+
+    def __eq__(self, other):
+        if not isinstance(other, Path):
+            return NotImplemented
+
+        return (self.points == other.points and
+                self._is_closed == other._is_closed)
+
+    def __hash__(self):
+        return hash((self.points, self.is_closed))
+
+    def __iter__(self):
+        return iter(self.points)
+
+    def __len__(self):
+        return len(self.points)
+
+    def __getitem__(self, i):
+        return self.points[i]
+
+    def __contains__(self, point):
+        return point in self.points
+
+
+class Polygon(Path):
+    """Immutable representation of PostgreSQL `polygon` type."""
+
+    __slots__ = ()
+
+    def __init__(self, *points):
+        # polygon is always closed
+        super().__init__(*points, is_closed=True)
+
+
+class Circle(tuple):
+    """Immutable representation of PostgreSQL `circle` type."""
+
+    __slots__ = ()
+
+    def __new__(cls, center, radius):
+        return super().__new__(cls, (center, radius))
+
+    @property
+    def center(self):
+        return self[0]
+
+    @property
+    def radius(self):
+        return self[1]
diff --git a/asyncpg/pool.py b/asyncpg/pool.py
new file mode 100644 (file)
index 0000000..e6eee9b
--- /dev/null
@@ -0,0 +1,885 @@
+# 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
+
+
+import asyncio
+import functools
+import inspect
+import logging
+import time
+import warnings
+
+from . import connection
+from . import connect_utils
+from . import exceptions
+
+
+logger = logging.getLogger(__name__)
+
+
+class PoolConnectionProxyMeta(type):
+
+    def __new__(mcls, name, bases, dct, *, wrap=False):
+        if wrap:
+            for attrname in dir(connection.Connection):
+                if attrname.startswith('_') or attrname in dct:
+                    continue
+
+                meth = getattr(connection.Connection, attrname)
+                if not inspect.isfunction(meth):
+                    continue
+
+                wrapper = mcls._wrap_connection_method(attrname)
+                wrapper = functools.update_wrapper(wrapper, meth)
+                dct[attrname] = wrapper
+
+            if '__doc__' not in dct:
+                dct['__doc__'] = connection.Connection.__doc__
+
+        return super().__new__(mcls, name, bases, dct)
+
+    def __init__(cls, name, bases, dct, *, wrap=False):
+        # Needed for Python 3.5 to handle `wrap` class keyword argument.
+        super().__init__(name, bases, dct)
+
+    @staticmethod
+    def _wrap_connection_method(meth_name):
+        def call_con_method(self, *args, **kwargs):
+            # This method will be owned by PoolConnectionProxy class.
+            if self._con is None:
+                raise exceptions.InterfaceError(
+                    'cannot call Connection.{}(): '
+                    'connection has been released back to the pool'.format(
+                        meth_name))
+
+            meth = getattr(self._con.__class__, meth_name)
+            return meth(self._con, *args, **kwargs)
+
+        return call_con_method
+
+
+class PoolConnectionProxy(connection._ConnectionProxy,
+                          metaclass=PoolConnectionProxyMeta,
+                          wrap=True):
+
+    __slots__ = ('_con', '_holder')
+
+    def __init__(self, holder: 'PoolConnectionHolder',
+                 con: connection.Connection):
+        self._con = con
+        self._holder = holder
+        con._set_proxy(self)
+
+    def __getattr__(self, attr):
+        # Proxy all unresolved attributes to the wrapped Connection object.
+        return getattr(self._con, attr)
+
+    def _detach(self) -> connection.Connection:
+        if self._con is None:
+            return
+
+        con, self._con = self._con, None
+        con._set_proxy(None)
+        return con
+
+    def __repr__(self):
+        if self._con is None:
+            return '<{classname} [released] {id:#x}>'.format(
+                classname=self.__class__.__name__, id=id(self))
+        else:
+            return '<{classname} {con!r} {id:#x}>'.format(
+                classname=self.__class__.__name__, con=self._con, id=id(self))
+
+
+class PoolConnectionHolder:
+
+    __slots__ = ('_con', '_pool', '_loop', '_proxy',
+                 '_max_queries', '_setup',
+                 '_max_inactive_time', '_in_use',
+                 '_inactive_callback', '_timeout',
+                 '_generation')
+
+    def __init__(self, pool, *, max_queries, setup, max_inactive_time):
+
+        self._pool = pool
+        self._con = None
+        self._proxy = None
+
+        self._max_queries = max_queries
+        self._max_inactive_time = max_inactive_time
+        self._setup = setup
+        self._inactive_callback = None
+        self._in_use = None  # type: asyncio.Future
+        self._timeout = None
+        self._generation = None
+
+    async def connect(self):
+        if self._con is not None:
+            raise exceptions.InternalClientError(
+                'PoolConnectionHolder.connect() called while another '
+                'connection already exists')
+
+        self._con = await self._pool._get_new_connection()
+        self._generation = self._pool._generation
+
+    async def acquire(self) -> PoolConnectionProxy:
+        if self._con is None or self._con.is_closed():
+            self._con = None
+            await self.connect()
+
+        elif self._generation != self._pool._generation:
+            # Connections have been expired, re-connect the holder.
+            self._pool._loop.create_task(
+                self._con.close(timeout=self._timeout))
+            self._con = None
+            await self.connect()
+
+        self._maybe_cancel_inactive_callback()
+
+        self._proxy = proxy = PoolConnectionProxy(self, self._con)
+
+        if self._setup is not None:
+            try:
+                await self._setup(proxy)
+            except Exception as ex:
+                # If a user-defined `setup` function fails, we don't
+                # know if the connection is safe for re-use, hence
+                # we close it.  A new connection will be created
+                # when `acquire` is called again.
+                try:
+                    # Use `close()` to close the connection gracefully.
+                    # An exception in `setup` isn't necessarily caused
+                    # by an IO or a protocol error.  close() will
+                    # do the necessary cleanup via _release_on_close().
+                    await self._con.close()
+                finally:
+                    raise ex
+
+        self._in_use = self._pool._loop.create_future()
+
+        return proxy
+
+    async def release(self, timeout):
+        if self._in_use is None:
+            raise exceptions.InternalClientError(
+                'PoolConnectionHolder.release() called on '
+                'a free connection holder')
+
+        if self._con.is_closed():
+            # When closing, pool connections perform the necessary
+            # cleanup, so we don't have to do anything else here.
+            return
+
+        self._timeout = None
+
+        if self._con._protocol.queries_count >= self._max_queries:
+            # The connection has reached its maximum utilization limit,
+            # so close it.  Connection.close() will call _release().
+            await self._con.close(timeout=timeout)
+            return
+
+        if self._generation != self._pool._generation:
+            # The connection has expired because it belongs to
+            # an older generation (Pool.expire_connections() has
+            # been called.)
+            await self._con.close(timeout=timeout)
+            return
+
+        try:
+            budget = timeout
+
+            if self._con._protocol._is_cancelling():
+                # If the connection is in cancellation state,
+                # wait for the cancellation
+                started = time.monotonic()
+                await asyncio.wait_for(
+                    self._con._protocol._wait_for_cancellation(),
+                    budget, loop=self._pool._loop)
+                if budget is not None:
+                    budget -= time.monotonic() - started
+
+            await self._con.reset(timeout=budget)
+        except Exception as ex:
+            # If the `reset` call failed, terminate the connection.
+            # A new one will be created when `acquire` is called
+            # again.
+            try:
+                # An exception in `reset` is most likely caused by
+                # an IO error, so terminate the connection.
+                self._con.terminate()
+            finally:
+                raise ex
+
+        # Free this connection holder and invalidate the
+        # connection proxy.
+        self._release()
+
+        # Rearm the connection inactivity timer.
+        self._setup_inactive_callback()
+
+    async def wait_until_released(self):
+        if self._in_use is None:
+            return
+        else:
+            await self._in_use
+
+    async def close(self):
+        if self._con is not None:
+            # Connection.close() will call _release_on_close() to
+            # finish holder cleanup.
+            await self._con.close()
+
+    def terminate(self):
+        if self._con is not None:
+            # Connection.terminate() will call _release_on_close() to
+            # finish holder cleanup.
+            self._con.terminate()
+
+    def _setup_inactive_callback(self):
+        if self._inactive_callback is not None:
+            raise exceptions.InternalClientError(
+                'pool connection inactivity timer already exists')
+
+        if self._max_inactive_time:
+            self._inactive_callback = self._pool._loop.call_later(
+                self._max_inactive_time, self._deactivate_inactive_connection)
+
+    def _maybe_cancel_inactive_callback(self):
+        if self._inactive_callback is not None:
+            self._inactive_callback.cancel()
+            self._inactive_callback = None
+
+    def _deactivate_inactive_connection(self):
+        if self._in_use is not None:
+            raise exceptions.InternalClientError(
+                'attempting to deactivate an acquired connection')
+
+        if self._con is not None:
+            # The connection is idle and not in use, so it's fine to
+            # use terminate() instead of close().
+            self._con.terminate()
+            # Must call clear_connection, because _deactivate_connection
+            # is called when the connection is *not* checked out, and
+            # so terminate() above will not call the below.
+            self._release_on_close()
+
+    def _release_on_close(self):
+        self._maybe_cancel_inactive_callback()
+        self._release()
+        self._con = None
+
+    def _release(self):
+        """Release this connection holder."""
+        if self._in_use is None:
+            # The holder is not checked out.
+            return
+
+        if not self._in_use.done():
+            self._in_use.set_result(None)
+        self._in_use = None
+
+        # Deinitialize the connection proxy.  All subsequent
+        # operations on it will fail.
+        if self._proxy is not None:
+            self._proxy._detach()
+            self._proxy = None
+
+        # Put ourselves back to the pool queue.
+        self._pool._queue.put_nowait(self)
+
+
+class Pool:
+    """A connection pool.
+
+    Connection pool can be used to manage a set of connections to the database.
+    Connections are first acquired from the pool, then used, and then released
+    back to the pool.  Once a connection is released, it's reset to close all
+    open cursors and other resources *except* prepared statements.
+
+    Pools are created by calling :func:`~asyncpg.pool.create_pool`.
+    """
+
+    __slots__ = ('_queue', '_loop', '_minsize', '_maxsize',
+                 '_init', '_connect_args', '_connect_kwargs',
+                 '_working_addr', '_working_config', '_working_params',
+                 '_holders', '_initialized', '_initializing', '_closing',
+                 '_closed', '_connection_class', '_generation')
+
+    def __init__(self, *connect_args,
+                 min_size,
+                 max_size,
+                 max_queries,
+                 max_inactive_connection_lifetime,
+                 setup,
+                 init,
+                 loop,
+                 connection_class,
+                 **connect_kwargs):
+
+        if len(connect_args) > 1:
+            warnings.warn(
+                "Passing multiple positional arguments to asyncpg.Pool "
+                "constructor is deprecated and will be removed in "
+                "asyncpg 0.17.0.  The non-deprecated form is "
+                "asyncpg.Pool(<dsn>, **kwargs)",
+                DeprecationWarning, stacklevel=2)
+
+        if loop is None:
+            loop = asyncio.get_event_loop()
+        self._loop = loop
+
+        if max_size <= 0:
+            raise ValueError('max_size is expected to be greater than zero')
+
+        if min_size < 0:
+            raise ValueError(
+                'min_size is expected to be greater or equal to zero')
+
+        if min_size > max_size:
+            raise ValueError('min_size is greater than max_size')
+
+        if max_queries <= 0:
+            raise ValueError('max_queries is expected to be greater than zero')
+
+        if max_inactive_connection_lifetime < 0:
+            raise ValueError(
+                'max_inactive_connection_lifetime is expected to be greater '
+                'or equal to zero')
+
+        if not issubclass(connection_class, connection.Connection):
+            raise TypeError(
+                'connection_class is expected to be a subclass of '
+                'asyncpg.Connection, got {!r}'.format(connection_class))
+
+        self._minsize = min_size
+        self._maxsize = max_size
+
+        self._holders = []
+        self._initialized = False
+        self._initializing = False
+        self._queue = asyncio.LifoQueue(maxsize=self._maxsize, loop=self._loop)
+
+        self._working_addr = None
+        self._working_config = None
+        self._working_params = None
+
+        self._connection_class = connection_class
+
+        self._closing = False
+        self._closed = False
+        self._generation = 0
+        self._init = init
+        self._connect_args = connect_args
+        self._connect_kwargs = connect_kwargs
+
+        for _ in range(max_size):
+            ch = PoolConnectionHolder(
+                self,
+                max_queries=max_queries,
+                max_inactive_time=max_inactive_connection_lifetime,
+                setup=setup)
+
+            self._holders.append(ch)
+            self._queue.put_nowait(ch)
+
+    async def _async__init__(self):
+        if self._initialized:
+            return
+        if self._initializing:
+            raise exceptions.InterfaceError(
+                'pool is being initialized in another task')
+        if self._closed:
+            raise exceptions.InterfaceError('pool is closed')
+        self._initializing = True
+        try:
+            await self._initialize()
+            return self
+        finally:
+            self._initializing = False
+            self._initialized = True
+
+    async def _initialize(self):
+        if self._minsize:
+            # Since we use a LIFO queue, the first items in the queue will be
+            # the last ones in `self._holders`.  We want to pre-connect the
+            # first few connections in the queue, therefore we want to walk
+            # `self._holders` in reverse.
+
+            # Connect the first connection holder in the queue so that it
+            # can record `_working_addr` and `_working_opts`, which will
+            # speed up successive connection attempts.
+            first_ch = self._holders[-1]  # type: PoolConnectionHolder
+            await first_ch.connect()
+
+            if self._minsize > 1:
+                connect_tasks = []
+                for i, ch in enumerate(reversed(self._holders[:-1])):
+                    # `minsize - 1` because we already have first_ch
+                    if i >= self._minsize - 1:
+                        break
+                    connect_tasks.append(ch.connect())
+
+                await asyncio.gather(*connect_tasks, loop=self._loop)
+
+    def set_connect_args(self, dsn=None, **connect_kwargs):
+        r"""Set the new connection arguments for this pool.
+
+        The new connection arguments will be used for all subsequent
+        new connection attempts.  Existing connections will remain until
+        they expire. Use :meth:`Pool.expire_connections()
+        <asyncpg.pool.Pool.expire_connections>` to expedite the connection
+        expiry.
+
+        :param str dsn:
+            Connection arguments specified using as a single string in
+            the following format:
+            ``postgres://user:pass@host:port/database?option=value``.
+
+        :param \*\*connect_kwargs:
+            Keyword arguments for the :func:`~asyncpg.connection.connect`
+            function.
+
+        .. versionadded:: 0.16.0
+        """
+
+        self._connect_args = [dsn]
+        self._connect_kwargs = connect_kwargs
+        self._working_addr = None
+        self._working_config = None
+        self._working_params = None
+
+    async def _get_new_connection(self):
+        if self._working_addr is None:
+            # First connection attempt on this pool.
+            con = await connection.connect(
+                *self._connect_args,
+                loop=self._loop,
+                connection_class=self._connection_class,
+                **self._connect_kwargs)
+
+            self._working_addr = con._addr
+            self._working_config = con._config
+            self._working_params = con._params
+
+        else:
+            # We've connected before and have a resolved address,
+            # and parsed options and config.
+            con = await connect_utils._connect_addr(
+                loop=self._loop,
+                addr=self._working_addr,
+                timeout=self._working_params.connect_timeout,
+                config=self._working_config,
+                params=self._working_params,
+                connection_class=self._connection_class)
+
+        if self._init is not None:
+            try:
+                await self._init(con)
+            except Exception as ex:
+                # If a user-defined `init` function fails, we don't
+                # know if the connection is safe for re-use, hence
+                # we close it.  A new connection will be created
+                # when `acquire` is called again.
+                try:
+                    # Use `close()` to close the connection gracefully.
+                    # An exception in `init` isn't necessarily caused
+                    # by an IO or a protocol error.  close() will
+                    # do the necessary cleanup via _release_on_close().
+                    await con.close()
+                finally:
+                    raise ex
+
+        return con
+
+    async def execute(self, query: str, *args, timeout: float=None) -> str:
+        """Execute an SQL command (or commands).
+
+        Pool performs this operation using one of its connections.  Other than
+        that, it behaves identically to
+        :meth:`Connection.execute() <connection.Connection.execute>`.
+
+        .. versionadded:: 0.10.0
+        """
+        async with self.acquire() as con:
+            return await con.execute(query, *args, timeout=timeout)
+
+    async def executemany(self, command: str, args, *, timeout: float=None):
+        """Execute an SQL *command* for each sequence of arguments in *args*.
+
+        Pool performs this operation using one of its connections.  Other than
+        that, it behaves identically to
+        :meth:`Connection.executemany() <connection.Connection.executemany>`.
+
+        .. versionadded:: 0.10.0
+        """
+        async with self.acquire() as con:
+            return await con.executemany(command, args, timeout=timeout)
+
+    async def fetch(self, query, *args, timeout=None) -> list:
+        """Run a query and return the results as a list of :class:`Record`.
+
+        Pool performs this operation using one of its connections.  Other than
+        that, it behaves identically to
+        :meth:`Connection.fetch() <connection.Connection.fetch>`.
+
+        .. versionadded:: 0.10.0
+        """
+        async with self.acquire() as con:
+            return await con.fetch(query, *args, timeout=timeout)
+
+    async def fetchval(self, query, *args, column=0, timeout=None):
+        """Run a query and return a value in the first row.
+
+        Pool performs this operation using one of its connections.  Other than
+        that, it behaves identically to
+        :meth:`Connection.fetchval() <connection.Connection.fetchval>`.
+
+        .. versionadded:: 0.10.0
+        """
+        async with self.acquire() as con:
+            return await con.fetchval(
+                query, *args, column=column, timeout=timeout)
+
+    async def fetchrow(self, query, *args, timeout=None):
+        """Run a query and return the first row.
+
+        Pool performs this operation using one of its connections.  Other than
+        that, it behaves identically to
+        :meth:`Connection.fetchrow() <connection.Connection.fetchrow>`.
+
+        .. versionadded:: 0.10.0
+        """
+        async with self.acquire() as con:
+            return await con.fetchrow(query, *args, timeout=timeout)
+
+    def acquire(self, *, timeout=None):
+        """Acquire a database connection from the pool.
+
+        :param float timeout: A timeout for acquiring a Connection.
+        :return: An instance of :class:`~asyncpg.connection.Connection`.
+
+        Can be used in an ``await`` expression or with an ``async with`` block.
+
+        .. code-block:: python
+
+            async with pool.acquire() as con:
+                await con.execute(...)
+
+        Or:
+
+        .. code-block:: python
+
+            con = await pool.acquire()
+            try:
+                await con.execute(...)
+            finally:
+                await pool.release(con)
+        """
+        return PoolAcquireContext(self, timeout)
+
+    async def _acquire(self, timeout):
+        async def _acquire_impl():
+            ch = await self._queue.get()  # type: PoolConnectionHolder
+            try:
+                proxy = await ch.acquire()  # type: PoolConnectionProxy
+            except Exception:
+                self._queue.put_nowait(ch)
+                raise
+            else:
+                # Record the timeout, as we will apply it by default
+                # in release().
+                ch._timeout = timeout
+                return proxy
+
+        if self._closing:
+            raise exceptions.InterfaceError('pool is closing')
+        self._check_init()
+
+        if timeout is None:
+            return await _acquire_impl()
+        else:
+            return await asyncio.wait_for(
+                _acquire_impl(), timeout=timeout, loop=self._loop)
+
+    async def release(self, connection, *, timeout=None):
+        """Release a database connection back to the pool.
+
+        :param Connection connection:
+            A :class:`~asyncpg.connection.Connection` object to release.
+        :param float timeout:
+            A timeout for releasing the connection.  If not specified, defaults
+            to the timeout provided in the corresponding call to the
+            :meth:`Pool.acquire() <asyncpg.pool.Pool.acquire>` method.
+
+        .. versionchanged:: 0.14.0
+            Added the *timeout* parameter.
+        """
+        if (type(connection) is not PoolConnectionProxy or
+                connection._holder._pool is not self):
+            raise exceptions.InterfaceError(
+                'Pool.release() received invalid connection: '
+                '{connection!r} is not a member of this pool'.format(
+                    connection=connection))
+
+        if connection._con is None:
+            # Already released, do nothing.
+            return
+
+        self._check_init()
+
+        # Let the connection do its internal housekeeping when its released.
+        connection._con._on_release()
+
+        ch = connection._holder
+        if timeout is None:
+            timeout = ch._timeout
+
+        # Use asyncio.shield() to guarantee that task cancellation
+        # does not prevent the connection from being returned to the
+        # pool properly.
+        return await asyncio.shield(ch.release(timeout), loop=self._loop)
+
+    async def close(self):
+        """Attempt to gracefully close all connections in the pool.
+
+        Wait until all pool connections are released, close them and
+        shut down the pool.  If any error (including cancellation) occurs
+        in ``close()`` the pool will terminate by calling
+        :meth:`Pool.terminate() <pool.Pool.terminate>`.
+
+        It is advisable to use :func:`python:asyncio.wait_for` to set
+        a timeout.
+
+        .. versionchanged:: 0.16.0
+            ``close()`` now waits until all pool connections are released
+            before closing them and the pool.  Errors raised in ``close()``
+            will cause immediate pool termination.
+        """
+        if self._closed:
+            return
+        self._check_init()
+
+        self._closing = True
+
+        try:
+            warning_callback = self._loop.call_later(
+                60, self._warn_on_long_close)
+
+            release_coros = [
+                ch.wait_until_released() for ch in self._holders]
+            await asyncio.gather(*release_coros, loop=self._loop)
+
+            close_coros = [
+                ch.close() for ch in self._holders]
+            await asyncio.gather(*close_coros, loop=self._loop)
+
+        except Exception:
+            self.terminate()
+            raise
+
+        finally:
+            warning_callback.cancel()
+            self._closed = True
+            self._closing = False
+
+    def _warn_on_long_close(self):
+        logger.warning('Pool.close() is taking over 60 seconds to complete. '
+                       'Check if you have any unreleased connections left. '
+                       'Use asyncio.wait_for() to set a timeout for '
+                       'Pool.close().')
+
+    def terminate(self):
+        """Terminate all connections in the pool."""
+        if self._closed:
+            return
+        self._check_init()
+        for ch in self._holders:
+            ch.terminate()
+        self._closed = True
+
+    async def expire_connections(self):
+        """Expire all currently open connections.
+
+        Cause all currently open connections to get replaced on the
+        next :meth:`~asyncpg.pool.Pool.acquire()` call.
+
+        .. versionadded:: 0.16.0
+        """
+        self._generation += 1
+
+    def _check_init(self):
+        if not self._initialized:
+            if self._initializing:
+                raise exceptions.InterfaceError(
+                    'pool is being initialized, but not yet ready: '
+                    'likely there is a race between creating a pool and '
+                    'using it')
+            raise exceptions.InterfaceError('pool is not initialized')
+        if self._closed:
+            raise exceptions.InterfaceError('pool is closed')
+
+    def _drop_statement_cache(self):
+        # Drop statement cache for all connections in the pool.
+        for ch in self._holders:
+            if ch._con is not None:
+                ch._con._drop_local_statement_cache()
+
+    def _drop_type_cache(self):
+        # Drop type codec cache for all connections in the pool.
+        for ch in self._holders:
+            if ch._con is not None:
+                ch._con._drop_local_type_cache()
+
+    def __await__(self):
+        return self._async__init__().__await__()
+
+    async def __aenter__(self):
+        await self._async__init__()
+        return self
+
+    async def __aexit__(self, *exc):
+        await self.close()
+
+
+class PoolAcquireContext:
+
+    __slots__ = ('timeout', 'connection', 'done', 'pool')
+
+    def __init__(self, pool, timeout):
+        self.pool = pool
+        self.timeout = timeout
+        self.connection = None
+        self.done = False
+
+    async def __aenter__(self):
+        if self.connection is not None or self.done:
+            raise exceptions.InterfaceError('a connection is already acquired')
+        self.connection = await self.pool._acquire(self.timeout)
+        return self.connection
+
+    async def __aexit__(self, *exc):
+        self.done = True
+        con = self.connection
+        self.connection = None
+        await self.pool.release(con)
+
+    def __await__(self):
+        self.done = True
+        return self.pool._acquire(self.timeout).__await__()
+
+
+def create_pool(dsn=None, *,
+                min_size=10,
+                max_size=10,
+                max_queries=50000,
+                max_inactive_connection_lifetime=300.0,
+                setup=None,
+                init=None,
+                loop=None,
+                connection_class=connection.Connection,
+                **connect_kwargs):
+    r"""Create a connection pool.
+
+    Can be used either with an ``async with`` block:
+
+    .. code-block:: python
+
+        async with asyncpg.create_pool(user='postgres',
+                                       command_timeout=60) as pool:
+            async with pool.acquire() as con:
+                await con.fetch('SELECT 1')
+
+    Or directly with ``await``:
+
+    .. code-block:: python
+
+        pool = await asyncpg.create_pool(user='postgres', command_timeout=60)
+        con = await pool.acquire()
+        try:
+            await con.fetch('SELECT 1')
+        finally:
+            await pool.release(con)
+
+    .. warning::
+        Prepared statements and cursors returned by
+        :meth:`Connection.prepare() <connection.Connection.prepare>` and
+        :meth:`Connection.cursor() <connection.Connection.cursor>` become
+        invalid once the connection is released.  Likewise, all notification
+        and log listeners are removed, and ``asyncpg`` will issue a warning
+        if there are any listener callbacks registered on a connection that
+        is being released to the pool.
+
+    :param str dsn:
+        Connection arguments specified using as a single string in
+        the following format:
+        ``postgres://user:pass@host:port/database?option=value``.
+
+    :param \*\*connect_kwargs:
+        Keyword arguments for the :func:`~asyncpg.connection.connect`
+        function.
+
+    :param Connection connection_class:
+        The class to use for connections.  Must be a subclass of
+        :class:`~asyncpg.connection.Connection`.
+
+    :param int min_size:
+        Number of connection the pool will be initialized with.
+
+    :param int max_size:
+        Max number of connections in the pool.
+
+    :param int max_queries:
+        Number of queries after a connection is closed and replaced
+        with a new connection.
+
+    :param float max_inactive_connection_lifetime:
+        Number of seconds after which inactive connections in the
+        pool will be closed.  Pass ``0`` to disable this mechanism.
+
+    :param coroutine setup:
+        A coroutine to prepare a connection right before it is returned
+        from :meth:`Pool.acquire() <pool.Pool.acquire>`.  An example use
+        case would be to automatically set up notifications listeners for
+        all connections of a pool.
+
+    :param coroutine init:
+        A coroutine to initialize a connection when it is created.
+        An example use case would be to setup type codecs with
+        :meth:`Connection.set_builtin_type_codec() <\
+        asyncpg.connection.Connection.set_builtin_type_codec>`
+        or :meth:`Connection.set_type_codec() <\
+        asyncpg.connection.Connection.set_type_codec>`.
+
+    :param loop:
+        An asyncio event loop instance.  If ``None``, the default
+        event loop will be used.
+
+    :return: An instance of :class:`~asyncpg.pool.Pool`.
+
+    .. versionchanged:: 0.10.0
+       An :exc:`~asyncpg.exceptions.InterfaceError` will be raised on any
+       attempted operation on a released connection.
+
+    .. versionchanged:: 0.13.0
+       An :exc:`~asyncpg.exceptions.InterfaceError` will be raised on any
+       attempted operation on a prepared statement or a cursor created
+       on a connection that has been released to the pool.
+
+    .. versionchanged:: 0.13.0
+       An :exc:`~asyncpg.exceptions.InterfaceWarning` will be produced
+       if there are any active listeners (added via
+       :meth:`Connection.add_listener() <connection.Connection.add_listener>`
+       or :meth:`Connection.add_log_listener()
+       <connection.Connection.add_log_listener>`) present on the connection
+       at the moment of its release to the pool.
+    """
+    return Pool(
+        dsn,
+        connection_class=connection_class,
+        min_size=min_size, max_size=max_size,
+        max_queries=max_queries, loop=loop, setup=setup, init=init,
+        max_inactive_connection_lifetime=max_inactive_connection_lifetime,
+        **connect_kwargs)
diff --git a/asyncpg/prepared_stmt.py b/asyncpg/prepared_stmt.py
new file mode 100644 (file)
index 0000000..09a0a2e
--- /dev/null
@@ -0,0 +1,227 @@
+# 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
+
+
+import json
+
+from . import connresource
+from . import cursor
+from . import exceptions
+
+
+class PreparedStatement(connresource.ConnectionResource):
+    """A representation of a prepared statement."""
+
+    __slots__ = ('_state', '_query', '_last_status')
+
+    def __init__(self, connection, query, state):
+        super().__init__(connection)
+        self._state = state
+        self._query = query
+        state.attach()
+        self._last_status = None
+
+    @connresource.guarded
+    def get_query(self) -> str:
+        """Return the text of the query for this prepared statement.
+
+        Example::
+
+            stmt = await connection.prepare('SELECT $1::int')
+            assert stmt.get_query() == "SELECT $1::int"
+        """
+        return self._query
+
+    @connresource.guarded
+    def get_statusmsg(self) -> str:
+        """Return the status of the executed command.
+
+        Example::
+
+            stmt = await connection.prepare('CREATE TABLE mytab (a int)')
+            await stmt.fetch()
+            assert stmt.get_statusmsg() == "CREATE TABLE"
+        """
+        if self._last_status is None:
+            return self._last_status
+        return self._last_status.decode()
+
+    @connresource.guarded
+    def get_parameters(self):
+        """Return a description of statement parameters types.
+
+        :return: A tuple of :class:`asyncpg.types.Type`.
+
+        Example::
+
+            stmt = await connection.prepare('SELECT ($1::int, $2::text)')
+            print(stmt.get_parameters())
+
+            # Will print:
+            #   (Type(oid=23, name='int4', kind='scalar', schema='pg_catalog'),
+            #    Type(oid=25, name='text', kind='scalar', schema='pg_catalog'))
+        """
+        return self._state._get_parameters()
+
+    @connresource.guarded
+    def get_attributes(self):
+        """Return a description of relation attributes (columns).
+
+        :return: A tuple of :class:`asyncpg.types.Attribute`.
+
+        Example::
+
+            st = await self.con.prepare('''
+                SELECT typname, typnamespace FROM pg_type
+            ''')
+            print(st.get_attributes())
+
+            # Will print:
+            #   (Attribute(
+            #       name='typname',
+            #       type=Type(oid=19, name='name', kind='scalar',
+            #                 schema='pg_catalog')),
+            #    Attribute(
+            #       name='typnamespace',
+            #       type=Type(oid=26, name='oid', kind='scalar',
+            #                 schema='pg_catalog')))
+        """
+        return self._state._get_attributes()
+
+    @connresource.guarded
+    def cursor(self, *args, prefetch=None,
+               timeout=None) -> cursor.CursorFactory:
+        """Return a *cursor factory* for the prepared statement.
+
+        :param args: Query arguments.
+        :param int prefetch: The number of rows the *cursor iterator*
+                             will prefetch (defaults to ``50``.)
+        :param float timeout: Optional timeout in seconds.
+
+        :return: A :class:`~cursor.CursorFactory` object.
+        """
+        return cursor.CursorFactory(self._connection, self._query,
+                                    self._state, args, prefetch,
+                                    timeout)
+
+    @connresource.guarded
+    async def explain(self, *args, analyze=False):
+        """Return the execution plan of the statement.
+
+        :param args: Query arguments.
+        :param analyze: If ``True``, the statement will be executed and
+                        the run time statitics added to the return value.
+
+        :return: An object representing the execution plan.  This value
+                 is actually a deserialized JSON output of the SQL
+                 ``EXPLAIN`` command.
+        """
+        query = 'EXPLAIN (FORMAT JSON, VERBOSE'
+        if analyze:
+            query += ', ANALYZE) '
+        else:
+            query += ') '
+        query += self._state.query
+
+        if analyze:
+            # From PostgreSQL docs:
+            # Important: Keep in mind that the statement is actually
+            # executed when the ANALYZE option is used. Although EXPLAIN
+            # will discard any output that a SELECT would return, other
+            # side effects of the statement will happen as usual. If you
+            # wish to use EXPLAIN ANALYZE on an INSERT, UPDATE, DELETE,
+            # CREATE TABLE AS, or EXECUTE statement without letting the
+            # command affect your data, use this approach:
+            #     BEGIN;
+            #     EXPLAIN ANALYZE ...;
+            #     ROLLBACK;
+            tr = self._connection.transaction()
+            await tr.start()
+            try:
+                data = await self._connection.fetchval(query, *args)
+            finally:
+                await tr.rollback()
+        else:
+            data = await self._connection.fetchval(query, *args)
+
+        return json.loads(data)
+
+    @connresource.guarded
+    async def fetch(self, *args, timeout=None):
+        r"""Execute the statement and return a list of :class:`Record` objects.
+
+        :param str query: Query text
+        :param args: Query arguments
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: A list of :class:`Record` instances.
+        """
+        data = await self.__bind_execute(args, 0, timeout)
+        return data
+
+    @connresource.guarded
+    async def fetchval(self, *args, column=0, timeout=None):
+        """Execute the statement and return a value in the first row.
+
+        :param args: Query arguments.
+        :param int column: Numeric index within the record of the value to
+                           return (defaults to 0).
+        :param float timeout: Optional timeout value in seconds.
+                            If not specified, defaults to the value of
+                            ``command_timeout`` argument to the ``Connection``
+                            instance constructor.
+
+        :return: The value of the specified column of the first record.
+        """
+        data = await self.__bind_execute(args, 1, timeout)
+        if not data:
+            return None
+        return data[0][column]
+
+    @connresource.guarded
+    async def fetchrow(self, *args, timeout=None):
+        """Execute the statement and return the first row.
+
+        :param str query: Query text
+        :param args: Query arguments
+        :param float timeout: Optional timeout value in seconds.
+
+        :return: The first row as a :class:`Record` instance.
+        """
+        data = await self.__bind_execute(args, 1, timeout)
+        if not data:
+            return None
+        return data[0]
+
+    async def __bind_execute(self, args, limit, timeout):
+        protocol = self._connection._protocol
+        try:
+            data, status, _ = await protocol.bind_execute(
+                self._state, args, '', limit, True, timeout)
+        except exceptions.OutdatedSchemaCacheError:
+            await self._connection.reload_schema_state()
+            # We can not find all manually created prepared statements, so just
+            # drop known cached ones in the `self._connection`.
+            # Other manually created prepared statements will fail and
+            # invalidate themselves (unfortunately, clearing caches again).
+            self._state.mark_closed()
+            raise
+        self._last_status = status
+        return data
+
+    def _check_open(self, meth_name):
+        if self._state.closed:
+            raise exceptions.InterfaceError(
+                'cannot call PreparedStmt.{}(): '
+                'the prepared statement is closed'.format(meth_name))
+
+    def _check_conn_validity(self, meth_name):
+        self._check_open(meth_name)
+        super()._check_conn_validity(meth_name)
+
+    def __del__(self):
+        self._state.detach()
+        self._connection._maybe_gc_stmt(self._state)
diff --git a/asyncpg/protocol/__init__.py b/asyncpg/protocol/__init__.py
new file mode 100644 (file)
index 0000000..e872e2f
--- /dev/null
@@ -0,0 +1,8 @@
+# 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
+
+
+from .protocol import Protocol, Record, NO_TIMEOUT  # NOQA
diff --git a/asyncpg/protocol/codecs/__init__.py b/asyncpg/protocol/codecs/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/asyncpg/protocol/codecs/array.pyx b/asyncpg/protocol/codecs/array.pyx
new file mode 100644 (file)
index 0000000..46bdb73
--- /dev/null
@@ -0,0 +1,876 @@
+# 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
+
+
+from collections.abc import (Iterable as IterableABC,
+                             Mapping as MappingABC,
+                             Sized as SizedABC)
+
+from asyncpg import exceptions
+
+
+DEF ARRAY_MAXDIM = 6  # defined in postgresql/src/includes/c.h
+
+# "NULL"
+cdef Py_UCS4 *APG_NULL = [0x004E, 0x0055, 0x004C, 0x004C, 0x0000]
+
+
+ctypedef object (*encode_func_ex)(ConnectionSettings settings,
+                                  WriteBuffer buf,
+                                  object obj,
+                                  const void *arg)
+
+
+ctypedef object (*decode_func_ex)(ConnectionSettings settings,
+                                  FRBuffer *buf,
+                                  const void *arg)
+
+
+cdef inline bint _is_trivial_container(object obj):
+    return cpython.PyUnicode_Check(obj) or cpython.PyBytes_Check(obj) or \
+            cpythonx.PyByteArray_Check(obj) or cpythonx.PyMemoryView_Check(obj)
+
+
+cdef inline _is_array_iterable(object obj):
+    return (
+        isinstance(obj, IterableABC) and
+        isinstance(obj, SizedABC) and
+        not _is_trivial_container(obj) and
+        not isinstance(obj, MappingABC)
+    )
+
+
+cdef inline _is_sub_array_iterable(object obj):
+    # Sub-arrays have a specialized check, because we treat
+    # nested tuples as records.
+    return _is_array_iterable(obj) and not cpython.PyTuple_Check(obj)
+
+
+cdef _get_array_shape(object obj, int32_t *dims, int32_t *ndims):
+    cdef:
+        ssize_t mylen = len(obj)
+        ssize_t elemlen = -2
+        object it
+
+    if mylen > _MAXINT32:
+        raise ValueError('too many elements in array value')
+
+    if ndims[0] > ARRAY_MAXDIM:
+        raise ValueError(
+            'number of array dimensions ({}) exceed the maximum expected ({})'.
+                format(ndims[0], ARRAY_MAXDIM))
+
+    dims[ndims[0] - 1] = <int32_t>mylen
+
+    for elem in obj:
+        if _is_sub_array_iterable(elem):
+            if elemlen == -2:
+                elemlen = len(elem)
+                if elemlen > _MAXINT32:
+                    raise ValueError('too many elements in array value')
+                ndims[0] += 1
+                _get_array_shape(elem, dims, ndims)
+            else:
+                if len(elem) != elemlen:
+                    raise ValueError('non-homogeneous array')
+        else:
+            if elemlen >= 0:
+                raise ValueError('non-homogeneous array')
+            else:
+                elemlen = -1
+
+
+cdef _write_array_data(ConnectionSettings settings, object obj, int32_t ndims,
+                       int32_t dim, WriteBuffer elem_data,
+                       encode_func_ex encoder, const void *encoder_arg):
+    if dim < ndims - 1:
+        for item in obj:
+            _write_array_data(settings, item, ndims, dim + 1, elem_data,
+                              encoder, encoder_arg)
+    else:
+        for item in obj:
+            if item is None:
+                elem_data.write_int32(-1)
+            else:
+                try:
+                    encoder(settings, elem_data, item, encoder_arg)
+                except TypeError as e:
+                    raise ValueError(
+                        'invalid array element: {}'.format(e.args[0])) from None
+
+
+cdef inline array_encode(ConnectionSettings settings, WriteBuffer buf,
+                         object obj, uint32_t elem_oid,
+                         encode_func_ex encoder, const void *encoder_arg):
+    cdef:
+        WriteBuffer elem_data
+        int32_t dims[ARRAY_MAXDIM]
+        int32_t ndims = 1
+        int32_t i
+
+    if not _is_array_iterable(obj):
+        raise TypeError(
+            'a sized iterable container expected (got type {!r})'.format(
+                type(obj).__name__))
+
+    _get_array_shape(obj, dims, &ndims)
+
+    elem_data = WriteBuffer.new()
+
+    if ndims > 1:
+        _write_array_data(settings, obj, ndims, 0, elem_data,
+                          encoder, encoder_arg)
+    else:
+        for i, item in enumerate(obj):
+            if item is None:
+                elem_data.write_int32(-1)
+            else:
+                try:
+                    encoder(settings, elem_data, item, encoder_arg)
+                except TypeError as e:
+                    raise ValueError(
+                        'invalid array element at index {}: {}'.format(
+                            i, e.args[0])) from None
+
+    buf.write_int32(12 + 8 * ndims + elem_data.len())
+    # Number of dimensions
+    buf.write_int32(ndims)
+    # flags
+    buf.write_int32(0)
+    # element type
+    buf.write_int32(<int32_t>elem_oid)
+    # upper / lower bounds
+    for i in range(ndims):
+        buf.write_int32(dims[i])
+        buf.write_int32(1)
+    # element data
+    buf.write_buffer(elem_data)
+
+
+cdef _write_textarray_data(ConnectionSettings settings, object obj,
+                           int32_t ndims, int32_t dim, WriteBuffer array_data,
+                           encode_func_ex encoder, const void *encoder_arg,
+                           Py_UCS4 typdelim):
+    cdef:
+        ssize_t i = 0
+        int8_t delim = <int8_t>typdelim
+        WriteBuffer elem_data
+        Py_buffer pybuf
+        const char *elem_str
+        char ch
+        ssize_t elem_len
+        ssize_t quoted_elem_len
+        bint need_quoting
+
+    array_data.write_byte(b'{')
+
+    if dim < ndims - 1:
+        for item in obj:
+            if i > 0:
+                array_data.write_byte(delim)
+                array_data.write_byte(b' ')
+            _write_textarray_data(settings, item, ndims, dim + 1, array_data,
+                                  encoder, encoder_arg, typdelim)
+            i += 1
+    else:
+        for item in obj:
+            elem_data = WriteBuffer.new()
+
+            if i > 0:
+                array_data.write_byte(delim)
+                array_data.write_byte(b' ')
+
+            if item is None:
+                array_data.write_bytes(b'NULL')
+                i += 1
+                continue
+            else:
+                try:
+                    encoder(settings, elem_data, item, encoder_arg)
+                except TypeError as e:
+                    raise ValueError(
+                        'invalid array element: {}'.format(
+                            e.args[0])) from None
+
+            # element string length (first four bytes are the encoded length.)
+            elem_len = elem_data.len() - 4
+
+            if elem_len == 0:
+                # Empty string
+                array_data.write_bytes(b'""')
+            else:
+                cpython.PyObject_GetBuffer(
+                    elem_data, &pybuf, cpython.PyBUF_SIMPLE)
+
+                elem_str = <const char*>(pybuf.buf) + 4
+
+                try:
+                    if not apg_strcasecmp_char(elem_str, b'NULL'):
+                        array_data.write_bytes(b'"NULL"')
+                    else:
+                        quoted_elem_len = elem_len
+                        need_quoting = False
+
+                        for i in range(elem_len):
+                            ch = elem_str[i]
+                            if ch == b'"' or ch == b'\\':
+                                # Quotes and backslashes need escaping.
+                                quoted_elem_len += 1
+                                need_quoting = True
+                            elif (ch == b'{' or ch == b'}' or ch == delim or
+                                    apg_ascii_isspace(<uint32_t>ch)):
+                                need_quoting = True
+
+                        if need_quoting:
+                            array_data.write_byte(b'"')
+
+                            if quoted_elem_len == elem_len:
+                                array_data.write_cstr(elem_str, elem_len)
+                            else:
+                                # Escaping required.
+                                for i in range(elem_len):
+                                    ch = elem_str[i]
+                                    if ch == b'"' or ch == b'\\':
+                                        array_data.write_byte(b'\\')
+                                    array_data.write_byte(ch)
+
+                            array_data.write_byte(b'"')
+                        else:
+                            array_data.write_cstr(elem_str, elem_len)
+                finally:
+                    cpython.PyBuffer_Release(&pybuf)
+
+            i += 1
+
+    array_data.write_byte(b'}')
+
+
+cdef inline textarray_encode(ConnectionSettings settings, WriteBuffer buf,
+                             object obj, encode_func_ex encoder,
+                             const void *encoder_arg, Py_UCS4 typdelim):
+    cdef:
+        WriteBuffer array_data
+        int32_t dims[ARRAY_MAXDIM]
+        int32_t ndims = 1
+        int32_t i
+
+    if not _is_array_iterable(obj):
+        raise TypeError(
+            'a sized iterable container expected (got type {!r})'.format(
+                type(obj).__name__))
+
+    _get_array_shape(obj, dims, &ndims)
+
+    array_data = WriteBuffer.new()
+    _write_textarray_data(settings, obj, ndims, 0, array_data,
+                          encoder, encoder_arg, typdelim)
+    buf.write_int32(array_data.len())
+    buf.write_buffer(array_data)
+
+
+cdef inline array_decode(ConnectionSettings settings, FRBuffer *buf,
+                         decode_func_ex decoder, const void *decoder_arg):
+    cdef:
+        int32_t ndims = hton.unpack_int32(frb_read(buf, 4))
+        int32_t flags = hton.unpack_int32(frb_read(buf, 4))
+        uint32_t elem_oid = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+        list result
+        int i
+        int32_t elem_len
+        int32_t elem_count = 1
+        FRBuffer elem_buf
+        int32_t dims[ARRAY_MAXDIM]
+        Codec elem_codec
+
+    if ndims == 0:
+        result = cpython.PyList_New(0)
+        return result
+
+    if ndims > ARRAY_MAXDIM:
+        raise exceptions.ProtocolError(
+            'number of array dimensions ({}) exceed the maximum expected ({})'.
+            format(ndims, ARRAY_MAXDIM))
+
+    for i in range(ndims):
+        dims[i] = hton.unpack_int32(frb_read(buf, 4))
+        # Ignore the lower bound information
+        frb_read(buf, 4)
+
+    if ndims == 1:
+        # Fast path for flat arrays
+        elem_count = dims[0]
+        result = cpython.PyList_New(elem_count)
+
+        for i in range(elem_count):
+            elem_len = hton.unpack_int32(frb_read(buf, 4))
+            if elem_len == -1:
+                elem = None
+            else:
+                frb_slice_from(&elem_buf, buf, elem_len)
+                elem = decoder(settings, &elem_buf, decoder_arg)
+
+            cpython.Py_INCREF(elem)
+            cpython.PyList_SET_ITEM(result, i, elem)
+
+    else:
+        result = _nested_array_decode(settings, buf,
+                                      decoder, decoder_arg, ndims, dims,
+                                      &elem_buf)
+
+    return result
+
+
+cdef _nested_array_decode(ConnectionSettings settings,
+                          FRBuffer *buf,
+                          decode_func_ex decoder,
+                          const void *decoder_arg,
+                          int32_t ndims, int32_t *dims,
+                          FRBuffer *elem_buf):
+
+    cdef:
+        int32_t elem_len
+        int64_t i, j
+        int64_t array_len = 1
+        object elem, stride
+        # An array of pointers to lists for each current array level.
+        void *strides[ARRAY_MAXDIM]
+        # An array of current positions at each array level.
+        int32_t indexes[ARRAY_MAXDIM]
+
+    if PG_DEBUG:
+        if ndims <= 0:
+            raise exceptions.ProtocolError(
+                'unexpected ndims value: {}'.format(ndims))
+
+    for i in range(ndims):
+        array_len *= dims[i]
+        indexes[i] = 0
+
+    for i in range(array_len):
+        # Decode the element.
+        elem_len = hton.unpack_int32(frb_read(buf, 4))
+        if elem_len == -1:
+            elem = None
+        else:
+            elem = decoder(settings,
+                           frb_slice_from(elem_buf, buf, elem_len),
+                           decoder_arg)
+
+        # Take an explicit reference for PyList_SET_ITEM in the below
+        # loop expects this.
+        cpython.Py_INCREF(elem)
+
+        # Iterate over array dimentions and put the element in
+        # the correctly nested sublist.
+        for j in reversed(range(ndims)):
+            if indexes[j] == 0:
+                # Allocate the list for this array level.
+                stride = cpython.PyList_New(dims[j])
+
+                strides[j] = <void*><cpython.PyObject>stride
+                # Take an explicit reference for PyList_SET_ITEM below
+                # expects this.
+                cpython.Py_INCREF(stride)
+
+            stride = <object><cpython.PyObject*>strides[j]
+            cpython.PyList_SET_ITEM(stride, indexes[j], elem)
+            indexes[j] += 1
+
+            if indexes[j] == dims[j] and j != 0:
+                # This array level is full, continue the
+                # ascent in the dimensions so that this level
+                # sublist will be appened to the parent list.
+                elem = stride
+                # Reset the index, this will cause the
+                # new list to be allocated on the next
+                # iteration on this array axis.
+                indexes[j] = 0
+            else:
+                break
+
+    stride = <object><cpython.PyObject*>strides[0]
+    # Since each element in strides has a refcount of 1,
+    # returning strides[0] will increment it to 2, so
+    # balance that.
+    cpython.Py_DECREF(stride)
+    return stride
+
+
+cdef textarray_decode(ConnectionSettings settings, FRBuffer *buf,
+                      decode_func_ex decoder, const void *decoder_arg,
+                      Py_UCS4 typdelim):
+    cdef:
+        Py_UCS4 *array_text
+        str s
+
+    # Make a copy of array data since we will be mutating it for
+    # the purposes of element decoding.
+    s = pgproto.text_decode(settings, buf)
+    array_text = cpythonx.PyUnicode_AsUCS4Copy(s)
+
+    try:
+        return _textarray_decode(
+            settings, array_text, decoder, decoder_arg, typdelim)
+    except ValueError as e:
+        raise exceptions.ProtocolError(
+            'malformed array literal {!r}: {}'.format(s, e.args[0]))
+    finally:
+        cpython.PyMem_Free(array_text)
+
+
+cdef _textarray_decode(ConnectionSettings settings,
+                       Py_UCS4 *array_text,
+                       decode_func_ex decoder,
+                       const void *decoder_arg,
+                       Py_UCS4 typdelim):
+
+    cdef:
+        bytearray array_bytes
+        list result
+        list new_stride
+        Py_UCS4 *ptr
+        int32_t ndims = 0
+        int32_t ubound = 0
+        int32_t lbound = 0
+        int32_t dims[ARRAY_MAXDIM]
+        int32_t inferred_dims[ARRAY_MAXDIM]
+        int32_t inferred_ndims = 0
+        void *strides[ARRAY_MAXDIM]
+        int32_t indexes[ARRAY_MAXDIM]
+        int32_t nest_level = 0
+        int32_t item_level = 0
+        bint end_of_array = False
+
+        bint end_of_item = False
+        bint has_quoting = False
+        bint strip_spaces = False
+        bint in_quotes = False
+        Py_UCS4 *item_start
+        Py_UCS4 *item_ptr
+        Py_UCS4 *item_end
+
+        int i
+        object item
+        str item_text
+        FRBuffer item_buf
+        char *pg_item_str
+        ssize_t pg_item_len
+
+    ptr = array_text
+
+    while True:
+        while apg_ascii_isspace(ptr[0]):
+            ptr += 1
+
+        if ptr[0] != '[':
+            # Finished parsing dimensions spec.
+            break
+
+        ptr += 1  # '['
+
+        if ndims > ARRAY_MAXDIM:
+            raise ValueError(
+                'number of array dimensions ({}) exceed the '
+                'maximum expected ({})'.format(ndims, ARRAY_MAXDIM))
+
+        ptr = apg_parse_int32(ptr, &ubound)
+        if ptr == NULL:
+            raise ValueError('missing array dimension value')
+
+        if ptr[0] == ':':
+            ptr += 1
+            lbound = ubound
+
+            # [lower:upper] spec.  We disregard the lbound for decoding.
+            ptr = apg_parse_int32(ptr, &ubound)
+            if ptr == NULL:
+                raise ValueError('missing array dimension value')
+        else:
+            lbound = 1
+
+        if ptr[0] != ']':
+            raise ValueError('missing \']\' after array dimensions')
+
+        ptr += 1  # ']'
+
+        dims[ndims] = ubound - lbound + 1
+        ndims += 1
+
+    if ndims != 0:
+        # If dimensions were given, the '=' token is expected.
+        if ptr[0] != '=':
+            raise ValueError('missing \'=\' after array dimensions')
+
+        ptr += 1  # '='
+
+        # Skip any whitespace after the '=', whitespace
+        # before was consumed in the above loop.
+        while apg_ascii_isspace(ptr[0]):
+            ptr += 1
+
+        # Infer the dimensions from the brace structure in the
+        # array literal body, and check that it matches the explicit
+        # spec.  This also validates that the array literal is sane.
+        _infer_array_dims(ptr, typdelim, inferred_dims, &inferred_ndims)
+
+        if inferred_ndims != ndims:
+            raise ValueError(
+                'specified array dimensions do not match array content')
+
+        for i in range(ndims):
+            if inferred_dims[i] != dims[i]:
+                raise ValueError(
+                    'specified array dimensions do not match array content')
+    else:
+        # Infer the dimensions from the brace structure in the array literal
+        # body.  This also validates that the array literal is sane.
+        _infer_array_dims(ptr, typdelim, dims, &ndims)
+
+    while not end_of_array:
+        # We iterate over the literal character by character
+        # and modify the string in-place removing the array-specific
+        # quoting and determining the boundaries of each element.
+        end_of_item = has_quoting = in_quotes = False
+        strip_spaces = True
+
+        # Pointers to array element start, end, and the current pointer
+        # tracking the position where characters are written when
+        # escaping is folded.
+        item_start = item_end = item_ptr = ptr
+        item_level = 0
+
+        while not end_of_item:
+            if ptr[0] == '"':
+                in_quotes = not in_quotes
+                if in_quotes:
+                    strip_spaces = False
+                else:
+                    item_end = item_ptr
+                has_quoting = True
+
+            elif ptr[0] == '\\':
+                # Quoted character, collapse the backslash.
+                ptr += 1
+                has_quoting = True
+                item_ptr[0] = ptr[0]
+                item_ptr += 1
+                strip_spaces = False
+                item_end = item_ptr
+
+            elif in_quotes:
+                # Consume the string until we see the closing quote.
+                item_ptr[0] = ptr[0]
+                item_ptr += 1
+
+            elif ptr[0] == '{':
+                # Nesting level increase.
+                nest_level += 1
+
+                indexes[nest_level - 1] = 0
+                new_stride = cpython.PyList_New(dims[nest_level - 1])
+                strides[nest_level - 1] = \
+                    <void*>(<cpython.PyObject>new_stride)
+
+                if nest_level > 1:
+                    cpython.Py_INCREF(new_stride)
+                    cpython.PyList_SET_ITEM(
+                        <object><cpython.PyObject*>strides[nest_level - 2],
+                        indexes[nest_level - 2],
+                        new_stride)
+                else:
+                    result = new_stride
+
+            elif ptr[0] == '}':
+                if item_level == 0:
+                    # Make sure we keep track of which nesting
+                    # level the item belongs to, as the loop
+                    # will continue to consume closing braces
+                    # until the delimiter or the end of input.
+                    item_level = nest_level
+
+                nest_level -= 1
+
+                if nest_level == 0:
+                    end_of_array = end_of_item = True
+
+            elif ptr[0] == typdelim:
+                # Array element delimiter,
+                end_of_item = True
+                if item_level == 0:
+                    item_level = nest_level
+
+            elif apg_ascii_isspace(ptr[0]):
+                if not strip_spaces:
+                    item_ptr[0] = ptr[0]
+                    item_ptr += 1
+                # Ignore the leading literal whitespace.
+
+            else:
+                item_ptr[0] = ptr[0]
+                item_ptr += 1
+                strip_spaces = False
+                item_end = item_ptr
+
+            ptr += 1
+
+        # end while not end_of_item
+
+        if item_end == item_start:
+            # Empty array
+            continue
+
+        item_end[0] = '\0'
+
+        if not has_quoting and apg_strcasecmp(item_start, APG_NULL) == 0:
+            # NULL element.
+            item = None
+        else:
+            # XXX: find a way to avoid the redundant encode/decode
+            # cycle here.
+            item_text = cpythonx.PyUnicode_FromKindAndData(
+                cpythonx.PyUnicode_4BYTE_KIND,
+                <void *>item_start,
+                item_end - item_start)
+
+            # Prepare the element buffer and call the text decoder
+            # for the element type.
+            pgproto.as_pg_string_and_size(
+                settings, item_text, &pg_item_str, &pg_item_len)
+            frb_init(&item_buf, pg_item_str, pg_item_len)
+            item = decoder(settings, &item_buf, decoder_arg)
+
+        # Place the decoded element in the array.
+        cpython.Py_INCREF(item)
+        cpython.PyList_SET_ITEM(
+            <object><cpython.PyObject*>strides[item_level - 1],
+            indexes[item_level - 1],
+            item)
+
+        if nest_level > 0:
+            indexes[nest_level - 1] += 1
+
+    return result
+
+
+cdef enum _ArrayParseState:
+    APS_START = 1
+    APS_STRIDE_STARTED = 2
+    APS_STRIDE_DONE = 3
+    APS_STRIDE_DELIMITED = 4
+    APS_ELEM_STARTED = 5
+    APS_ELEM_DELIMITED = 6
+
+
+cdef _UnexpectedCharacter(const Py_UCS4 *array_text, const Py_UCS4 *ptr):
+    return ValueError('unexpected character {!r} at position {}'.format(
+        cpython.PyUnicode_FromOrdinal(<int>ptr[0]), ptr - array_text + 1))
+
+
+cdef _infer_array_dims(const Py_UCS4 *array_text,
+                       Py_UCS4 typdelim,
+                       int32_t *dims,
+                       int32_t *ndims):
+    cdef:
+        const Py_UCS4 *ptr = array_text
+        int i
+        int nest_level = 0
+        bint end_of_array = False
+        bint end_of_item = False
+        bint in_quotes = False
+        bint array_is_empty = True
+        int stride_len[ARRAY_MAXDIM]
+        int prev_stride_len[ARRAY_MAXDIM]
+        _ArrayParseState parse_state = APS_START
+
+    for i in range(ARRAY_MAXDIM):
+        dims[i] = prev_stride_len[i] = 0
+        stride_len[i] = 1
+
+    while not end_of_array:
+        end_of_item = False
+
+        while not end_of_item:
+            if ptr[0] == '\0':
+                raise ValueError('unexpected end of string')
+
+            elif ptr[0] == '"':
+                if (parse_state not in (APS_STRIDE_STARTED,
+                                        APS_ELEM_DELIMITED) and
+                        not (parse_state == APS_ELEM_STARTED and in_quotes)):
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                in_quotes = not in_quotes
+                if in_quotes:
+                    parse_state = APS_ELEM_STARTED
+                    array_is_empty = False
+
+            elif ptr[0] == '\\':
+                if parse_state not in (APS_STRIDE_STARTED,
+                                       APS_ELEM_STARTED,
+                                       APS_ELEM_DELIMITED):
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                parse_state = APS_ELEM_STARTED
+                array_is_empty = False
+
+                if ptr[1] != '\0':
+                    ptr += 1
+                else:
+                    raise ValueError('unexpected end of string')
+
+            elif in_quotes:
+                # Ignore everything inside the quotes.
+                pass
+
+            elif ptr[0] == '{':
+                if parse_state not in (APS_START,
+                                       APS_STRIDE_STARTED,
+                                       APS_STRIDE_DELIMITED):
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                parse_state = APS_STRIDE_STARTED
+                if nest_level >= ARRAY_MAXDIM:
+                    raise ValueError(
+                        'number of array dimensions ({}) exceed the '
+                        'maximum expected ({})'.format(
+                            nest_level, ARRAY_MAXDIM))
+
+                dims[nest_level] = 0
+                nest_level += 1
+                if ndims[0] < nest_level:
+                    ndims[0] = nest_level
+
+            elif ptr[0] == '}':
+                if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and
+                        not (nest_level == 1 and
+                             parse_state == APS_STRIDE_STARTED)):
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                parse_state = APS_STRIDE_DONE
+
+                if nest_level == 0:
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                nest_level -= 1
+
+                if (prev_stride_len[nest_level] != 0 and
+                        stride_len[nest_level] != prev_stride_len[nest_level]):
+                    raise ValueError(
+                        'inconsistent sub-array dimensions'
+                        ' at position {}'.format(
+                            ptr - array_text + 1))
+
+                prev_stride_len[nest_level] = stride_len[nest_level]
+                stride_len[nest_level] = 1
+                if nest_level == 0:
+                    end_of_array = end_of_item = True
+                else:
+                    dims[nest_level - 1] += 1
+
+            elif ptr[0] == typdelim:
+                if parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE):
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                if parse_state == APS_STRIDE_DONE:
+                    parse_state = APS_STRIDE_DELIMITED
+                else:
+                    parse_state = APS_ELEM_DELIMITED
+                end_of_item = True
+                stride_len[nest_level - 1] += 1
+
+            elif not apg_ascii_isspace(ptr[0]):
+                if parse_state not in (APS_STRIDE_STARTED,
+                                       APS_ELEM_STARTED,
+                                       APS_ELEM_DELIMITED):
+                    raise _UnexpectedCharacter(array_text, ptr)
+
+                parse_state = APS_ELEM_STARTED
+                array_is_empty = False
+
+            if not end_of_item:
+                ptr += 1
+
+        if not array_is_empty:
+            dims[ndims[0] - 1] += 1
+
+        ptr += 1
+
+    # only whitespace is allowed after the closing brace
+    while ptr[0] != '\0':
+        if not apg_ascii_isspace(ptr[0]):
+            raise _UnexpectedCharacter(array_text, ptr)
+
+        ptr += 1
+
+    if array_is_empty:
+        ndims[0] = 0
+
+
+cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,
+                     const void *arg):
+    return pgproto.uint4_encode(settings, buf, obj)
+
+
+cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf,
+                     const void *arg):
+    return pgproto.uint4_decode(settings, buf)
+
+
+cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items):
+    array_encode(settings, buf, items, OIDOID,
+                 <encode_func_ex>&uint4_encode_ex, NULL)
+
+
+cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf):
+    return array_decode(settings, buf, <decode_func_ex>&uint4_decode_ex, NULL)
+
+
+cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,
+                    const void *arg):
+    return pgproto.text_encode(settings, buf, obj)
+
+
+cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf,
+                    const void *arg):
+    return pgproto.text_decode(settings, buf)
+
+
+cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items):
+    array_encode(settings, buf, items, TEXTOID,
+                 <encode_func_ex>&text_encode_ex, NULL)
+
+
+cdef arraytext_decode(ConnectionSettings settings, FRBuffer *buf):
+    return array_decode(settings, buf, <decode_func_ex>&text_decode_ex, NULL)
+
+
+cdef anyarray_decode(ConnectionSettings settings, FRBuffer *buf):
+    # Instances of anyarray (or any other polymorphic pseudotype) are
+    # never supposed to be returned from actual queries.
+    raise exceptions.ProtocolError(
+        'unexpected instance of \'anyarray\' type')
+
+
+cdef init_array_codecs():
+    register_core_codec(ANYARRAYOID,
+                        NULL,
+                        <decode_func>&anyarray_decode,
+                        PG_FORMAT_BINARY)
+
+    # oid[] and text[] are registered as core codecs
+    # to make type introspection query work
+    #
+    register_core_codec(_OIDOID,
+                        <encode_func>&arrayoid_encode,
+                        <decode_func>&arrayoid_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(_TEXTOID,
+                        <encode_func>&arraytext_encode,
+                        <decode_func>&arraytext_decode,
+                        PG_FORMAT_BINARY)
+
+init_array_codecs()
diff --git a/asyncpg/protocol/codecs/base.pxd b/asyncpg/protocol/codecs/base.pxd
new file mode 100644 (file)
index 0000000..be1f0a3
--- /dev/null
@@ -0,0 +1,170 @@
+# 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
+
+
+ctypedef object (*encode_func)(ConnectionSettings settings,
+                               WriteBuffer buf,
+                               object obj)
+
+ctypedef object (*decode_func)(ConnectionSettings settings,
+                               FRBuffer *buf)
+
+ctypedef object (*codec_encode_func)(Codec codec,
+                                     ConnectionSettings settings,
+                                     WriteBuffer buf,
+                                     object obj)
+
+ctypedef object (*codec_decode_func)(Codec codec,
+                                     ConnectionSettings settings,
+                                     FRBuffer *buf)
+
+
+cdef enum CodecType:
+    CODEC_UNDEFINED = 0
+    CODEC_C         = 1
+    CODEC_PY        = 2
+    CODEC_ARRAY     = 3
+    CODEC_COMPOSITE = 4
+    CODEC_RANGE     = 5
+
+
+cdef enum ServerDataFormat:
+    PG_FORMAT_ANY = -1
+    PG_FORMAT_TEXT = 0
+    PG_FORMAT_BINARY = 1
+
+
+cdef enum ClientExchangeFormat:
+    PG_XFORMAT_OBJECT = 1
+    PG_XFORMAT_TUPLE = 2
+
+
+cdef class Codec:
+    cdef:
+        uint32_t        oid
+
+        str             name
+        str             schema
+        str             kind
+
+        CodecType       type
+        ServerDataFormat format
+        ClientExchangeFormat xformat
+
+        encode_func     c_encoder
+        decode_func     c_decoder
+
+        object          py_encoder
+        object          py_decoder
+
+        # arrays
+        Codec           element_codec
+        Py_UCS4         element_delimiter
+
+        # composite types
+        tuple           element_type_oids
+        object          element_names
+        object          record_desc
+        list            element_codecs
+
+        # Pointers to actual encoder/decoder functions for this codec
+        codec_encode_func encoder
+        codec_decode_func decoder
+
+    cdef init(self, str name, str schema, str kind,
+              CodecType type, ServerDataFormat format,
+              ClientExchangeFormat xformat,
+              encode_func c_encoder, decode_func c_decoder,
+              object py_encoder, object py_decoder,
+              Codec element_codec, tuple element_type_oids,
+              object element_names, list element_codecs,
+              Py_UCS4 element_delimiter)
+
+    cdef encode_scalar(self, ConnectionSettings settings, WriteBuffer buf,
+                       object obj)
+
+    cdef encode_array(self, ConnectionSettings settings, WriteBuffer buf,
+                      object obj)
+
+    cdef encode_array_text(self, ConnectionSettings settings, WriteBuffer buf,
+                           object obj)
+
+    cdef encode_range(self, ConnectionSettings settings, WriteBuffer buf,
+                      object obj)
+
+    cdef encode_composite(self, ConnectionSettings settings, WriteBuffer buf,
+                          object obj)
+
+    cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf,
+                          object obj)
+
+    cdef decode_scalar(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef decode_array_text(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef decode_composite(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef decode_in_python(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef inline encode(self,
+                       ConnectionSettings settings,
+                       WriteBuffer buf,
+                       object obj)
+
+    cdef inline decode(self, ConnectionSettings settings, FRBuffer *buf)
+
+    cdef has_encoder(self)
+    cdef has_decoder(self)
+    cdef is_binary(self)
+
+    cdef inline Codec copy(self)
+
+    @staticmethod
+    cdef Codec new_array_codec(uint32_t oid,
+                               str name,
+                               str schema,
+                               Codec element_codec,
+                               Py_UCS4 element_delimiter)
+
+    @staticmethod
+    cdef Codec new_range_codec(uint32_t oid,
+                               str name,
+                               str schema,
+                               Codec element_codec)
+
+    @staticmethod
+    cdef Codec new_composite_codec(uint32_t oid,
+                                   str name,
+                                   str schema,
+                                   ServerDataFormat format,
+                                   list element_codecs,
+                                   tuple element_type_oids,
+                                   object element_names)
+
+    @staticmethod
+    cdef Codec new_python_codec(uint32_t oid,
+                                str name,
+                                str schema,
+                                str kind,
+                                object encoder,
+                                object decoder,
+                                encode_func c_encoder,
+                                decode_func c_decoder,
+                                ServerDataFormat format,
+                                ClientExchangeFormat xformat)
+
+
+cdef class DataCodecConfig:
+    cdef:
+        dict _derived_type_codecs
+        dict _custom_type_codecs
+
+    cdef inline Codec get_codec(self, uint32_t oid, ServerDataFormat format)
+    cdef inline Codec get_any_local_codec(self, uint32_t oid)
diff --git a/asyncpg/protocol/codecs/base.pyx b/asyncpg/protocol/codecs/base.pyx
new file mode 100644 (file)
index 0000000..5d3ccc4
--- /dev/null
@@ -0,0 +1,816 @@
+# 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
+
+
+from collections.abc import Mapping as MappingABC
+
+from asyncpg import exceptions
+
+
+cdef void* binary_codec_map[(MAXSUPPORTEDOID + 1) * 2]
+cdef void* text_codec_map[(MAXSUPPORTEDOID + 1) * 2]
+cdef dict EXTRA_CODECS = {}
+
+
+@cython.final
+cdef class Codec:
+
+    def __cinit__(self, uint32_t oid):
+        self.oid = oid
+        self.type = CODEC_UNDEFINED
+
+    cdef init(self, str name, str schema, str kind,
+              CodecType type, ServerDataFormat format,
+              ClientExchangeFormat xformat,
+              encode_func c_encoder, decode_func c_decoder,
+              object py_encoder, object py_decoder,
+              Codec element_codec, tuple element_type_oids,
+              object element_names, list element_codecs,
+              Py_UCS4 element_delimiter):
+
+        self.name = name
+        self.schema = schema
+        self.kind = kind
+        self.type = type
+        self.format = format
+        self.xformat = xformat
+        self.c_encoder = c_encoder
+        self.c_decoder = c_decoder
+        self.py_encoder = py_encoder
+        self.py_decoder = py_decoder
+        self.element_codec = element_codec
+        self.element_type_oids = element_type_oids
+        self.element_codecs = element_codecs
+        self.element_delimiter = element_delimiter
+        self.element_names = element_names
+
+        if element_names is not None:
+            self.record_desc = record.ApgRecordDesc_New(
+                element_names, tuple(element_names))
+        else:
+            self.record_desc = None
+
+        if type == CODEC_C:
+            self.encoder = <codec_encode_func>&self.encode_scalar
+            self.decoder = <codec_decode_func>&self.decode_scalar
+        elif type == CODEC_ARRAY:
+            if format == PG_FORMAT_BINARY:
+                self.encoder = <codec_encode_func>&self.encode_array
+                self.decoder = <codec_decode_func>&self.decode_array
+            else:
+                self.encoder = <codec_encode_func>&self.encode_array_text
+                self.decoder = <codec_decode_func>&self.decode_array_text
+        elif type == CODEC_RANGE:
+            if format != PG_FORMAT_BINARY:
+                raise NotImplementedError(
+                    'cannot decode type "{}"."{}": text encoding of '
+                    'range types is not supported'.format(schema, name))
+            self.encoder = <codec_encode_func>&self.encode_range
+            self.decoder = <codec_decode_func>&self.decode_range
+        elif type == CODEC_COMPOSITE:
+            if format != PG_FORMAT_BINARY:
+                raise NotImplementedError(
+                    'cannot decode type "{}"."{}": text encoding of '
+                    'composite types is not supported'.format(schema, name))
+            self.encoder = <codec_encode_func>&self.encode_composite
+            self.decoder = <codec_decode_func>&self.decode_composite
+        elif type == CODEC_PY:
+            self.encoder = <codec_encode_func>&self.encode_in_python
+            self.decoder = <codec_decode_func>&self.decode_in_python
+        else:
+            raise exceptions.InternalClientError(
+                'unexpected codec type: {}'.format(type))
+
+    cdef Codec copy(self):
+        cdef Codec codec
+
+        codec = Codec(self.oid)
+        codec.init(self.name, self.schema, self.kind,
+                   self.type, self.format, self.xformat,
+                   self.c_encoder, self.c_decoder,
+                   self.py_encoder, self.py_decoder,
+                   self.element_codec,
+                   self.element_type_oids, self.element_names,
+                   self.element_codecs, self.element_delimiter)
+
+        return codec
+
+    cdef encode_scalar(self, ConnectionSettings settings, WriteBuffer buf,
+                       object obj):
+        self.c_encoder(settings, buf, obj)
+
+    cdef encode_array(self, ConnectionSettings settings, WriteBuffer buf,
+                      object obj):
+        array_encode(settings, buf, obj, self.element_codec.oid,
+                     codec_encode_func_ex,
+                     <void*>(<cpython.PyObject>self.element_codec))
+
+    cdef encode_array_text(self, ConnectionSettings settings, WriteBuffer buf,
+                           object obj):
+        return textarray_encode(settings, buf, obj,
+                                codec_encode_func_ex,
+                                <void*>(<cpython.PyObject>self.element_codec),
+                                self.element_delimiter)
+
+    cdef encode_range(self, ConnectionSettings settings, WriteBuffer buf,
+                      object obj):
+        range_encode(settings, buf, obj, self.element_codec.oid,
+                     codec_encode_func_ex,
+                     <void*>(<cpython.PyObject>self.element_codec))
+
+    cdef encode_composite(self, ConnectionSettings settings, WriteBuffer buf,
+                          object obj):
+        cdef:
+            WriteBuffer elem_data
+            int i
+            list elem_codecs = self.element_codecs
+            ssize_t count
+            ssize_t composite_size
+            tuple rec
+
+        if isinstance(obj, MappingABC):
+            # Input is dict-like, form a tuple
+            composite_size = len(self.element_type_oids)
+            rec = cpython.PyTuple_New(composite_size)
+
+            for i in range(composite_size):
+                cpython.Py_INCREF(None)
+                cpython.PyTuple_SET_ITEM(rec, i, None)
+
+            for field in obj:
+                try:
+                    i = self.element_names[field]
+                except KeyError:
+                    raise ValueError(
+                        '{!r} is not a valid element of composite '
+                        'type {}'.format(field, self.name)) from None
+
+                item = obj[field]
+                cpython.Py_INCREF(item)
+                cpython.PyTuple_SET_ITEM(rec, i, item)
+
+            obj = rec
+
+        count = len(obj)
+        if count > _MAXINT32:
+            raise ValueError('too many elements in composite type record')
+
+        elem_data = WriteBuffer.new()
+        i = 0
+        for item in obj:
+            elem_data.write_int32(<int32_t>self.element_type_oids[i])
+            if item is None:
+                elem_data.write_int32(-1)
+            else:
+                (<Codec>elem_codecs[i]).encode(settings, elem_data, item)
+            i += 1
+
+        record_encode_frame(settings, buf, elem_data, <int32_t>count)
+
+    cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf,
+                          object obj):
+        data = self.py_encoder(obj)
+        if self.xformat == PG_XFORMAT_OBJECT:
+            if self.format == PG_FORMAT_BINARY:
+                pgproto.bytea_encode(settings, buf, data)
+            elif self.format == PG_FORMAT_TEXT:
+                pgproto.text_encode(settings, buf, data)
+            else:
+                raise exceptions.InternalClientError(
+                    'unexpected data format: {}'.format(self.format))
+        elif self.xformat == PG_XFORMAT_TUPLE:
+            self.c_encoder(settings, buf, data)
+        else:
+            raise exceptions.InternalClientError(
+                'unexpected exchange format: {}'.format(self.xformat))
+
+    cdef encode(self, ConnectionSettings settings, WriteBuffer buf,
+                object obj):
+        return self.encoder(self, settings, buf, obj)
+
+    cdef decode_scalar(self, ConnectionSettings settings, FRBuffer *buf):
+        return self.c_decoder(settings, buf)
+
+    cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf):
+        return array_decode(settings, buf, codec_decode_func_ex,
+                            <void*>(<cpython.PyObject>self.element_codec))
+
+    cdef decode_array_text(self, ConnectionSettings settings,
+                           FRBuffer *buf):
+        return textarray_decode(settings, buf, codec_decode_func_ex,
+                                <void*>(<cpython.PyObject>self.element_codec),
+                                self.element_delimiter)
+
+    cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf):
+        return range_decode(settings, buf, codec_decode_func_ex,
+                            <void*>(<cpython.PyObject>self.element_codec))
+
+    cdef decode_composite(self, ConnectionSettings settings,
+                          FRBuffer *buf):
+        cdef:
+            object result
+            ssize_t elem_count
+            ssize_t i
+            int32_t elem_len
+            uint32_t elem_typ
+            uint32_t received_elem_typ
+            Codec elem_codec
+            FRBuffer elem_buf
+
+        elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+        if elem_count != len(self.element_type_oids):
+            raise exceptions.OutdatedSchemaCacheError(
+                'unexpected number of attributes of composite type: '
+                '{}, expected {}'
+                    .format(
+                        elem_count,
+                        len(self.element_type_oids),
+                    ),
+                schema=self.schema,
+                data_type=self.name,
+            )
+        result = record.ApgRecord_New(self.record_desc, elem_count)
+        for i in range(elem_count):
+            elem_typ = self.element_type_oids[i]
+            received_elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+
+            if received_elem_typ != elem_typ:
+                raise exceptions.OutdatedSchemaCacheError(
+                    'unexpected data type of composite type attribute {}: '
+                    '{!r}, expected {!r}'
+                        .format(
+                            i,
+                            BUILTIN_TYPE_OID_MAP.get(
+                                received_elem_typ, received_elem_typ),
+                            BUILTIN_TYPE_OID_MAP.get(
+                                elem_typ, elem_typ)
+                        ),
+                    schema=self.schema,
+                    data_type=self.name,
+                    position=i,
+                )
+
+            elem_len = hton.unpack_int32(frb_read(buf, 4))
+            if elem_len == -1:
+                elem = None
+            else:
+                elem_codec = self.element_codecs[i]
+                elem = elem_codec.decode(
+                    settings, frb_slice_from(&elem_buf, buf, elem_len))
+
+            cpython.Py_INCREF(elem)
+            record.ApgRecord_SET_ITEM(result, i, elem)
+
+        return result
+
+    cdef decode_in_python(self, ConnectionSettings settings,
+                          FRBuffer *buf):
+        if self.xformat == PG_XFORMAT_OBJECT:
+            if self.format == PG_FORMAT_BINARY:
+                data = pgproto.bytea_decode(settings, buf)
+            elif self.format == PG_FORMAT_TEXT:
+                data = pgproto.text_decode(settings, buf)
+            else:
+                raise exceptions.InternalClientError(
+                    'unexpected data format: {}'.format(self.format))
+        elif self.xformat == PG_XFORMAT_TUPLE:
+            data = self.c_decoder(settings, buf)
+        else:
+            raise exceptions.InternalClientError(
+                'unexpected exchange format: {}'.format(self.xformat))
+
+        return self.py_decoder(data)
+
+    cdef inline decode(self, ConnectionSettings settings, FRBuffer *buf):
+        return self.decoder(self, settings, buf)
+
+    cdef inline has_encoder(self):
+        cdef Codec elem_codec
+
+        if self.c_encoder is not NULL or self.py_encoder is not None:
+            return True
+
+        elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:
+            return self.element_codec.has_encoder()
+
+        elif self.type == CODEC_COMPOSITE:
+            for elem_codec in self.element_codecs:
+                if not elem_codec.has_encoder():
+                    return False
+            return True
+
+        else:
+            return False
+
+    cdef has_decoder(self):
+        cdef Codec elem_codec
+
+        if self.c_decoder is not NULL or self.py_decoder is not None:
+            return True
+
+        elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:
+            return self.element_codec.has_decoder()
+
+        elif self.type == CODEC_COMPOSITE:
+            for elem_codec in self.element_codecs:
+                if not elem_codec.has_decoder():
+                    return False
+            return True
+
+        else:
+            return False
+
+    cdef is_binary(self):
+        return self.format == PG_FORMAT_BINARY
+
+    def __repr__(self):
+        return '<Codec oid={} elem_oid={} core={}>'.format(
+            self.oid,
+            'NA' if self.element_codec is None else self.element_codec.oid,
+            has_core_codec(self.oid))
+
+    @staticmethod
+    cdef Codec new_array_codec(uint32_t oid,
+                               str name,
+                               str schema,
+                               Codec element_codec,
+                               Py_UCS4 element_delimiter):
+        cdef Codec codec
+        codec = Codec(oid)
+        codec.init(name, schema, 'array', CODEC_ARRAY, element_codec.format,
+                   PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+                   None, None, None, element_delimiter)
+        return codec
+
+    @staticmethod
+    cdef Codec new_range_codec(uint32_t oid,
+                               str name,
+                               str schema,
+                               Codec element_codec):
+        cdef Codec codec
+        codec = Codec(oid)
+        codec.init(name, schema, 'range', CODEC_RANGE, element_codec.format,
+                   PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+                   None, None, None, 0)
+        return codec
+
+    @staticmethod
+    cdef Codec new_composite_codec(uint32_t oid,
+                                   str name,
+                                   str schema,
+                                   ServerDataFormat format,
+                                   list element_codecs,
+                                   tuple element_type_oids,
+                                   object element_names):
+        cdef Codec codec
+        codec = Codec(oid)
+        codec.init(name, schema, 'composite', CODEC_COMPOSITE,
+                   format, PG_XFORMAT_OBJECT, NULL, NULL, None, None, None,
+                   element_type_oids, element_names, element_codecs, 0)
+        return codec
+
+    @staticmethod
+    cdef Codec new_python_codec(uint32_t oid,
+                                str name,
+                                str schema,
+                                str kind,
+                                object encoder,
+                                object decoder,
+                                encode_func c_encoder,
+                                decode_func c_decoder,
+                                ServerDataFormat format,
+                                ClientExchangeFormat xformat):
+        cdef Codec codec
+        codec = Codec(oid)
+        codec.init(name, schema, kind, CODEC_PY, format, xformat,
+                   c_encoder, c_decoder, encoder, decoder,
+                   None, None, None, None, 0)
+        return codec
+
+
+# Encode callback for arrays
+cdef codec_encode_func_ex(ConnectionSettings settings, WriteBuffer buf,
+                          object obj, const void *arg):
+    return (<Codec>arg).encode(settings, buf, obj)
+
+
+# Decode callback for arrays
+cdef codec_decode_func_ex(ConnectionSettings settings, FRBuffer *buf,
+                          const void *arg):
+    return (<Codec>arg).decode(settings, buf)
+
+
+cdef uint32_t pylong_as_oid(val) except? 0xFFFFFFFFl:
+    cdef:
+        int64_t oid = 0
+        bint overflow = False
+
+    try:
+        oid = cpython.PyLong_AsLongLong(val)
+    except OverflowError:
+        overflow = True
+
+    if overflow or (oid < 0 or oid > UINT32_MAX):
+        raise OverflowError('OID value too large: {!r}'.format(val))
+
+    return <uint32_t>val
+
+
+cdef class DataCodecConfig:
+    def __init__(self, cache_key):
+        # Codec instance cache for derived types:
+        # composites, arrays, ranges, domains and their combinations.
+        self._derived_type_codecs = {}
+        # Codec instances set up by the user for the connection.
+        self._custom_type_codecs = {}
+
+    def add_types(self, types):
+        cdef:
+            Codec elem_codec
+            list comp_elem_codecs
+            ServerDataFormat format
+            ServerDataFormat elem_format
+            bint has_text_elements
+            Py_UCS4 elem_delim
+
+        for ti in types:
+            oid = ti['oid']
+
+            if not ti['has_bin_io']:
+                format = PG_FORMAT_TEXT
+            else:
+                format = PG_FORMAT_BINARY
+
+            has_text_elements = False
+
+            if self.get_codec(oid, format) is not None:
+                continue
+
+            name = ti['name']
+            schema = ti['ns']
+            array_element_oid = ti['elemtype']
+            range_subtype_oid = ti['range_subtype']
+            if ti['attrtypoids']:
+                comp_type_attrs = tuple(ti['attrtypoids'])
+            else:
+                comp_type_attrs = None
+            base_type = ti['basetype']
+
+            if array_element_oid:
+                # Array type (note, there is no separate 'kind' for arrays)
+
+                # Canonicalize type name to "elemtype[]"
+                if name.startswith('_'):
+                    name = name[1:]
+                name = '{}[]'.format(name)
+
+                if ti['elem_has_bin_io']:
+                    elem_format = PG_FORMAT_BINARY
+                else:
+                    elem_format = PG_FORMAT_TEXT
+
+                elem_codec = self.get_codec(array_element_oid, elem_format)
+                if elem_codec is None:
+                    elem_format = PG_FORMAT_TEXT
+                    elem_codec = self.declare_fallback_codec(
+                        array_element_oid, name, schema)
+
+                elem_delim = <Py_UCS4>ti['elemdelim'][0]
+
+                self._derived_type_codecs[oid, elem_format] = \
+                    Codec.new_array_codec(
+                        oid, name, schema, elem_codec, elem_delim)
+
+            elif ti['kind'] == b'c':
+                if not comp_type_attrs:
+                    raise exceptions.InternalClientError(
+                        'type record missing field types for '
+                        'composite {}'.format(oid))
+
+                # Composite type
+
+                comp_elem_codecs = []
+
+                for typoid in comp_type_attrs:
+                    elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)
+                    if elem_codec is None:
+                        elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+                        has_text_elements = True
+                    if elem_codec is None:
+                        raise exceptions.InternalClientError(
+                            'no codec for composite attribute type {}'.format(
+                                typoid))
+                    comp_elem_codecs.append(elem_codec)
+
+                element_names = collections.OrderedDict()
+                for i, attrname in enumerate(ti['attrnames']):
+                    element_names[attrname] = i
+
+                if has_text_elements:
+                    format = PG_FORMAT_TEXT
+
+                self._derived_type_codecs[oid, format] = \
+                    Codec.new_composite_codec(
+                        oid, name, schema, format, comp_elem_codecs,
+                        comp_type_attrs, element_names)
+
+            elif ti['kind'] == b'd':
+                # Domain type
+
+                if not base_type:
+                    raise exceptions.InternalClientError(
+                        'type record missing base type for domain {}'.format(
+                            oid))
+
+                elem_codec = self.get_codec(base_type, format)
+                if elem_codec is None:
+                    format = PG_FORMAT_TEXT
+                    elem_codec = self.declare_fallback_codec(
+                        base_type, name, schema)
+
+                self._derived_type_codecs[oid, format] = elem_codec
+
+            elif ti['kind'] == b'r':
+                # Range type
+
+                if not range_subtype_oid:
+                    raise exceptions.InternalClientError(
+                        'type record missing base type for range {}'.format(
+                            oid))
+
+                if ti['elem_has_bin_io']:
+                    elem_format = PG_FORMAT_BINARY
+                else:
+                    elem_format = PG_FORMAT_TEXT
+
+                elem_codec = self.get_codec(range_subtype_oid, elem_format)
+                if elem_codec is None:
+                    elem_format = PG_FORMAT_TEXT
+                    elem_codec = self.declare_fallback_codec(
+                        range_subtype_oid, name, schema)
+
+                self._derived_type_codecs[oid, elem_format] = \
+                    Codec.new_range_codec(oid, name, schema, elem_codec)
+
+            elif ti['kind'] == b'e':
+                # Enum types are essentially text
+                self._set_builtin_type_codec(oid, name, schema, 'scalar',
+                                             TEXTOID, PG_FORMAT_ANY)
+            else:
+                self.declare_fallback_codec(oid, name, schema)
+
+    def add_python_codec(self, typeoid, typename, typeschema, typekind,
+                         encoder, decoder, format, xformat):
+        cdef:
+            Codec core_codec
+            encode_func c_encoder = NULL
+            decode_func c_decoder = NULL
+            uint32_t oid = pylong_as_oid(typeoid)
+            bint codec_set = False
+
+        # Clear all previous overrides (this also clears type cache).
+        self.remove_python_codec(typeoid, typename, typeschema)
+
+        if format == PG_FORMAT_ANY:
+            formats = (PG_FORMAT_TEXT, PG_FORMAT_BINARY)
+        else:
+            formats = (format,)
+
+        for fmt in formats:
+            if xformat == PG_XFORMAT_TUPLE:
+                core_codec = get_core_codec(oid, fmt, xformat)
+                if core_codec is None:
+                    continue
+                c_encoder = core_codec.c_encoder
+                c_decoder = core_codec.c_decoder
+
+            self._custom_type_codecs[typeoid, fmt] = \
+                Codec.new_python_codec(oid, typename, typeschema, typekind,
+                                       encoder, decoder, c_encoder, c_decoder,
+                                       fmt, xformat)
+            codec_set = True
+
+        if not codec_set:
+            raise exceptions.InterfaceError(
+                "{} type does not support the 'tuple' exchange format".format(
+                    typename))
+
+    def remove_python_codec(self, typeoid, typename, typeschema):
+        for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):
+            self._custom_type_codecs.pop((typeoid, fmt), None)
+        self.clear_type_cache()
+
+    def _set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+                                alias_to, format=PG_FORMAT_ANY):
+        cdef:
+            Codec codec
+            Codec target_codec
+            uint32_t oid = pylong_as_oid(typeoid)
+            uint32_t alias_oid = 0
+            bint codec_set = False
+
+        if format == PG_FORMAT_ANY:
+            formats = (PG_FORMAT_BINARY, PG_FORMAT_TEXT)
+        else:
+            formats = (format,)
+
+        if isinstance(alias_to, int):
+            alias_oid = pylong_as_oid(alias_to)
+        else:
+            alias_oid = BUILTIN_TYPE_NAME_MAP.get(alias_to, 0)
+
+        for format in formats:
+            if alias_oid != 0:
+                target_codec = self.get_codec(alias_oid, format)
+            else:
+                target_codec = get_extra_codec(alias_to, format)
+
+            if target_codec is None:
+                continue
+
+            codec = target_codec.copy()
+            codec.oid = typeoid
+            codec.name = typename
+            codec.schema = typeschema
+            codec.kind = typekind
+
+            self._custom_type_codecs[typeoid, format] = codec
+            codec_set = True
+
+        if not codec_set:
+            if format == PG_FORMAT_BINARY:
+                codec_str = 'binary'
+            elif format == PG_FORMAT_TEXT:
+                codec_str = 'text'
+            else:
+                codec_str = 'text or binary'
+
+            raise exceptions.InterfaceError(
+                f'cannot alias {typename} to {alias_to}: '
+                f'there is no {codec_str} codec for {alias_to}')
+
+    def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+                               alias_to, format=PG_FORMAT_ANY):
+        self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,
+                                     alias_to, format)
+        self.clear_type_cache()
+
+    def clear_type_cache(self):
+        self._derived_type_codecs.clear()
+
+    def declare_fallback_codec(self, uint32_t oid, str name, str schema):
+        cdef Codec codec
+
+        codec = self.get_codec(oid, PG_FORMAT_TEXT)
+        if codec is not None:
+            return codec
+
+        if oid <= MAXBUILTINOID:
+            # This is a BKI type, for which asyncpg has no
+            # defined codec.  This should only happen for newly
+            # added builtin types, for which this version of
+            # asyncpg is lacking support.
+            #
+            raise NotImplementedError(
+                'unhandled standard data type {!r} (OID {})'.format(
+                    name, oid))
+        else:
+            # This is a non-BKI type, and as such, has no
+            # stable OID, so no possibility of a builtin codec.
+            # In this case, fallback to text format.  Applications
+            # can avoid this by specifying a codec for this type
+            # using Connection.set_type_codec().
+            #
+            self._set_builtin_type_codec(oid, name, schema, 'scalar',
+                                         TEXTOID, PG_FORMAT_TEXT)
+
+            codec = self.get_codec(oid, PG_FORMAT_TEXT)
+
+        return codec
+
+    cdef inline Codec get_codec(self, uint32_t oid, ServerDataFormat format):
+        cdef Codec codec
+
+        codec = self.get_any_local_codec(oid)
+        if codec is not None:
+            if codec.format != format:
+                # The codec for this OID has been overridden by
+                # set_{builtin}_type_codec with a different format.
+                # We must respect that and not return a core codec.
+                return None
+            else:
+                return codec
+
+        codec = get_core_codec(oid, format)
+        if codec is not None:
+            return codec
+        else:
+            try:
+                return self._derived_type_codecs[oid, format]
+            except KeyError:
+                return None
+
+    cdef inline Codec get_any_local_codec(self, uint32_t oid):
+        cdef Codec codec
+
+        codec = self._custom_type_codecs.get((oid, PG_FORMAT_BINARY))
+        if codec is None:
+            return self._custom_type_codecs.get((oid, PG_FORMAT_TEXT))
+        else:
+            return codec
+
+
+cdef inline Codec get_core_codec(
+        uint32_t oid, ServerDataFormat format,
+        ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+    cdef:
+        void *ptr = NULL
+
+    if oid > MAXSUPPORTEDOID:
+        return None
+    if format == PG_FORMAT_BINARY:
+        ptr = binary_codec_map[oid * xformat]
+    elif format == PG_FORMAT_TEXT:
+        ptr = text_codec_map[oid * xformat]
+
+    if ptr is NULL:
+        return None
+    else:
+        return <Codec>ptr
+
+
+cdef inline Codec get_any_core_codec(
+        uint32_t oid, ServerDataFormat format,
+        ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+    """A version of get_core_codec that accepts PG_FORMAT_ANY."""
+    cdef:
+        Codec codec
+
+    if format == PG_FORMAT_ANY:
+        codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)
+        if codec is None:
+            codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat)
+    else:
+        codec = get_core_codec(oid, format, xformat)
+
+    return codec
+
+
+cdef inline int has_core_codec(uint32_t oid):
+    return binary_codec_map[oid] != NULL or text_codec_map[oid] != NULL
+
+
+cdef register_core_codec(uint32_t oid,
+                         encode_func encode,
+                         decode_func decode,
+                         ServerDataFormat format,
+                         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+
+    if oid > MAXSUPPORTEDOID:
+        raise exceptions.InternalClientError(
+            'cannot register core codec for OID {}: it is greater '
+            'than MAXSUPPORTEDOID ({})'.format(oid, MAXSUPPORTEDOID))
+
+    cdef:
+        Codec codec
+        str name
+        str kind
+
+    name = BUILTIN_TYPE_OID_MAP[oid]
+    kind = 'array' if oid in ARRAY_TYPES else 'scalar'
+
+    codec = Codec(oid)
+    codec.init(name, 'pg_catalog', kind, CODEC_C, format, xformat,
+               encode, decode, None, None, None, None, None, None, 0)
+    cpython.Py_INCREF(codec)  # immortalize
+
+    if format == PG_FORMAT_BINARY:
+        binary_codec_map[oid * xformat] = <void*>codec
+    elif format == PG_FORMAT_TEXT:
+        text_codec_map[oid * xformat] = <void*>codec
+    else:
+        raise exceptions.InternalClientError(
+            'invalid data format: {}'.format(format))
+
+
+cdef register_extra_codec(str name,
+                          encode_func encode,
+                          decode_func decode,
+                          ServerDataFormat format):
+    cdef:
+        Codec codec
+        str kind
+
+    kind = 'scalar'
+
+    codec = Codec(INVALIDOID)
+    codec.init(name, None, kind, CODEC_C, format, PG_XFORMAT_OBJECT,
+               encode, decode, None, None, None, None, None, None, 0)
+    EXTRA_CODECS[name, format] = codec
+
+
+cdef inline Codec get_extra_codec(str name, ServerDataFormat format):
+    return EXTRA_CODECS.get((name, format))
diff --git a/asyncpg/protocol/codecs/pgproto.pyx b/asyncpg/protocol/codecs/pgproto.pyx
new file mode 100644 (file)
index 0000000..ea9c15a
--- /dev/null
@@ -0,0 +1,441 @@
+# 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 init_bits_codecs():
+    register_core_codec(BITOID,
+                        <encode_func>pgproto.bits_encode,
+                        <decode_func>pgproto.bits_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(VARBITOID,
+                        <encode_func>pgproto.bits_encode,
+                        <decode_func>pgproto.bits_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_bytea_codecs():
+    register_core_codec(BYTEAOID,
+                        <encode_func>pgproto.bytea_encode,
+                        <decode_func>pgproto.bytea_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(CHAROID,
+                        <encode_func>pgproto.bytea_encode,
+                        <decode_func>pgproto.bytea_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_datetime_codecs():
+    register_core_codec(DATEOID,
+                        <encode_func>pgproto.date_encode,
+                        <decode_func>pgproto.date_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(DATEOID,
+                        <encode_func>pgproto.date_encode_tuple,
+                        <decode_func>pgproto.date_decode_tuple,
+                        PG_FORMAT_BINARY,
+                        PG_XFORMAT_TUPLE)
+
+    register_core_codec(TIMEOID,
+                        <encode_func>pgproto.time_encode,
+                        <decode_func>pgproto.time_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(TIMEOID,
+                        <encode_func>pgproto.time_encode_tuple,
+                        <decode_func>pgproto.time_decode_tuple,
+                        PG_FORMAT_BINARY,
+                        PG_XFORMAT_TUPLE)
+
+    register_core_codec(TIMETZOID,
+                        <encode_func>pgproto.timetz_encode,
+                        <decode_func>pgproto.timetz_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(TIMETZOID,
+                        <encode_func>pgproto.timetz_encode_tuple,
+                        <decode_func>pgproto.timetz_decode_tuple,
+                        PG_FORMAT_BINARY,
+                        PG_XFORMAT_TUPLE)
+
+    register_core_codec(TIMESTAMPOID,
+                        <encode_func>pgproto.timestamp_encode,
+                        <decode_func>pgproto.timestamp_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(TIMESTAMPOID,
+                        <encode_func>pgproto.timestamp_encode_tuple,
+                        <decode_func>pgproto.timestamp_decode_tuple,
+                        PG_FORMAT_BINARY,
+                        PG_XFORMAT_TUPLE)
+
+    register_core_codec(TIMESTAMPTZOID,
+                        <encode_func>pgproto.timestamptz_encode,
+                        <decode_func>pgproto.timestamptz_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(TIMESTAMPTZOID,
+                        <encode_func>pgproto.timestamp_encode_tuple,
+                        <decode_func>pgproto.timestamp_decode_tuple,
+                        PG_FORMAT_BINARY,
+                        PG_XFORMAT_TUPLE)
+
+    register_core_codec(INTERVALOID,
+                        <encode_func>pgproto.interval_encode,
+                        <decode_func>pgproto.interval_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(INTERVALOID,
+                        <encode_func>pgproto.interval_encode_tuple,
+                        <decode_func>pgproto.interval_decode_tuple,
+                        PG_FORMAT_BINARY,
+                        PG_XFORMAT_TUPLE)
+
+    # For obsolete abstime/reltime/tinterval, we do not bother to
+    # interpret the value, and simply return and pass it as text.
+    #
+    register_core_codec(ABSTIMEOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    register_core_codec(RELTIMEOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    register_core_codec(TINTERVALOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+
+cdef init_float_codecs():
+    register_core_codec(FLOAT4OID,
+                        <encode_func>pgproto.float4_encode,
+                        <decode_func>pgproto.float4_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(FLOAT8OID,
+                        <encode_func>pgproto.float8_encode,
+                        <decode_func>pgproto.float8_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_geometry_codecs():
+    register_core_codec(BOXOID,
+                        <encode_func>pgproto.box_encode,
+                        <decode_func>pgproto.box_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(LINEOID,
+                        <encode_func>pgproto.line_encode,
+                        <decode_func>pgproto.line_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(LSEGOID,
+                        <encode_func>pgproto.lseg_encode,
+                        <decode_func>pgproto.lseg_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(POINTOID,
+                        <encode_func>pgproto.point_encode,
+                        <decode_func>pgproto.point_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(PATHOID,
+                        <encode_func>pgproto.path_encode,
+                        <decode_func>pgproto.path_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(POLYGONOID,
+                        <encode_func>pgproto.poly_encode,
+                        <decode_func>pgproto.poly_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(CIRCLEOID,
+                        <encode_func>pgproto.circle_encode,
+                        <decode_func>pgproto.circle_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_hstore_codecs():
+    register_extra_codec('pg_contrib.hstore',
+                         <encode_func>pgproto.hstore_encode,
+                         <decode_func>pgproto.hstore_decode,
+                         PG_FORMAT_BINARY)
+
+
+cdef init_json_codecs():
+    register_core_codec(JSONOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_BINARY)
+    register_core_codec(JSONBOID,
+                        <encode_func>pgproto.jsonb_encode,
+                        <decode_func>pgproto.jsonb_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_int_codecs():
+
+    register_core_codec(BOOLOID,
+                        <encode_func>pgproto.bool_encode,
+                        <decode_func>pgproto.bool_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(INT2OID,
+                        <encode_func>pgproto.int2_encode,
+                        <decode_func>pgproto.int2_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(INT4OID,
+                        <encode_func>pgproto.int4_encode,
+                        <decode_func>pgproto.int4_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(INT8OID,
+                        <encode_func>pgproto.int8_encode,
+                        <decode_func>pgproto.int8_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_pseudo_codecs():
+    # Void type is returned by SELECT void_returning_function()
+    register_core_codec(VOIDOID,
+                        <encode_func>pgproto.void_encode,
+                        <decode_func>pgproto.void_decode,
+                        PG_FORMAT_BINARY)
+
+    # Unknown type, always decoded as text
+    register_core_codec(UNKNOWNOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    # OID and friends
+    oid_types = [
+        OIDOID, XIDOID, CIDOID
+    ]
+
+    for oid_type in oid_types:
+        register_core_codec(oid_type,
+                            <encode_func>pgproto.uint4_encode,
+                            <decode_func>pgproto.uint4_decode,
+                            PG_FORMAT_BINARY)
+
+    # reg* types -- these are really system catalog OIDs, but
+    # allow the catalog object name as an input.  We could just
+    # decode these as OIDs, but handling them as text seems more
+    # useful.
+    #
+    reg_types = [
+        REGPROCOID, REGPROCEDUREOID, REGOPEROID, REGOPERATOROID,
+        REGCLASSOID, REGTYPEOID, REGCONFIGOID, REGDICTIONARYOID,
+        REGNAMESPACEOID, REGROLEOID, REFCURSOROID
+    ]
+
+    for reg_type in reg_types:
+        register_core_codec(reg_type,
+                            <encode_func>pgproto.text_encode,
+                            <decode_func>pgproto.text_decode,
+                            PG_FORMAT_TEXT)
+
+    # cstring type is used by Postgres' I/O functions
+    register_core_codec(CSTRINGOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_BINARY)
+
+    # various system pseudotypes with no I/O
+    no_io_types = [
+        ANYOID, TRIGGEROID, EVENT_TRIGGEROID, LANGUAGE_HANDLEROID,
+        FDW_HANDLEROID, TSM_HANDLEROID, INTERNALOID, OPAQUEOID,
+        ANYELEMENTOID, ANYNONARRAYOID, PG_DDL_COMMANDOID,
+        INDEX_AM_HANDLEROID,
+    ]
+
+    register_core_codec(ANYENUMOID,
+                        NULL,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    for no_io_type in no_io_types:
+        register_core_codec(no_io_type,
+                            NULL,
+                            NULL,
+                            PG_FORMAT_BINARY)
+
+    # ACL specification string
+    register_core_codec(ACLITEMOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    # Postgres' serialized expression tree type
+    register_core_codec(PG_NODE_TREEOID,
+                        NULL,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    # pg_lsn type -- a pointer to a location in the XLOG.
+    register_core_codec(PG_LSNOID,
+                        <encode_func>pgproto.int8_encode,
+                        <decode_func>pgproto.int8_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(SMGROID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    # pg_dependencies and pg_ndistinct are special types
+    # used in pg_statistic_ext columns.
+    register_core_codec(PG_DEPENDENCIESOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    register_core_codec(PG_NDISTINCTOID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+
+cdef init_text_codecs():
+    textoids = [
+        NAMEOID,
+        BPCHAROID,
+        VARCHAROID,
+        TEXTOID,
+        XMLOID
+    ]
+
+    for oid in textoids:
+        register_core_codec(oid,
+                            <encode_func>pgproto.text_encode,
+                            <decode_func>pgproto.text_decode,
+                            PG_FORMAT_BINARY)
+
+        register_core_codec(oid,
+                            <encode_func>pgproto.text_encode,
+                            <decode_func>pgproto.text_decode,
+                            PG_FORMAT_TEXT)
+
+
+cdef init_tid_codecs():
+    register_core_codec(TIDOID,
+                        <encode_func>pgproto.tid_encode,
+                        <decode_func>pgproto.tid_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_txid_codecs():
+    register_core_codec(TXID_SNAPSHOTOID,
+                        <encode_func>pgproto.txid_snapshot_encode,
+                        <decode_func>pgproto.txid_snapshot_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_tsearch_codecs():
+    ts_oids = [
+        TSQUERYOID,
+        TSVECTOROID,
+    ]
+
+    for oid in ts_oids:
+        register_core_codec(oid,
+                            <encode_func>pgproto.text_encode,
+                            <decode_func>pgproto.text_decode,
+                            PG_FORMAT_TEXT)
+
+    register_core_codec(GTSVECTOROID,
+                        NULL,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+
+cdef init_uuid_codecs():
+    register_core_codec(UUIDOID,
+                        <encode_func>pgproto.uuid_encode,
+                        <decode_func>pgproto.uuid_decode,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_numeric_codecs():
+    register_core_codec(NUMERICOID,
+                        <encode_func>pgproto.numeric_encode_text,
+                        <decode_func>pgproto.numeric_decode_text,
+                        PG_FORMAT_TEXT)
+
+    register_core_codec(NUMERICOID,
+                        <encode_func>pgproto.numeric_encode_binary,
+                        <decode_func>pgproto.numeric_decode_binary,
+                        PG_FORMAT_BINARY)
+
+
+cdef init_network_codecs():
+    register_core_codec(CIDROID,
+                        <encode_func>pgproto.cidr_encode,
+                        <decode_func>pgproto.net_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(INETOID,
+                        <encode_func>pgproto.inet_encode,
+                        <decode_func>pgproto.net_decode,
+                        PG_FORMAT_BINARY)
+
+    register_core_codec(MACADDROID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+    register_core_codec(MACADDR8OID,
+                        <encode_func>pgproto.text_encode,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+
+cdef init_monetary_codecs():
+    moneyoids = [
+        MONEYOID,
+    ]
+
+    for oid in moneyoids:
+        register_core_codec(oid,
+                            <encode_func>pgproto.text_encode,
+                            <decode_func>pgproto.text_decode,
+                            PG_FORMAT_TEXT)
+
+
+cdef init_all_pgproto_codecs():
+    # Builtin types, in lexicographical order.
+    init_bits_codecs()
+    init_bytea_codecs()
+    init_datetime_codecs()
+    init_float_codecs()
+    init_geometry_codecs()
+    init_int_codecs()
+    init_json_codecs()
+    init_monetary_codecs()
+    init_network_codecs()
+    init_numeric_codecs()
+    init_text_codecs()
+    init_tid_codecs()
+    init_tsearch_codecs()
+    init_txid_codecs()
+    init_uuid_codecs()
+
+    # Various pseudotypes and system types
+    init_pseudo_codecs()
+
+    # contrib
+    init_hstore_codecs()
+
+
+init_all_pgproto_codecs()
diff --git a/asyncpg/protocol/codecs/range.pyx b/asyncpg/protocol/codecs/range.pyx
new file mode 100644 (file)
index 0000000..2f598c1
--- /dev/null
@@ -0,0 +1,149 @@
+# 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
+
+
+from asyncpg import types as apg_types
+
+# defined in postgresql/src/include/utils/rangetypes.h
+DEF RANGE_EMPTY  = 0x01  # range is empty
+DEF RANGE_LB_INC = 0x02  # lower bound is inclusive
+DEF RANGE_UB_INC = 0x04  # upper bound is inclusive
+DEF RANGE_LB_INF = 0x08  # lower bound is -infinity
+DEF RANGE_UB_INF = 0x10  # upper bound is +infinity
+
+
+cdef enum _RangeArgumentType:
+    _RANGE_ARGUMENT_INVALID = 0
+    _RANGE_ARGUMENT_TUPLE = 1
+    _RANGE_ARGUMENT_RANGE = 2
+
+
+cdef inline bint _range_has_lbound(uint8_t flags):
+    return not (flags & (RANGE_EMPTY | RANGE_LB_INF))
+
+
+cdef inline bint _range_has_ubound(uint8_t flags):
+    return not (flags & (RANGE_EMPTY | RANGE_UB_INF))
+
+
+cdef inline _RangeArgumentType _range_type(object obj):
+    if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):
+        return _RANGE_ARGUMENT_TUPLE
+    elif isinstance(obj, apg_types.Range):
+        return _RANGE_ARGUMENT_RANGE
+    else:
+        return _RANGE_ARGUMENT_INVALID
+
+
+cdef range_encode(ConnectionSettings settings, WriteBuffer buf,
+                  object obj, uint32_t elem_oid,
+                  encode_func_ex encoder, const void *encoder_arg):
+    cdef:
+        ssize_t obj_len
+        uint8_t flags = 0
+        object lower = None
+        object upper = None
+        WriteBuffer bounds_data = WriteBuffer.new()
+        _RangeArgumentType arg_type = _range_type(obj)
+
+    if arg_type == _RANGE_ARGUMENT_INVALID:
+        raise TypeError(
+            'list, tuple or Range object expected (got type {})'.format(
+                type(obj)))
+
+    elif arg_type == _RANGE_ARGUMENT_TUPLE:
+        obj_len = len(obj)
+        if obj_len == 2:
+            lower = obj[0]
+            upper = obj[1]
+
+            if lower is None:
+                flags |= RANGE_LB_INF
+
+            if upper is None:
+                flags |= RANGE_UB_INF
+
+            flags |= RANGE_LB_INC | RANGE_UB_INC
+
+        elif obj_len == 1:
+            lower = obj[0]
+            flags |= RANGE_LB_INC | RANGE_UB_INF
+
+        elif obj_len == 0:
+            flags |= RANGE_EMPTY
+
+        else:
+            raise ValueError(
+                'expected 0, 1 or 2 elements in range (got {})'.format(
+                    obj_len))
+
+    else:
+        if obj.isempty:
+            flags |= RANGE_EMPTY
+        else:
+            lower = obj.lower
+            upper = obj.upper
+
+            if obj.lower_inc:
+                flags |= RANGE_LB_INC
+            elif lower is None:
+                flags |= RANGE_LB_INF
+
+            if obj.upper_inc:
+                flags |= RANGE_UB_INC
+            elif upper is None:
+                flags |= RANGE_UB_INF
+
+    if _range_has_lbound(flags):
+        encoder(settings, bounds_data, lower, encoder_arg)
+
+    if _range_has_ubound(flags):
+        encoder(settings, bounds_data, upper, encoder_arg)
+
+    buf.write_int32(1 + bounds_data.len())
+    buf.write_byte(<int8_t>flags)
+    buf.write_buffer(bounds_data)
+
+
+cdef range_decode(ConnectionSettings settings, FRBuffer *buf,
+                  decode_func_ex decoder, const void *decoder_arg):
+    cdef:
+        uint8_t flags = <uint8_t>frb_read(buf, 1)[0]
+        int32_t bound_len
+        object lower = None
+        object upper = None
+        FRBuffer bound_buf
+
+    if _range_has_lbound(flags):
+        bound_len = hton.unpack_int32(frb_read(buf, 4))
+        if bound_len == -1:
+            lower = None
+        else:
+            frb_slice_from(&bound_buf, buf, bound_len)
+            lower = decoder(settings, &bound_buf, decoder_arg)
+
+    if _range_has_ubound(flags):
+        bound_len = hton.unpack_int32(frb_read(buf, 4))
+        if bound_len == -1:
+            upper = None
+        else:
+            frb_slice_from(&bound_buf, buf, bound_len)
+            upper = decoder(settings, &bound_buf, decoder_arg)
+
+    return apg_types.Range(lower=lower, upper=upper,
+                           lower_inc=(flags & RANGE_LB_INC) != 0,
+                           upper_inc=(flags & RANGE_UB_INC) != 0,
+                           empty=(flags & RANGE_EMPTY) != 0)
+
+
+cdef init_range_codecs():
+    register_core_codec(ANYRANGEOID,
+                        NULL,
+                        <decode_func>pgproto.text_decode,
+                        PG_FORMAT_TEXT)
+
+
+init_range_codecs()
diff --git a/asyncpg/protocol/codecs/record.pyx b/asyncpg/protocol/codecs/record.pyx
new file mode 100644 (file)
index 0000000..5326a8c
--- /dev/null
@@ -0,0 +1,60 @@
+# 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
+
+
+from asyncpg import exceptions
+
+
+cdef inline record_encode_frame(ConnectionSettings settings, WriteBuffer buf,
+                                WriteBuffer elem_data, int32_t elem_count):
+    buf.write_int32(4 + elem_data.len())
+    # attribute count
+    buf.write_int32(elem_count)
+    # encoded attribute data
+    buf.write_buffer(elem_data)
+
+
+cdef anonymous_record_decode(ConnectionSettings settings, FRBuffer *buf):
+    cdef:
+        tuple result
+        ssize_t elem_count
+        ssize_t i
+        int32_t elem_len
+        uint32_t elem_typ
+        Codec elem_codec
+        FRBuffer elem_buf
+
+    elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+    result = cpython.PyTuple_New(elem_count)
+
+    for i in range(elem_count):
+        elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+        elem_len = hton.unpack_int32(frb_read(buf, 4))
+
+        if elem_len == -1:
+            elem = None
+        else:
+            elem_codec = settings.get_data_codec(elem_typ)
+            if elem_codec is None or not elem_codec.has_decoder():
+                raise exceptions.InternalClientError(
+                    'no decoder for composite type element in '
+                    'position {} of type OID {}'.format(i, elem_typ))
+            elem = elem_codec.decode(settings,
+                                     frb_slice_from(&elem_buf, buf, elem_len))
+
+        cpython.Py_INCREF(elem)
+        cpython.PyTuple_SET_ITEM(result, i, elem)
+
+    return result
+
+
+cdef init_record_codecs():
+    register_core_codec(RECORDOID,
+                        <encode_func>NULL,
+                        <decode_func>anonymous_record_decode,
+                        PG_FORMAT_BINARY)
+
+init_record_codecs()
diff --git a/asyncpg/protocol/codecs/textutils.pyx b/asyncpg/protocol/codecs/textutils.pyx
new file mode 100644 (file)
index 0000000..dfaf29e
--- /dev/null
@@ -0,0 +1,99 @@
+# 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 inline uint32_t _apg_tolower(uint32_t c):
+    if c >= <uint32_t><Py_UCS4>'A' and c <= <uint32_t><Py_UCS4>'Z':
+        return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'
+    else:
+        return c
+
+
+cdef int apg_strcasecmp(const Py_UCS4 *s1, const Py_UCS4 *s2):
+    cdef:
+        uint32_t c1
+        uint32_t c2
+        int i = 0
+
+    while True:
+        c1 = s1[i]
+        c2 = s2[i]
+
+        if c1 != c2:
+            c1 = _apg_tolower(c1)
+            c2 = _apg_tolower(c2)
+            if c1 != c2:
+                return <int32_t>c1 - <int32_t>c2
+
+        if c1 == 0 or c2 == 0:
+            break
+
+        i += 1
+
+    return 0
+
+
+cdef int apg_strcasecmp_char(const char *s1, const char *s2):
+    cdef:
+        uint8_t c1
+        uint8_t c2
+        int i = 0
+
+    while True:
+        c1 = <uint8_t>s1[i]
+        c2 = <uint8_t>s2[i]
+
+        if c1 != c2:
+            c1 = <uint8_t>_apg_tolower(c1)
+            c2 = <uint8_t>_apg_tolower(c2)
+            if c1 != c2:
+                return <int8_t>c1 - <int8_t>c2
+
+        if c1 == 0 or c2 == 0:
+            break
+
+        i += 1
+
+    return 0
+
+
+cdef inline bint apg_ascii_isspace(Py_UCS4 ch):
+    return (
+        ch == ' ' or
+        ch == '\n' or
+        ch == '\r' or
+        ch == '\t' or
+        ch == '\v' or
+        ch == '\f'
+    )
+
+
+cdef Py_UCS4 *apg_parse_int32(Py_UCS4 *buf, int32_t *num):
+    cdef:
+        Py_UCS4 *p
+        int32_t n = 0
+        int32_t neg = 0
+
+    if buf[0] == '-':
+        neg = 1
+        buf += 1
+    elif buf[0] == '+':
+        buf += 1
+
+    p = buf
+    while <int>p[0] >= <int><Py_UCS4>'0' and <int>p[0] <= <int><Py_UCS4>'9':
+        n = 10 * n - (<int>p[0] - <int32_t><Py_UCS4>'0')
+        p += 1
+
+    if p == buf:
+        return NULL
+
+    if not neg:
+        n = -n
+
+    num[0] = n
+
+    return p
diff --git a/asyncpg/protocol/consts.pxi b/asyncpg/protocol/consts.pxi
new file mode 100644 (file)
index 0000000..97cbbf3
--- /dev/null
@@ -0,0 +1,10 @@
+# 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
+
+
+DEF _MAXINT32 = 2**31 - 1
+DEF _COPY_BUFFER_SIZE = 524288
+DEF _COPY_SIGNATURE = b"PGCOPY\n\377\r\n\0"
diff --git a/asyncpg/protocol/coreproto.pxd b/asyncpg/protocol/coreproto.pxd
new file mode 100644 (file)
index 0000000..9c8b64a
--- /dev/null
@@ -0,0 +1,175 @@
+# 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 enum ConnectionStatus:
+    CONNECTION_OK = 1
+    CONNECTION_BAD = 2
+    CONNECTION_STARTED = 3           # Waiting for connection to be made.
+
+
+cdef enum ProtocolState:
+    PROTOCOL_IDLE = 0
+
+    PROTOCOL_FAILED = 1
+    PROTOCOL_ERROR_CONSUME = 2
+    PROTOCOL_CANCELLED = 3
+    PROTOCOL_TERMINATING = 4
+
+    PROTOCOL_AUTH = 10
+    PROTOCOL_PREPARE = 11
+    PROTOCOL_BIND_EXECUTE = 12
+    PROTOCOL_BIND_EXECUTE_MANY = 13
+    PROTOCOL_CLOSE_STMT_PORTAL = 14
+    PROTOCOL_SIMPLE_QUERY = 15
+    PROTOCOL_EXECUTE = 16
+    PROTOCOL_BIND = 17
+    PROTOCOL_COPY_OUT = 18
+    PROTOCOL_COPY_OUT_DATA = 19
+    PROTOCOL_COPY_OUT_DONE = 20
+    PROTOCOL_COPY_IN = 21
+    PROTOCOL_COPY_IN_DATA = 22
+
+
+cdef enum AuthenticationMessage:
+    AUTH_SUCCESSFUL = 0
+    AUTH_REQUIRED_KERBEROS = 2
+    AUTH_REQUIRED_PASSWORD = 3
+    AUTH_REQUIRED_PASSWORDMD5 = 5
+    AUTH_REQUIRED_SCMCRED = 6
+    AUTH_REQUIRED_GSS = 7
+    AUTH_REQUIRED_GSS_CONTINUE = 8
+    AUTH_REQUIRED_SSPI = 9
+
+
+AUTH_METHOD_NAME = {
+    AUTH_REQUIRED_KERBEROS: 'kerberosv5',
+    AUTH_REQUIRED_PASSWORD: 'password',
+    AUTH_REQUIRED_PASSWORDMD5: 'md5',
+    AUTH_REQUIRED_GSS: 'gss',
+    AUTH_REQUIRED_SSPI: 'sspi',
+}
+
+
+cdef enum ResultType:
+    RESULT_OK = 1
+    RESULT_FAILED = 2
+
+
+cdef enum TransactionStatus:
+    PQTRANS_IDLE = 0                 # connection idle
+    PQTRANS_ACTIVE = 1               # command in progress
+    PQTRANS_INTRANS = 2              # idle, within transaction block
+    PQTRANS_INERROR = 3              # idle, within failed transaction
+    PQTRANS_UNKNOWN = 4              # cannot determine status
+
+
+ctypedef object (*decode_row_method)(object, const char*, ssize_t)
+
+
+cdef class CoreProtocol:
+    cdef:
+        ReadBuffer buffer
+        bint _skip_discard
+        bint _discard_data
+
+        # executemany support data
+        object _execute_iter
+        str _execute_portal_name
+        str _execute_stmt_name
+
+        ConnectionStatus con_status
+        ProtocolState state
+        TransactionStatus xact_status
+
+        str encoding
+
+        object transport
+
+        # Instance of _ConnectionParameters
+        object con_params
+
+        readonly int32_t backend_pid
+        readonly int32_t backend_secret
+
+        ## Result
+        ResultType result_type
+        object result
+        bytes result_param_desc
+        bytes result_row_desc
+        bytes result_status_msg
+
+        # True - completed, False - suspended
+        bint result_execute_completed
+
+    cdef _process__auth(self, char mtype)
+    cdef _process__prepare(self, char mtype)
+    cdef _process__bind_execute(self, char mtype)
+    cdef _process__bind_execute_many(self, char mtype)
+    cdef _process__close_stmt_portal(self, char mtype)
+    cdef _process__simple_query(self, char mtype)
+    cdef _process__bind(self, char mtype)
+    cdef _process__copy_out(self, char mtype)
+    cdef _process__copy_out_data(self, char mtype)
+    cdef _process__copy_in(self, char mtype)
+    cdef _process__copy_in_data(self, char mtype)
+
+    cdef _parse_msg_authentication(self)
+    cdef _parse_msg_parameter_status(self)
+    cdef _parse_msg_notification(self)
+    cdef _parse_msg_backend_key_data(self)
+    cdef _parse_msg_ready_for_query(self)
+    cdef _parse_data_msgs(self)
+    cdef _parse_copy_data_msgs(self)
+    cdef _parse_msg_error_response(self, is_error)
+    cdef _parse_msg_command_complete(self)
+
+    cdef _write_copy_data_msg(self, object data)
+    cdef _write_copy_done_msg(self)
+    cdef _write_copy_fail_msg(self, str cause)
+
+    cdef _auth_password_message_cleartext(self)
+    cdef _auth_password_message_md5(self, bytes salt)
+
+    cdef _write(self, buf)
+
+    cdef _read_server_messages(self)
+
+    cdef _push_result(self)
+    cdef _reset_result(self)
+    cdef _set_state(self, ProtocolState new_state)
+
+    cdef _ensure_connected(self)
+
+    cdef WriteBuffer _build_bind_message(self, str portal_name,
+                                         str stmt_name,
+                                         WriteBuffer bind_data)
+
+
+    cdef _connect(self)
+    cdef _prepare(self, str stmt_name, str query)
+    cdef _send_bind_message(self, str portal_name, str stmt_name,
+                            WriteBuffer bind_data, int32_t limit)
+    cdef _bind_execute(self, str portal_name, str stmt_name,
+                       WriteBuffer bind_data, int32_t limit)
+    cdef _bind_execute_many(self, str portal_name, str stmt_name,
+                            object bind_data)
+    cdef _bind(self, str portal_name, str stmt_name,
+               WriteBuffer bind_data)
+    cdef _execute(self, str portal_name, int32_t limit)
+    cdef _close(self, str name, bint is_portal)
+    cdef _simple_query(self, str query)
+    cdef _copy_out(self, str copy_stmt)
+    cdef _copy_in(self, str copy_stmt)
+    cdef _terminate(self)
+
+    cdef _decode_row(self, const char* buf, ssize_t buf_len)
+
+    cdef _on_result(self)
+    cdef _on_notification(self, pid, channel, payload)
+    cdef _on_notice(self, parsed)
+    cdef _set_server_parameter(self, name, val)
+    cdef _on_connection_lost(self, exc)
diff --git a/asyncpg/protocol/coreproto.pyx b/asyncpg/protocol/coreproto.pyx
new file mode 100644 (file)
index 0000000..73433a4
--- /dev/null
@@ -0,0 +1,942 @@
+# 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
+
+
+from hashlib import md5 as hashlib_md5  # for MD5 authentication
+
+
+cdef class CoreProtocol:
+
+    def __init__(self, con_params):
+        # type of `con_params` is `_ConnectionParameters`
+        self.buffer = ReadBuffer()
+        self.user = con_params.user
+        self.password = con_params.password
+        self.auth_msg = None
+        self.con_params = con_params
+        self.con_status = CONNECTION_BAD
+        self.state = PROTOCOL_IDLE
+        self.xact_status = PQTRANS_IDLE
+        self.encoding = 'utf-8'
+
+        # executemany support data
+        self._execute_iter = None
+        self._execute_portal_name = None
+        self._execute_stmt_name = None
+
+        self._reset_result()
+
+    cdef _read_server_messages(self):
+        cdef:
+            char mtype
+            ProtocolState state
+            pgproto.take_message_method take_message = \
+                <pgproto.take_message_method>self.buffer.take_message
+            pgproto.get_message_type_method get_message_type= \
+                <pgproto.get_message_type_method>self.buffer.get_message_type
+
+        while take_message(self.buffer) == 1:
+            mtype = get_message_type(self.buffer)
+            state = self.state
+
+            try:
+                if mtype == b'S':
+                    # ParameterStatus
+                    self._parse_msg_parameter_status()
+
+                elif mtype == b'A':
+                    # NotificationResponse
+                    self._parse_msg_notification()
+
+                elif mtype == b'N':
+                    # 'N' - NoticeResponse
+                    self._on_notice(self._parse_msg_error_response(False))
+
+                elif state == PROTOCOL_AUTH:
+                    self._process__auth(mtype)
+
+                elif state == PROTOCOL_PREPARE:
+                    self._process__prepare(mtype)
+
+                elif state == PROTOCOL_BIND_EXECUTE:
+                    self._process__bind_execute(mtype)
+
+                elif state == PROTOCOL_BIND_EXECUTE_MANY:
+                    self._process__bind_execute_many(mtype)
+
+                elif state == PROTOCOL_EXECUTE:
+                    self._process__bind_execute(mtype)
+
+                elif state == PROTOCOL_BIND:
+                    self._process__bind(mtype)
+
+                elif state == PROTOCOL_CLOSE_STMT_PORTAL:
+                    self._process__close_stmt_portal(mtype)
+
+                elif state == PROTOCOL_SIMPLE_QUERY:
+                    self._process__simple_query(mtype)
+
+                elif state == PROTOCOL_COPY_OUT:
+                    self._process__copy_out(mtype)
+
+                elif (state == PROTOCOL_COPY_OUT_DATA or
+                        state == PROTOCOL_COPY_OUT_DONE):
+                    self._process__copy_out_data(mtype)
+
+                elif state == PROTOCOL_COPY_IN:
+                    self._process__copy_in(mtype)
+
+                elif state == PROTOCOL_COPY_IN_DATA:
+                    self._process__copy_in_data(mtype)
+
+                elif state == PROTOCOL_CANCELLED:
+                    # discard all messages until the sync message
+                    if mtype == b'E':
+                        self._parse_msg_error_response(True)
+                    elif mtype == b'Z':
+                        self._parse_msg_ready_for_query()
+                        self._push_result()
+                    else:
+                        self.buffer.discard_message()
+
+                elif state == PROTOCOL_ERROR_CONSUME:
+                    # Error in protocol (on asyncpg side);
+                    # discard all messages until sync message
+
+                    if mtype == b'Z':
+                        # Sync point, self to push the result
+                        if self.result_type != RESULT_FAILED:
+                            self.result_type = RESULT_FAILED
+                            self.result = apg_exc.InternalClientError(
+                                'unknown error in protocol implementation')
+
+                        self._push_result()
+
+                    else:
+                        self.buffer.discard_message()
+
+                elif state == PROTOCOL_TERMINATING:
+                    # The connection is being terminated.
+                    # discard all messages until connection
+                    # termination.
+                    self.buffer.discard_message()
+
+                else:
+                    raise apg_exc.InternalClientError(
+                        f'cannot process message {chr(mtype)!r}: '
+                        f'protocol is in an unexpected state {state!r}.')
+
+            except Exception as ex:
+                self.result_type = RESULT_FAILED
+                self.result = ex
+
+                if mtype == b'Z':
+                    self._push_result()
+                else:
+                    self.state = PROTOCOL_ERROR_CONSUME
+
+            finally:
+                self.buffer.finish_message()
+
+    cdef _process__auth(self, char mtype):
+        if mtype == b'R':
+            # Authentication...
+            self._parse_msg_authentication()
+            if self.result_type != RESULT_OK:
+                self.con_status = CONNECTION_BAD
+                self._push_result()
+
+            elif self.auth_msg is not None:
+                # Server wants us to send auth data, so do that.
+                self._write(self.auth_msg)
+                self.auth_msg = None
+
+        elif mtype == b'K':
+            # BackendKeyData
+            self._parse_msg_backend_key_data()
+
+        elif mtype == b'E':
+            # ErrorResponse
+            self.con_status = CONNECTION_BAD
+            self._parse_msg_error_response(True)
+            self._push_result()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self.con_status = CONNECTION_OK
+            self._push_result()
+
+    cdef _process__prepare(self, char mtype):
+        if mtype == b't':
+            # Parameters description
+            self.result_param_desc = self.buffer.consume_message()
+
+        elif mtype == b'1':
+            # ParseComplete
+            self.buffer.discard_message()
+
+        elif mtype == b'T':
+            # Row description
+            self.result_row_desc = self.buffer.consume_message()
+
+        elif mtype == b'E':
+            # ErrorResponse
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+        elif mtype == b'n':
+            # NoData
+            self.buffer.discard_message()
+
+    cdef _process__bind_execute(self, char mtype):
+        if mtype == b'D':
+            # DataRow
+            self._parse_data_msgs()
+
+        elif mtype == b's':
+            # PortalSuspended
+            self.buffer.discard_message()
+
+        elif mtype == b'C':
+            # CommandComplete
+            self.result_execute_completed = True
+            self._parse_msg_command_complete()
+
+        elif mtype == b'E':
+            # ErrorResponse
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'2':
+            # BindComplete
+            self.buffer.discard_message()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+        elif mtype == b'I':
+            # EmptyQueryResponse
+            self.buffer.discard_message()
+
+    cdef _process__bind_execute_many(self, char mtype):
+        cdef WriteBuffer buf
+
+        if mtype == b'D':
+            # DataRow
+            self._parse_data_msgs()
+
+        elif mtype == b's':
+            # PortalSuspended
+            self.buffer.discard_message()
+
+        elif mtype == b'C':
+            # CommandComplete
+            self._parse_msg_command_complete()
+
+        elif mtype == b'E':
+            # ErrorResponse
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'2':
+            # BindComplete
+            self.buffer.discard_message()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            if self.result_type == RESULT_FAILED:
+                self._push_result()
+            else:
+                try:
+                    buf = <WriteBuffer>next(self._execute_iter)
+                except StopIteration:
+                    self._push_result()
+                except Exception as e:
+                    self.result_type = RESULT_FAILED
+                    self.result = e
+                    self._push_result()
+                else:
+                    # Next iteration over the executemany() arg sequence
+                    self._send_bind_message(
+                        self._execute_portal_name, self._execute_stmt_name,
+                        buf, 0)
+
+        elif mtype == b'I':
+            # EmptyQueryResponse
+            self.buffer.discard_message()
+
+    cdef _process__bind(self, char mtype):
+        if mtype == b'E':
+            # ErrorResponse
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'2':
+            # BindComplete
+            self.buffer.discard_message()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+    cdef _process__close_stmt_portal(self, char mtype):
+        if mtype == b'E':
+            # ErrorResponse
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'3':
+            # CloseComplete
+            self.buffer.discard_message()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+    cdef _process__simple_query(self, char mtype):
+        if mtype in {b'D', b'I', b'T'}:
+            # 'D' - DataRow
+            # 'I' - EmptyQueryResponse
+            # 'T' - RowDescription
+            self.buffer.discard_message()
+
+        elif mtype == b'E':
+            # ErrorResponse
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+        elif mtype == b'C':
+            # CommandComplete
+            self._parse_msg_command_complete()
+
+        else:
+            # We don't really care about COPY IN etc
+            self.buffer.discard_message()
+
+    cdef _process__copy_out(self, char mtype):
+        if mtype == b'E':
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'H':
+            # CopyOutResponse
+            self._set_state(PROTOCOL_COPY_OUT_DATA)
+            self.buffer.discard_message()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+    cdef _process__copy_out_data(self, char mtype):
+        if mtype == b'E':
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'd':
+            # CopyData
+            self._parse_copy_data_msgs()
+
+        elif mtype == b'c':
+            # CopyDone
+            self.buffer.discard_message()
+            self._set_state(PROTOCOL_COPY_OUT_DONE)
+
+        elif mtype == b'C':
+            # CommandComplete
+            self._parse_msg_command_complete()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+    cdef _process__copy_in(self, char mtype):
+        if mtype == b'E':
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'G':
+            # CopyInResponse
+            self._set_state(PROTOCOL_COPY_IN_DATA)
+            self.buffer.discard_message()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+    cdef _process__copy_in_data(self, char mtype):
+        if mtype == b'E':
+            self._parse_msg_error_response(True)
+
+        elif mtype == b'C':
+            # CommandComplete
+            self._parse_msg_command_complete()
+
+        elif mtype == b'Z':
+            # ReadyForQuery
+            self._parse_msg_ready_for_query()
+            self._push_result()
+
+    cdef _parse_msg_command_complete(self):
+        cdef:
+            const char* cbuf
+            ssize_t cbuf_len
+
+        cbuf = self.buffer.try_consume_message(&cbuf_len)
+        if cbuf != NULL and cbuf_len > 0:
+            msg = cpython.PyBytes_FromStringAndSize(cbuf, cbuf_len - 1)
+        else:
+            msg = self.buffer.read_cstr()
+        self.result_status_msg = msg
+
+    cdef _parse_copy_data_msgs(self):
+        cdef:
+            ReadBuffer buf = self.buffer
+
+        self.result = buf.consume_messages(b'd')
+
+        # By this point we have consumed all CopyData messages
+        # in the inbound buffer.  If there are no messages left
+        # in the buffer, we need to push the accumulated data
+        # out to the caller in anticipation of the new CopyData
+        # batch.  If there _are_ non-CopyData messages left,
+        # we must not push the result here and let the
+        # _process__copy_out_data subprotocol do the job.
+        if not buf.take_message():
+            self._on_result()
+            self.result = None
+        else:
+            # If there is a message in the buffer, put it back to
+            # be processed by the next protocol iteration.
+            buf.put_message()
+
+    cdef _write_copy_data_msg(self, object data):
+        cdef:
+            WriteBuffer buf
+            object mview
+            Py_buffer *pybuf
+
+        mview = cpythonx.PyMemoryView_GetContiguous(
+            data, cpython.PyBUF_SIMPLE, b'C')
+
+        try:
+            pybuf = cpythonx.PyMemoryView_GET_BUFFER(mview)
+
+            buf = WriteBuffer.new_message(b'd')
+            buf.write_cstr(<const char *>pybuf.buf, pybuf.len)
+            buf.end_message()
+        finally:
+            mview.release()
+
+        self._write(buf)
+
+    cdef _write_copy_done_msg(self):
+        cdef:
+            WriteBuffer buf
+
+        buf = WriteBuffer.new_message(b'c')
+        buf.end_message()
+        self._write(buf)
+
+    cdef _write_copy_fail_msg(self, str cause):
+        cdef:
+            WriteBuffer buf
+
+        buf = WriteBuffer.new_message(b'f')
+        buf.write_str(cause or '', self.encoding)
+        buf.end_message()
+        self._write(buf)
+
+    cdef _parse_data_msgs(self):
+        cdef:
+            ReadBuffer buf = self.buffer
+            list rows
+
+            decode_row_method decoder = <decode_row_method>self._decode_row
+            pgproto.try_consume_message_method try_consume_message = \
+                <pgproto.try_consume_message_method>buf.try_consume_message
+            pgproto.take_message_type_method take_message_type = \
+                <pgproto.take_message_type_method>buf.take_message_type
+
+            const char* cbuf
+            ssize_t cbuf_len
+            object row
+            bytes mem
+
+        if PG_DEBUG:
+            if buf.get_message_type() != b'D':
+                raise apg_exc.InternalClientError(
+                    '_parse_data_msgs: first message is not "D"')
+
+        if self._discard_data:
+            while take_message_type(buf, b'D'):
+                buf.discard_message()
+            return
+
+        if PG_DEBUG:
+            if type(self.result) is not list:
+                raise apg_exc.InternalClientError(
+                    '_parse_data_msgs: result is not a list, but {!r}'.
+                    format(self.result))
+
+        rows = self.result
+        while take_message_type(buf, b'D'):
+            cbuf = try_consume_message(buf, &cbuf_len)
+            if cbuf != NULL:
+                row = decoder(self, cbuf, cbuf_len)
+            else:
+                mem = buf.consume_message()
+                row = decoder(
+                    self,
+                    cpython.PyBytes_AS_STRING(mem),
+                    cpython.PyBytes_GET_SIZE(mem))
+
+            cpython.PyList_Append(rows, row)
+
+    cdef _parse_msg_backend_key_data(self):
+        self.backend_pid = self.buffer.read_int32()
+        self.backend_secret = self.buffer.read_int32()
+
+    cdef _parse_msg_parameter_status(self):
+        name = self.buffer.read_cstr()
+        name = name.decode(self.encoding)
+
+        val = self.buffer.read_cstr()
+        val = val.decode(self.encoding)
+
+        self._set_server_parameter(name, val)
+
+    cdef _parse_msg_notification(self):
+        pid = self.buffer.read_int32()
+        channel = self.buffer.read_cstr().decode(self.encoding)
+        payload = self.buffer.read_cstr().decode(self.encoding)
+        self._on_notification(pid, channel, payload)
+
+    cdef _parse_msg_authentication(self):
+        cdef:
+            int32_t status
+            bytes md5_salt
+
+        status = self.buffer.read_int32()
+
+        if status == AUTH_SUCCESSFUL:
+            # AuthenticationOk
+            self.result_type = RESULT_OK
+
+        elif status == AUTH_REQUIRED_PASSWORD:
+            # AuthenticationCleartextPassword
+            self.result_type = RESULT_OK
+            self.auth_msg = self._auth_password_message_cleartext()
+
+        elif status == AUTH_REQUIRED_PASSWORDMD5:
+            # AuthenticationMD5Password
+            # Note: MD5 salt is passed as a four-byte sequence
+            md5_salt = self.buffer.read_bytes(4)
+            self.auth_msg = self._auth_password_message_md5(md5_salt)
+
+        elif status in (AUTH_REQUIRED_KERBEROS, AUTH_REQUIRED_SCMCRED,
+                        AUTH_REQUIRED_GSS, AUTH_REQUIRED_GSS_CONTINUE,
+                        AUTH_REQUIRED_SSPI):
+            self.result_type = RESULT_FAILED
+            self.result = apg_exc.InterfaceError(
+                'unsupported authentication method requested by the '
+                'server: {!r}'.format(AUTH_METHOD_NAME[status]))
+
+        else:
+            self.result_type = RESULT_FAILED
+            self.result = apg_exc.InterfaceError(
+                'unsupported authentication method requested by the '
+                'server: {}'.format(status))
+
+        self.buffer.discard_message()
+
+    cdef _auth_password_message_cleartext(self):
+        cdef:
+            WriteBuffer msg
+
+        msg = WriteBuffer.new_message(b'p')
+        msg.write_bytestring(self.password.encode('ascii'))
+        msg.end_message()
+
+        return msg
+
+    cdef _auth_password_message_md5(self, bytes salt):
+        cdef:
+            WriteBuffer msg
+
+        msg = WriteBuffer.new_message(b'p')
+
+        # 'md5' + md5(md5(password + username) + salt))
+        userpass = ((self.password or '') + (self.user or '')).encode('ascii')
+        hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\
+                encode('ascii') + salt).hexdigest().encode('ascii')
+
+        msg.write_bytestring(b'md5' + hash)
+        msg.end_message()
+
+        return msg
+
+    cdef _parse_msg_ready_for_query(self):
+        cdef char status = self.buffer.read_byte()
+
+        if status == b'I':
+            self.xact_status = PQTRANS_IDLE
+        elif status == b'T':
+            self.xact_status = PQTRANS_INTRANS
+        elif status == b'E':
+            self.xact_status = PQTRANS_INERROR
+        else:
+            self.xact_status = PQTRANS_UNKNOWN
+
+    cdef _parse_msg_error_response(self, is_error):
+        cdef:
+            char code
+            bytes message
+            dict parsed = {}
+
+        while True:
+            code = self.buffer.read_byte()
+            if code == 0:
+                break
+
+            message = self.buffer.read_cstr()
+
+            parsed[chr(code)] = message.decode()
+
+        if is_error:
+            self.result_type = RESULT_FAILED
+            self.result = parsed
+        else:
+            return parsed
+
+    cdef _push_result(self):
+        try:
+            self._on_result()
+        finally:
+            self._set_state(PROTOCOL_IDLE)
+            self._reset_result()
+
+    cdef _reset_result(self):
+        self.result_type = RESULT_OK
+        self.result = None
+        self.result_param_desc = None
+        self.result_row_desc = None
+        self.result_status_msg = None
+        self.result_execute_completed = False
+        self._discard_data = False
+
+    cdef _set_state(self, ProtocolState new_state):
+        if new_state == PROTOCOL_IDLE:
+            if self.state == PROTOCOL_FAILED:
+                raise apg_exc.InternalClientError(
+                    'cannot switch to "idle" state; '
+                    'protocol is in the "failed" state')
+            elif self.state == PROTOCOL_IDLE:
+                pass
+            else:
+                self.state = new_state
+
+        elif new_state == PROTOCOL_FAILED:
+            self.state = PROTOCOL_FAILED
+
+        elif new_state == PROTOCOL_CANCELLED:
+            self.state = PROTOCOL_CANCELLED
+
+        elif new_state == PROTOCOL_TERMINATING:
+            self.state = PROTOCOL_TERMINATING
+
+        else:
+            if self.state == PROTOCOL_IDLE:
+                self.state = new_state
+
+            elif (self.state == PROTOCOL_COPY_OUT and
+                    new_state == PROTOCOL_COPY_OUT_DATA):
+                self.state = new_state
+
+            elif (self.state == PROTOCOL_COPY_OUT_DATA and
+                    new_state == PROTOCOL_COPY_OUT_DONE):
+                self.state = new_state
+
+            elif (self.state == PROTOCOL_COPY_IN and
+                    new_state == PROTOCOL_COPY_IN_DATA):
+                self.state = new_state
+
+            elif self.state == PROTOCOL_FAILED:
+                raise apg_exc.InternalClientError(
+                    'cannot switch to state {}; '
+                    'protocol is in the "failed" state'.format(new_state))
+            else:
+                raise apg_exc.InternalClientError(
+                    'cannot switch to state {}; '
+                    'another operation ({}) is in progress'.format(
+                        new_state, self.state))
+
+    cdef _ensure_connected(self):
+        if self.con_status != CONNECTION_OK:
+            raise apg_exc.InternalClientError('not connected')
+
+    cdef WriteBuffer _build_bind_message(self, str portal_name,
+                                         str stmt_name,
+                                         WriteBuffer bind_data):
+        cdef WriteBuffer buf
+
+        buf = WriteBuffer.new_message(b'B')
+        buf.write_str(portal_name, self.encoding)
+        buf.write_str(stmt_name, self.encoding)
+
+        # Arguments
+        buf.write_buffer(bind_data)
+
+        buf.end_message()
+        return buf
+
+    # API for subclasses
+
+    cdef _connect(self):
+        cdef:
+            WriteBuffer buf
+            WriteBuffer outbuf
+
+        if self.con_status != CONNECTION_BAD:
+            raise apg_exc.InternalClientError('already connected')
+
+        self._set_state(PROTOCOL_AUTH)
+        self.con_status = CONNECTION_STARTED
+
+        # Assemble a startup message
+        buf = WriteBuffer()
+
+        # protocol version
+        buf.write_int16(3)
+        buf.write_int16(0)
+
+        buf.write_bytestring(b'client_encoding')
+        buf.write_bytestring("'{}'".format(self.encoding).encode('ascii'))
+
+        buf.write_str('user', self.encoding)
+        buf.write_str(self.con_params.user, self.encoding)
+
+        buf.write_str('database', self.encoding)
+        buf.write_str(self.con_params.database, self.encoding)
+
+        if self.con_params.server_settings is not None:
+            for k, v in self.con_params.server_settings.items():
+                buf.write_str(k, self.encoding)
+                buf.write_str(v, self.encoding)
+
+        buf.write_bytestring(b'')
+
+        # Send the buffer
+        outbuf = WriteBuffer()
+        outbuf.write_int32(buf.len() + 4)
+        outbuf.write_buffer(buf)
+        self._write(outbuf)
+
+    cdef _prepare(self, str stmt_name, str query):
+        cdef:
+            WriteBuffer packet
+            WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_PREPARE)
+
+        buf = WriteBuffer.new_message(b'P')
+        buf.write_str(stmt_name, self.encoding)
+        buf.write_str(query, self.encoding)
+        buf.write_int16(0)
+        buf.end_message()
+        packet = buf
+
+        buf = WriteBuffer.new_message(b'D')
+        buf.write_byte(b'S')
+        buf.write_str(stmt_name, self.encoding)
+        buf.end_message()
+        packet.write_buffer(buf)
+
+        packet.write_bytes(SYNC_MESSAGE)
+
+        self._write(packet)
+
+    cdef _send_bind_message(self, str portal_name, str stmt_name,
+                            WriteBuffer bind_data, int32_t limit):
+
+        cdef:
+            WriteBuffer packet
+            WriteBuffer buf
+
+        buf = self._build_bind_message(portal_name, stmt_name, bind_data)
+        packet = buf
+
+        buf = WriteBuffer.new_message(b'E')
+        buf.write_str(portal_name, self.encoding)  # name of the portal
+        buf.write_int32(limit)  # number of rows to return; 0 - all
+        buf.end_message()
+        packet.write_buffer(buf)
+
+        packet.write_bytes(SYNC_MESSAGE)
+
+        self._write(packet)
+
+    cdef _bind_execute(self, str portal_name, str stmt_name,
+                       WriteBuffer bind_data, int32_t limit):
+
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_BIND_EXECUTE)
+
+        self.result = []
+
+        self._send_bind_message(portal_name, stmt_name, bind_data, limit)
+
+    cdef _bind_execute_many(self, str portal_name, str stmt_name,
+                            object bind_data):
+
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_BIND_EXECUTE_MANY)
+
+        self.result = None
+        self._discard_data = True
+        self._execute_iter = bind_data
+        self._execute_portal_name = portal_name
+        self._execute_stmt_name = stmt_name
+
+        try:
+            buf = <WriteBuffer>next(bind_data)
+        except StopIteration:
+            self._push_result()
+        except Exception as e:
+            self.result_type = RESULT_FAILED
+            self.result = e
+            self._push_result()
+        else:
+            self._send_bind_message(portal_name, stmt_name, buf, 0)
+
+    cdef _execute(self, str portal_name, int32_t limit):
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_EXECUTE)
+
+        self.result = []
+
+        buf = WriteBuffer.new_message(b'E')
+        buf.write_str(portal_name, self.encoding)  # name of the portal
+        buf.write_int32(limit)  # number of rows to return; 0 - all
+        buf.end_message()
+
+        buf.write_bytes(SYNC_MESSAGE)
+
+        self._write(buf)
+
+    cdef _bind(self, str portal_name, str stmt_name,
+               WriteBuffer bind_data):
+
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_BIND)
+
+        buf = self._build_bind_message(portal_name, stmt_name, bind_data)
+
+        buf.write_bytes(SYNC_MESSAGE)
+
+        self._write(buf)
+
+    cdef _close(self, str name, bint is_portal):
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_CLOSE_STMT_PORTAL)
+
+        buf = WriteBuffer.new_message(b'C')
+
+        if is_portal:
+            buf.write_byte(b'P')
+        else:
+            buf.write_byte(b'S')
+
+        buf.write_str(name, self.encoding)
+        buf.end_message()
+
+        buf.write_bytes(SYNC_MESSAGE)
+
+        self._write(buf)
+
+    cdef _simple_query(self, str query):
+        cdef WriteBuffer buf
+        self._ensure_connected()
+        self._set_state(PROTOCOL_SIMPLE_QUERY)
+        buf = WriteBuffer.new_message(b'Q')
+        buf.write_str(query, self.encoding)
+        buf.end_message()
+        self._write(buf)
+
+    cdef _copy_out(self, str copy_stmt):
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_COPY_OUT)
+
+        # Send the COPY .. TO STDOUT using the SimpleQuery protocol.
+        buf = WriteBuffer.new_message(b'Q')
+        buf.write_str(copy_stmt, self.encoding)
+        buf.end_message()
+        self._write(buf)
+
+    cdef _copy_in(self, str copy_stmt):
+        cdef WriteBuffer buf
+
+        self._ensure_connected()
+        self._set_state(PROTOCOL_COPY_IN)
+
+        buf = WriteBuffer.new_message(b'Q')
+        buf.write_str(copy_stmt, self.encoding)
+        buf.end_message()
+        self._write(buf)
+
+    cdef _terminate(self):
+        cdef WriteBuffer buf
+        self._ensure_connected()
+        self._set_state(PROTOCOL_TERMINATING)
+        buf = WriteBuffer.new_message(b'X')
+        buf.end_message()
+        self._write(buf)
+
+    cdef _write(self, buf):
+        raise NotImplementedError
+
+    cdef _decode_row(self, const char* buf, ssize_t buf_len):
+        pass
+
+    cdef _set_server_parameter(self, name, val):
+        pass
+
+    cdef _on_result(self):
+        pass
+
+    cdef _on_notice(self, parsed):
+        pass
+
+    cdef _on_notification(self, pid, channel, payload):
+        pass
+
+    cdef _on_connection_lost(self, exc):
+        pass
+
+
+cdef bytes SYNC_MESSAGE = bytes(WriteBuffer.new_message(b'S').end_message())
diff --git a/asyncpg/protocol/cpythonx.pxd b/asyncpg/protocol/cpythonx.pxd
new file mode 100644 (file)
index 0000000..1c72988
--- /dev/null
@@ -0,0 +1,19 @@
+# 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 extern from "Python.h":
+    int PyByteArray_Check(object)
+
+    int PyMemoryView_Check(object)
+    Py_buffer *PyMemoryView_GET_BUFFER(object)
+    object PyMemoryView_GetContiguous(object, int buffertype, char order)
+
+    Py_UCS4* PyUnicode_AsUCS4Copy(object) except NULL
+    object PyUnicode_FromKindAndData(
+        int kind, const void *buffer, Py_ssize_t size)
+
+    int PyUnicode_4BYTE_KIND
diff --git a/asyncpg/protocol/encodings.pyx b/asyncpg/protocol/encodings.pyx
new file mode 100644 (file)
index 0000000..dcd692b
--- /dev/null
@@ -0,0 +1,63 @@
+# 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
+
+
+'''Map PostgreSQL encoding names to Python encoding names
+
+https://www.postgresql.org/docs/current/static/multibyte.html#CHARSET-TABLE
+'''
+
+cdef dict ENCODINGS_MAP = {
+    'abc': 'cp1258',
+    'alt': 'cp866',
+    'euc_cn': 'euccn',
+    'euc_jp': 'eucjp',
+    'euc_kr': 'euckr',
+    'koi8r': 'koi8_r',
+    'koi8u': 'koi8_u',
+    'shift_jis_2004': 'euc_jis_2004',
+    'sjis': 'shift_jis',
+    'sql_ascii': 'ascii',
+    'vscii': 'cp1258',
+    'tcvn': 'cp1258',
+    'tcvn5712': 'cp1258',
+    'unicode': 'utf_8',
+    'win': 'cp1521',
+    'win1250': 'cp1250',
+    'win1251': 'cp1251',
+    'win1252': 'cp1252',
+    'win1253': 'cp1253',
+    'win1254': 'cp1254',
+    'win1255': 'cp1255',
+    'win1256': 'cp1256',
+    'win1257': 'cp1257',
+    'win1258': 'cp1258',
+    'win866': 'cp866',
+    'win874': 'cp874',
+    'win932': 'cp932',
+    'win936': 'cp936',
+    'win949': 'cp949',
+    'win950': 'cp950',
+    'windows1250': 'cp1250',
+    'windows1251': 'cp1251',
+    'windows1252': 'cp1252',
+    'windows1253': 'cp1253',
+    'windows1254': 'cp1254',
+    'windows1255': 'cp1255',
+    'windows1256': 'cp1256',
+    'windows1257': 'cp1257',
+    'windows1258': 'cp1258',
+    'windows866': 'cp866',
+    'windows874': 'cp874',
+    'windows932': 'cp932',
+    'windows936': 'cp936',
+    'windows949': 'cp949',
+    'windows950': 'cp950',
+}
+
+
+cdef get_python_encoding(pg_encoding):
+    return ENCODINGS_MAP.get(pg_encoding.lower(), pg_encoding.lower())
diff --git a/asyncpg/protocol/pgtypes.pxi b/asyncpg/protocol/pgtypes.pxi
new file mode 100644 (file)
index 0000000..14db69d
--- /dev/null
@@ -0,0 +1,220 @@
+# 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
+
+
+# GENERATED FROM pg_catalog.pg_type
+# DO NOT MODIFY, use tools/generate_type_map.py to update
+
+DEF INVALIDOID = 0
+DEF MAXBUILTINOID = 9999
+DEF MAXSUPPORTEDOID = 4096
+
+DEF BOOLOID = 16
+DEF BYTEAOID = 17
+DEF CHAROID = 18
+DEF NAMEOID = 19
+DEF INT8OID = 20
+DEF INT2OID = 21
+DEF INT4OID = 23
+DEF REGPROCOID = 24
+DEF TEXTOID = 25
+DEF OIDOID = 26
+DEF TIDOID = 27
+DEF XIDOID = 28
+DEF CIDOID = 29
+DEF PG_DDL_COMMANDOID = 32
+DEF JSONOID = 114
+DEF XMLOID = 142
+DEF PG_NODE_TREEOID = 194
+DEF SMGROID = 210
+DEF INDEX_AM_HANDLEROID = 325
+DEF POINTOID = 600
+DEF LSEGOID = 601
+DEF PATHOID = 602
+DEF BOXOID = 603
+DEF POLYGONOID = 604
+DEF LINEOID = 628
+DEF CIDROID = 650
+DEF FLOAT4OID = 700
+DEF FLOAT8OID = 701
+DEF ABSTIMEOID = 702
+DEF RELTIMEOID = 703
+DEF TINTERVALOID = 704
+DEF UNKNOWNOID = 705
+DEF CIRCLEOID = 718
+DEF MACADDR8OID = 774
+DEF MONEYOID = 790
+DEF MACADDROID = 829
+DEF INETOID = 869
+DEF _TEXTOID = 1009
+DEF _OIDOID = 1028
+DEF ACLITEMOID = 1033
+DEF BPCHAROID = 1042
+DEF VARCHAROID = 1043
+DEF DATEOID = 1082
+DEF TIMEOID = 1083
+DEF TIMESTAMPOID = 1114
+DEF TIMESTAMPTZOID = 1184
+DEF INTERVALOID = 1186
+DEF TIMETZOID = 1266
+DEF BITOID = 1560
+DEF VARBITOID = 1562
+DEF NUMERICOID = 1700
+DEF REFCURSOROID = 1790
+DEF REGPROCEDUREOID = 2202
+DEF REGOPEROID = 2203
+DEF REGOPERATOROID = 2204
+DEF REGCLASSOID = 2205
+DEF REGTYPEOID = 2206
+DEF RECORDOID = 2249
+DEF CSTRINGOID = 2275
+DEF ANYOID = 2276
+DEF ANYARRAYOID = 2277
+DEF VOIDOID = 2278
+DEF TRIGGEROID = 2279
+DEF LANGUAGE_HANDLEROID = 2280
+DEF INTERNALOID = 2281
+DEF OPAQUEOID = 2282
+DEF ANYELEMENTOID = 2283
+DEF ANYNONARRAYOID = 2776
+DEF UUIDOID = 2950
+DEF TXID_SNAPSHOTOID = 2970
+DEF FDW_HANDLEROID = 3115
+DEF PG_LSNOID = 3220
+DEF TSM_HANDLEROID = 3310
+DEF PG_NDISTINCTOID = 3361
+DEF PG_DEPENDENCIESOID = 3402
+DEF ANYENUMOID = 3500
+DEF TSVECTOROID = 3614
+DEF TSQUERYOID = 3615
+DEF GTSVECTOROID = 3642
+DEF REGCONFIGOID = 3734
+DEF REGDICTIONARYOID = 3769
+DEF JSONBOID = 3802
+DEF ANYRANGEOID = 3831
+DEF EVENT_TRIGGEROID = 3838
+DEF REGNAMESPACEOID = 4089
+DEF REGROLEOID = 4096
+
+cdef ARRAY_TYPES = (_TEXTOID, _OIDOID,)
+
+BUILTIN_TYPE_OID_MAP = {
+    ABSTIMEOID: 'abstime',
+    ACLITEMOID: 'aclitem',
+    ANYARRAYOID: 'anyarray',
+    ANYELEMENTOID: 'anyelement',
+    ANYENUMOID: 'anyenum',
+    ANYNONARRAYOID: 'anynonarray',
+    ANYOID: 'any',
+    ANYRANGEOID: 'anyrange',
+    BITOID: 'bit',
+    BOOLOID: 'bool',
+    BOXOID: 'box',
+    BPCHAROID: 'bpchar',
+    BYTEAOID: 'bytea',
+    CHAROID: 'char',
+    CIDOID: 'cid',
+    CIDROID: 'cidr',
+    CIRCLEOID: 'circle',
+    CSTRINGOID: 'cstring',
+    DATEOID: 'date',
+    EVENT_TRIGGEROID: 'event_trigger',
+    FDW_HANDLEROID: 'fdw_handler',
+    FLOAT4OID: 'float4',
+    FLOAT8OID: 'float8',
+    GTSVECTOROID: 'gtsvector',
+    INDEX_AM_HANDLEROID: 'index_am_handler',
+    INETOID: 'inet',
+    INT2OID: 'int2',
+    INT4OID: 'int4',
+    INT8OID: 'int8',
+    INTERNALOID: 'internal',
+    INTERVALOID: 'interval',
+    JSONBOID: 'jsonb',
+    JSONOID: 'json',
+    LANGUAGE_HANDLEROID: 'language_handler',
+    LINEOID: 'line',
+    LSEGOID: 'lseg',
+    MACADDR8OID: 'macaddr8',
+    MACADDROID: 'macaddr',
+    MONEYOID: 'money',
+    NAMEOID: 'name',
+    NUMERICOID: 'numeric',
+    OIDOID: 'oid',
+    OPAQUEOID: 'opaque',
+    PATHOID: 'path',
+    PG_DDL_COMMANDOID: 'pg_ddl_command',
+    PG_DEPENDENCIESOID: 'pg_dependencies',
+    PG_LSNOID: 'pg_lsn',
+    PG_NDISTINCTOID: 'pg_ndistinct',
+    PG_NODE_TREEOID: 'pg_node_tree',
+    POINTOID: 'point',
+    POLYGONOID: 'polygon',
+    RECORDOID: 'record',
+    REFCURSOROID: 'refcursor',
+    REGCLASSOID: 'regclass',
+    REGCONFIGOID: 'regconfig',
+    REGDICTIONARYOID: 'regdictionary',
+    REGNAMESPACEOID: 'regnamespace',
+    REGOPERATOROID: 'regoperator',
+    REGOPEROID: 'regoper',
+    REGPROCEDUREOID: 'regprocedure',
+    REGPROCOID: 'regproc',
+    REGROLEOID: 'regrole',
+    REGTYPEOID: 'regtype',
+    RELTIMEOID: 'reltime',
+    SMGROID: 'smgr',
+    TEXTOID: 'text',
+    TIDOID: 'tid',
+    TIMEOID: 'time',
+    TIMESTAMPOID: 'timestamp',
+    TIMESTAMPTZOID: 'timestamptz',
+    TIMETZOID: 'timetz',
+    TINTERVALOID: 'tinterval',
+    TRIGGEROID: 'trigger',
+    TSM_HANDLEROID: 'tsm_handler',
+    TSQUERYOID: 'tsquery',
+    TSVECTOROID: 'tsvector',
+    TXID_SNAPSHOTOID: 'txid_snapshot',
+    UNKNOWNOID: 'unknown',
+    UUIDOID: 'uuid',
+    VARBITOID: 'varbit',
+    VARCHAROID: 'varchar',
+    VOIDOID: 'void',
+    XIDOID: 'xid',
+    XMLOID: 'xml',
+    _OIDOID: 'oid[]',
+    _TEXTOID: 'text[]'
+}
+
+BUILTIN_TYPE_NAME_MAP = {v: k for k, v in BUILTIN_TYPE_OID_MAP.items()}
+
+BUILTIN_TYPE_NAME_MAP['smallint'] = \
+    BUILTIN_TYPE_NAME_MAP['int2']
+
+BUILTIN_TYPE_NAME_MAP['int'] = \
+    BUILTIN_TYPE_NAME_MAP['int4']
+
+BUILTIN_TYPE_NAME_MAP['integer'] = \
+    BUILTIN_TYPE_NAME_MAP['int4']
+
+BUILTIN_TYPE_NAME_MAP['bigint'] = \
+    BUILTIN_TYPE_NAME_MAP['int8']
+
+BUILTIN_TYPE_NAME_MAP['decimal'] = \
+    BUILTIN_TYPE_NAME_MAP['numeric']
+
+BUILTIN_TYPE_NAME_MAP['real'] = \
+    BUILTIN_TYPE_NAME_MAP['float4']
+
+BUILTIN_TYPE_NAME_MAP['double precision'] = \
+    BUILTIN_TYPE_NAME_MAP['float8']
+
+BUILTIN_TYPE_NAME_MAP['timestamp with timezone'] = \
+    BUILTIN_TYPE_NAME_MAP['timestamptz']
+
+BUILTIN_TYPE_NAME_MAP['time with timezone'] = \
+    BUILTIN_TYPE_NAME_MAP['timetz']
diff --git a/asyncpg/protocol/prepared_stmt.pxd b/asyncpg/protocol/prepared_stmt.pxd
new file mode 100644 (file)
index 0000000..0d3f8d3
--- /dev/null
@@ -0,0 +1,35 @@
+# 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 class PreparedStatementState:
+    cdef:
+        readonly str name
+        readonly str query
+        readonly bint closed
+        readonly int refs
+
+        list         row_desc
+        list         parameters_desc
+
+        ConnectionSettings settings
+
+        int16_t      args_num
+        bint         have_text_args
+        tuple        args_codecs
+
+        int16_t      cols_num
+        object       cols_desc
+        bint         have_text_cols
+        tuple        rows_codecs
+
+    cdef _encode_bind_msg(self, args)
+    cpdef _init_codecs(self)
+    cdef _ensure_rows_decoder(self)
+    cdef _ensure_args_encoder(self)
+    cdef _set_row_desc(self, object desc)
+    cdef _set_args_desc(self, object desc)
+    cdef _decode_row(self, const char* cbuf, ssize_t buf_len)
diff --git a/asyncpg/protocol/prepared_stmt.pyx b/asyncpg/protocol/prepared_stmt.pyx
new file mode 100644 (file)
index 0000000..eef9cbf
--- /dev/null
@@ -0,0 +1,349 @@
+# 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
+
+
+from asyncpg import exceptions
+
+
+@cython.final
+cdef class PreparedStatementState:
+
+    def __cinit__(self, str name, str query, BaseProtocol protocol):
+        self.name = name
+        self.query = query
+        self.settings = protocol.settings
+        self.row_desc = self.parameters_desc = None
+        self.args_codecs = self.rows_codecs = None
+        self.args_num = self.cols_num = 0
+        self.cols_desc = None
+        self.closed = False
+        self.refs = 0
+
+    def _get_parameters(self):
+        cdef Codec codec
+
+        result = []
+        for oid in self.parameters_desc:
+            codec = self.settings.get_data_codec(oid)
+            if codec is None:
+                raise exceptions.InternalClientError(
+                    'missing codec information for OID {}'.format(oid))
+            result.append(apg_types.Type(
+                oid, codec.name, codec.kind, codec.schema))
+
+        return tuple(result)
+
+    def _get_attributes(self):
+        cdef Codec codec
+
+        if not self.row_desc:
+            return ()
+
+        result = []
+        for d in self.row_desc:
+            name = d[0]
+            oid = d[3]
+
+            codec = self.settings.get_data_codec(oid)
+            if codec is None:
+                raise exceptions.InternalClientError(
+                    'missing codec information for OID {}'.format(oid))
+
+            name = name.decode(self.settings._encoding)
+
+            result.append(
+                apg_types.Attribute(name,
+                    apg_types.Type(oid, codec.name, codec.kind, codec.schema)))
+
+        return tuple(result)
+
+    def _init_types(self):
+        cdef:
+            Codec codec
+            set missing = set()
+
+        if self.parameters_desc:
+            for p_oid in self.parameters_desc:
+                codec = self.settings.get_data_codec(<uint32_t>p_oid)
+                if codec is None or not codec.has_encoder():
+                    missing.add(p_oid)
+
+        if self.row_desc:
+            for rdesc in self.row_desc:
+                codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+                if codec is None or not codec.has_decoder():
+                    missing.add(rdesc[3])
+
+        return missing
+
+    cpdef _init_codecs(self):
+        self._ensure_args_encoder()
+        self._ensure_rows_decoder()
+
+    def attach(self):
+        self.refs += 1
+
+    def detach(self):
+        self.refs -= 1
+
+    def mark_closed(self):
+        self.closed = True
+
+    cdef _encode_bind_msg(self, args):
+        cdef:
+            int idx
+            WriteBuffer writer
+            Codec codec
+
+        if len(args) > 32767:
+            raise exceptions.InterfaceError(
+                'the number of query arguments cannot exceed 32767')
+
+        writer = WriteBuffer.new()
+
+        num_args_passed = len(args)
+        if self.args_num != num_args_passed:
+            hint = 'Check the query against the passed list of arguments.'
+
+            if self.args_num == 0:
+                # If the server was expecting zero arguments, it is likely
+                # that the user tried to parametrize a statement that does
+                # not support parameters.
+                hint += (r'  Note that parameters are supported only in'
+                         r' SELECT, INSERT, UPDATE, DELETE, and VALUES'
+                         r' statements, and will *not* work in statements '
+                         r' like CREATE VIEW or DECLARE CURSOR.')
+
+            raise exceptions.InterfaceError(
+                'the server expects {x} argument{s} for this query, '
+                '{y} {w} passed'.format(
+                    x=self.args_num, s='s' if self.args_num != 1 else '',
+                    y=num_args_passed,
+                    w='was' if num_args_passed == 1 else 'were'),
+                hint=hint)
+
+        if self.have_text_args:
+            writer.write_int16(self.args_num)
+            for idx in range(self.args_num):
+                codec = <Codec>(self.args_codecs[idx])
+                writer.write_int16(codec.format)
+        else:
+            # All arguments are in binary format
+            writer.write_int32(0x00010001)
+
+        writer.write_int16(self.args_num)
+
+        for idx in range(self.args_num):
+            arg = args[idx]
+            if arg is None:
+                writer.write_int32(-1)
+            else:
+                codec = <Codec>(self.args_codecs[idx])
+                try:
+                    codec.encode(self.settings, writer, arg)
+                except (AssertionError, exceptions.InternalClientError):
+                    # These are internal errors and should raise as-is.
+                    raise
+                except exceptions.InterfaceError:
+                    # This is already a descriptive error.
+                    raise
+                except Exception as e:
+                    # Everything else is assumed to be an encoding error
+                    # due to invalid input.
+                    value_repr = repr(arg)
+                    if len(value_repr) > 40:
+                        value_repr = value_repr[:40] + '...'
+
+                    raise exceptions.DataError(
+                        'invalid input for query argument'
+                        ' ${n}: {v} ({msg})'.format(
+                            n=idx + 1, v=value_repr, msg=e)) from e
+
+        if self.have_text_cols:
+            writer.write_int16(self.cols_num)
+            for idx in range(self.cols_num):
+                codec = <Codec>(self.rows_codecs[idx])
+                writer.write_int16(codec.format)
+        else:
+            # All columns are in binary format
+            writer.write_int32(0x00010001)
+
+        return writer
+
+    cdef _ensure_rows_decoder(self):
+        cdef:
+            list cols_names
+            object cols_mapping
+            tuple row
+            uint32_t oid
+            Codec codec
+            list codecs
+
+        if self.cols_desc is not None:
+            return
+
+        if self.cols_num == 0:
+            self.cols_desc = record.ApgRecordDesc_New({}, ())
+            return
+
+        cols_mapping = collections.OrderedDict()
+        cols_names = []
+        codecs = []
+        for i from 0 <= i < self.cols_num:
+            row = self.row_desc[i]
+            col_name = row[0].decode(self.settings._encoding)
+            cols_mapping[col_name] = i
+            cols_names.append(col_name)
+            oid = row[3]
+            codec = self.settings.get_data_codec(oid)
+            if codec is None or not codec.has_decoder():
+                raise exceptions.InternalClientError(
+                    'no decoder for OID {}'.format(oid))
+            if not codec.is_binary():
+                self.have_text_cols = True
+
+            codecs.append(codec)
+
+        self.cols_desc = record.ApgRecordDesc_New(
+            cols_mapping, tuple(cols_names))
+
+        self.rows_codecs = tuple(codecs)
+
+    cdef _ensure_args_encoder(self):
+        cdef:
+            uint32_t p_oid
+            Codec codec
+            list codecs = []
+
+        if self.args_num == 0 or self.args_codecs is not None:
+            return
+
+        for i from 0 <= i < self.args_num:
+            p_oid = self.parameters_desc[i]
+            codec = self.settings.get_data_codec(p_oid)
+            if codec is None or not codec.has_encoder():
+                raise exceptions.InternalClientError(
+                    'no encoder for OID {}'.format(p_oid))
+            if codec.type not in {}:
+                self.have_text_args = True
+
+            codecs.append(codec)
+
+        self.args_codecs = tuple(codecs)
+
+    cdef _set_row_desc(self, object desc):
+        self.row_desc = _decode_row_desc(desc)
+        self.cols_num = <int16_t>(len(self.row_desc))
+
+    cdef _set_args_desc(self, object desc):
+        self.parameters_desc = _decode_parameters_desc(desc)
+        self.args_num = <int16_t>(len(self.parameters_desc))
+
+    cdef _decode_row(self, const char* cbuf, ssize_t buf_len):
+        cdef:
+            Codec codec
+            int16_t fnum
+            int32_t flen
+            object dec_row
+            tuple rows_codecs = self.rows_codecs
+            ConnectionSettings settings = self.settings
+            int32_t i
+            FRBuffer rbuf
+            ssize_t bl
+
+        frb_init(&rbuf, cbuf, buf_len)
+
+        fnum = hton.unpack_int16(frb_read(&rbuf, 2))
+
+        if fnum != self.cols_num:
+            raise exceptions.ProtocolError(
+                'the number of columns in the result row ({}) is '
+                'different from what was described ({})'.format(
+                    fnum, self.cols_num))
+
+        dec_row = record.ApgRecord_New(self.cols_desc, fnum)
+        for i in range(fnum):
+            flen = hton.unpack_int32(frb_read(&rbuf, 4))
+
+            if flen == -1:
+                val = None
+            else:
+                # Clamp buffer size to that of the reported field length
+                # to make sure that codecs can rely on read_all() working
+                # properly.
+                bl = frb_get_len(&rbuf)
+                if flen > bl:
+                    frb_check(&rbuf, flen)
+                frb_set_len(&rbuf, flen)
+                codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)
+                val = codec.decode(settings, &rbuf)
+                if frb_get_len(&rbuf) != 0:
+                    raise BufferError(
+                        'unexpected trailing {} bytes in buffer'.format(
+                            frb_get_len(&rbuf)))
+                frb_set_len(&rbuf, bl - flen)
+
+            cpython.Py_INCREF(val)
+            record.ApgRecord_SET_ITEM(dec_row, i, val)
+
+        if frb_get_len(&rbuf) != 0:
+            raise BufferError('unexpected trailing {} bytes in buffer'.format(
+                frb_get_len(&rbuf)))
+
+        return dec_row
+
+
+cdef _decode_parameters_desc(object desc):
+    cdef:
+        ReadBuffer reader
+        int16_t nparams
+        uint32_t p_oid
+        list result = []
+
+    reader = ReadBuffer.new_message_parser(desc)
+    nparams = reader.read_int16()
+
+    for i from 0 <= i < nparams:
+        p_oid = <uint32_t>reader.read_int32()
+        result.append(p_oid)
+
+    return result
+
+
+cdef _decode_row_desc(object desc):
+    cdef:
+        ReadBuffer reader
+
+        int16_t nfields
+
+        bytes f_name
+        uint32_t f_table_oid
+        int16_t f_column_num
+        uint32_t f_dt_oid
+        int16_t f_dt_size
+        int32_t f_dt_mod
+        int16_t f_format
+
+        list result
+
+    reader = ReadBuffer.new_message_parser(desc)
+    nfields = reader.read_int16()
+    result = []
+
+    for i from 0 <= i < nfields:
+        f_name = reader.read_cstr()
+        f_table_oid = <uint32_t>reader.read_int32()
+        f_column_num = reader.read_int16()
+        f_dt_oid = <uint32_t>reader.read_int32()
+        f_dt_size = reader.read_int16()
+        f_dt_mod = reader.read_int32()
+        f_format = reader.read_int16()
+
+        result.append(
+            (f_name, f_table_oid, f_column_num, f_dt_oid,
+             f_dt_size, f_dt_mod, f_format))
+
+    return result
diff --git a/asyncpg/protocol/protocol.c b/asyncpg/protocol/protocol.c
new file mode 100644 (file)
index 0000000..80e87d8
--- /dev/null
@@ -0,0 +1,80877 @@
+/* Generated by Cython 0.29 */
+
+/* BEGIN: Cython Metadata
+{
+    "distutils": {
+        "depends": [
+            "asyncpg/pgproto/debug.h"
+        ],
+        "extra_compile_args": [
+            "-O2",
+            "-fsigned-char",
+            "-Wall",
+            "-Wsign-compare",
+            "-Wconversion"
+        ],
+        "include_dirs": [
+            "./asyncpg/pgproto",
+            "asyncpg/pgproto/"
+        ],
+        "name": "asyncpg.protocol.protocol",
+        "sources": [
+            "asyncpg/protocol/protocol.pyx",
+            "asyncpg/protocol/record/recordobj.c"
+        ]
+    },
+    "module_name": "asyncpg.protocol.protocol"
+}
+END: Cython Metadata */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+    #error Python headers needed to compile C extensions, please install development version of Python.
+#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
+    #error Cython requires Python 2.6+ or Python 3.3+.
+#else
+#define CYTHON_ABI "0_29"
+#define CYTHON_HEX_VERSION 0x001D00F0
+#define CYTHON_FUTURE_DIVISION 1
+#include <stddef.h>
+#ifndef offsetof
+  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+  #ifndef __stdcall
+    #define __stdcall
+  #endif
+  #ifndef __cdecl
+    #define __cdecl
+  #endif
+  #ifndef __fastcall
+    #define __fastcall
+  #endif
+#endif
+#ifndef DL_IMPORT
+  #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+  #define DL_EXPORT(t) t
+#endif
+#define __PYX_COMMA ,
+#ifndef HAVE_LONG_LONG
+  #if PY_VERSION_HEX >= 0x02070000
+    #define HAVE_LONG_LONG
+  #endif
+#endif
+#ifndef PY_LONG_LONG
+  #define PY_LONG_LONG LONG_LONG
+#endif
+#ifndef Py_HUGE_VAL
+  #define Py_HUGE_VAL HUGE_VAL
+#endif
+#ifdef PYPY_VERSION
+  #define CYTHON_COMPILING_IN_PYPY 1
+  #define CYTHON_COMPILING_IN_PYSTON 0
+  #define CYTHON_COMPILING_IN_CPYTHON 0
+  #undef CYTHON_USE_TYPE_SLOTS
+  #define CYTHON_USE_TYPE_SLOTS 0
+  #undef CYTHON_USE_PYTYPE_LOOKUP
+  #define CYTHON_USE_PYTYPE_LOOKUP 0
+  #if PY_VERSION_HEX < 0x03050000
+    #undef CYTHON_USE_ASYNC_SLOTS
+    #define CYTHON_USE_ASYNC_SLOTS 0
+  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
+    #define CYTHON_USE_ASYNC_SLOTS 1
+  #endif
+  #undef CYTHON_USE_PYLIST_INTERNALS
+  #define CYTHON_USE_PYLIST_INTERNALS 0
+  #undef CYTHON_USE_UNICODE_INTERNALS
+  #define CYTHON_USE_UNICODE_INTERNALS 0
+  #undef CYTHON_USE_UNICODE_WRITER
+  #define CYTHON_USE_UNICODE_WRITER 0
+  #undef CYTHON_USE_PYLONG_INTERNALS
+  #define CYTHON_USE_PYLONG_INTERNALS 0
+  #undef CYTHON_AVOID_BORROWED_REFS
+  #define CYTHON_AVOID_BORROWED_REFS 1
+  #undef CYTHON_ASSUME_SAFE_MACROS
+  #define CYTHON_ASSUME_SAFE_MACROS 0
+  #undef CYTHON_UNPACK_METHODS
+  #define CYTHON_UNPACK_METHODS 0
+  #undef CYTHON_FAST_THREAD_STATE
+  #define CYTHON_FAST_THREAD_STATE 0
+  #undef CYTHON_FAST_PYCALL
+  #define CYTHON_FAST_PYCALL 0
+  #undef CYTHON_PEP489_MULTI_PHASE_INIT
+  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
+  #undef CYTHON_USE_TP_FINALIZE
+  #define CYTHON_USE_TP_FINALIZE 0
+  #undef CYTHON_USE_DICT_VERSIONS
+  #define CYTHON_USE_DICT_VERSIONS 0
+  #undef CYTHON_USE_EXC_INFO_STACK
+  #define CYTHON_USE_EXC_INFO_STACK 0
+#elif defined(PYSTON_VERSION)
+  #define CYTHON_COMPILING_IN_PYPY 0
+  #define CYTHON_COMPILING_IN_PYSTON 1
+  #define CYTHON_COMPILING_IN_CPYTHON 0
+  #ifndef CYTHON_USE_TYPE_SLOTS
+    #define CYTHON_USE_TYPE_SLOTS 1
+  #endif
+  #undef CYTHON_USE_PYTYPE_LOOKUP
+  #define CYTHON_USE_PYTYPE_LOOKUP 0
+  #undef CYTHON_USE_ASYNC_SLOTS
+  #define CYTHON_USE_ASYNC_SLOTS 0
+  #undef CYTHON_USE_PYLIST_INTERNALS
+  #define CYTHON_USE_PYLIST_INTERNALS 0
+  #ifndef CYTHON_USE_UNICODE_INTERNALS
+    #define CYTHON_USE_UNICODE_INTERNALS 1
+  #endif
+  #undef CYTHON_USE_UNICODE_WRITER
+  #define CYTHON_USE_UNICODE_WRITER 0
+  #undef CYTHON_USE_PYLONG_INTERNALS
+  #define CYTHON_USE_PYLONG_INTERNALS 0
+  #ifndef CYTHON_AVOID_BORROWED_REFS
+    #define CYTHON_AVOID_BORROWED_REFS 0
+  #endif
+  #ifndef CYTHON_ASSUME_SAFE_MACROS
+    #define CYTHON_ASSUME_SAFE_MACROS 1
+  #endif
+  #ifndef CYTHON_UNPACK_METHODS
+    #define CYTHON_UNPACK_METHODS 1
+  #endif
+  #undef CYTHON_FAST_THREAD_STATE
+  #define CYTHON_FAST_THREAD_STATE 0
+  #undef CYTHON_FAST_PYCALL
+  #define CYTHON_FAST_PYCALL 0
+  #undef CYTHON_PEP489_MULTI_PHASE_INIT
+  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
+  #undef CYTHON_USE_TP_FINALIZE
+  #define CYTHON_USE_TP_FINALIZE 0
+  #undef CYTHON_USE_DICT_VERSIONS
+  #define CYTHON_USE_DICT_VERSIONS 0
+  #undef CYTHON_USE_EXC_INFO_STACK
+  #define CYTHON_USE_EXC_INFO_STACK 0
+#else
+  #define CYTHON_COMPILING_IN_PYPY 0
+  #define CYTHON_COMPILING_IN_PYSTON 0
+  #define CYTHON_COMPILING_IN_CPYTHON 1
+  #ifndef CYTHON_USE_TYPE_SLOTS
+    #define CYTHON_USE_TYPE_SLOTS 1
+  #endif
+  #if PY_VERSION_HEX < 0x02070000
+    #undef CYTHON_USE_PYTYPE_LOOKUP
+    #define CYTHON_USE_PYTYPE_LOOKUP 0
+  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
+    #define CYTHON_USE_PYTYPE_LOOKUP 1
+  #endif
+  #if PY_MAJOR_VERSION < 3
+    #undef CYTHON_USE_ASYNC_SLOTS
+    #define CYTHON_USE_ASYNC_SLOTS 0
+  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
+    #define CYTHON_USE_ASYNC_SLOTS 1
+  #endif
+  #if PY_VERSION_HEX < 0x02070000
+    #undef CYTHON_USE_PYLONG_INTERNALS
+    #define CYTHON_USE_PYLONG_INTERNALS 0
+  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
+    #define CYTHON_USE_PYLONG_INTERNALS 1
+  #endif
+  #ifndef CYTHON_USE_PYLIST_INTERNALS
+    #define CYTHON_USE_PYLIST_INTERNALS 1
+  #endif
+  #ifndef CYTHON_USE_UNICODE_INTERNALS
+    #define CYTHON_USE_UNICODE_INTERNALS 1
+  #endif
+  #if PY_VERSION_HEX < 0x030300F0
+    #undef CYTHON_USE_UNICODE_WRITER
+    #define CYTHON_USE_UNICODE_WRITER 0
+  #elif !defined(CYTHON_USE_UNICODE_WRITER)
+    #define CYTHON_USE_UNICODE_WRITER 1
+  #endif
+  #ifndef CYTHON_AVOID_BORROWED_REFS
+    #define CYTHON_AVOID_BORROWED_REFS 0
+  #endif
+  #ifndef CYTHON_ASSUME_SAFE_MACROS
+    #define CYTHON_ASSUME_SAFE_MACROS 1
+  #endif
+  #ifndef CYTHON_UNPACK_METHODS
+    #define CYTHON_UNPACK_METHODS 1
+  #endif
+  #ifndef CYTHON_FAST_THREAD_STATE
+    #define CYTHON_FAST_THREAD_STATE 1
+  #endif
+  #ifndef CYTHON_FAST_PYCALL
+    #define CYTHON_FAST_PYCALL 1
+  #endif
+  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
+    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
+  #endif
+  #ifndef CYTHON_USE_TP_FINALIZE
+    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
+  #endif
+  #ifndef CYTHON_USE_DICT_VERSIONS
+    #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
+  #endif
+  #ifndef CYTHON_USE_EXC_INFO_STACK
+    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
+  #endif
+#endif
+#if !defined(CYTHON_FAST_PYCCALL)
+#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
+#endif
+#if CYTHON_USE_PYLONG_INTERNALS
+  #include "longintrepr.h"
+  #undef SHIFT
+  #undef BASE
+  #undef MASK
+#endif
+#ifndef __has_attribute
+  #define __has_attribute(x) 0
+#endif
+#ifndef __has_cpp_attribute
+  #define __has_cpp_attribute(x) 0
+#endif
+#ifndef CYTHON_RESTRICT
+  #if defined(__GNUC__)
+    #define CYTHON_RESTRICT __restrict__
+  #elif defined(_MSC_VER) && _MSC_VER >= 1400
+    #define CYTHON_RESTRICT __restrict
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_RESTRICT restrict
+  #else
+    #define CYTHON_RESTRICT
+  #endif
+#endif
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#     define CYTHON_UNUSED __attribute__ ((__unused__))
+#   else
+#     define CYTHON_UNUSED
+#   endif
+# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
+#   define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+#   define CYTHON_UNUSED
+# endif
+#endif
+#ifndef CYTHON_MAYBE_UNUSED_VAR
+#  if defined(__cplusplus)
+     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
+#  else
+#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
+#  endif
+#endif
+#ifndef CYTHON_NCP_UNUSED
+# if CYTHON_COMPILING_IN_CPYTHON
+#  define CYTHON_NCP_UNUSED
+# else
+#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
+# endif
+#endif
+#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
+#ifdef _MSC_VER
+    #ifndef _MSC_STDINT_H_
+        #if _MSC_VER < 1300
+           typedef unsigned char     uint8_t;
+           typedef unsigned int      uint32_t;
+        #else
+           typedef unsigned __int8   uint8_t;
+           typedef unsigned __int32  uint32_t;
+        #endif
+    #endif
+#else
+   #include <stdint.h>
+#endif
+#ifndef CYTHON_FALLTHROUGH
+  #if defined(__cplusplus) && __cplusplus >= 201103L
+    #if __has_cpp_attribute(fallthrough)
+      #define CYTHON_FALLTHROUGH [[fallthrough]]
+    #elif __has_cpp_attribute(clang::fallthrough)
+      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
+    #elif __has_cpp_attribute(gnu::fallthrough)
+      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
+    #endif
+  #endif
+  #ifndef CYTHON_FALLTHROUGH
+    #if __has_attribute(fallthrough)
+      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
+    #else
+      #define CYTHON_FALLTHROUGH
+    #endif
+  #endif
+  #if defined(__clang__ ) && defined(__apple_build_version__)
+    #if __apple_build_version__ < 7000000
+      #undef  CYTHON_FALLTHROUGH
+      #define CYTHON_FALLTHROUGH
+    #endif
+  #endif
+#endif
+
+#ifndef CYTHON_INLINE
+  #if defined(__clang__)
+    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
+  #elif defined(__GNUC__)
+    #define CYTHON_INLINE __inline__
+  #elif defined(_MSC_VER)
+    #define CYTHON_INLINE __inline
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_INLINE inline
+  #else
+    #define CYTHON_INLINE
+  #endif
+#endif
+
+#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
+  #define Py_OptimizeFlag 0
+#endif
+#define __PYX_BUILD_PY_SSIZE_T "n"
+#define CYTHON_FORMAT_SSIZE_T "z"
+#if PY_MAJOR_VERSION < 3
+  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
+          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+  #define __Pyx_DefaultClassType PyClass_Type
+#else
+  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
+          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
+  #define __Pyx_DefaultClassType PyType_Type
+#endif
+#ifndef Py_TPFLAGS_CHECKTYPES
+  #define Py_TPFLAGS_CHECKTYPES 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_INDEX
+  #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
+  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_FINALIZE
+  #define Py_TPFLAGS_HAVE_FINALIZE 0
+#endif
+#ifndef METH_STACKLESS
+  #define METH_STACKLESS 0
+#endif
+#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
+  #ifndef METH_FASTCALL
+     #define METH_FASTCALL 0x80
+  #endif
+  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
+  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
+                                                          Py_ssize_t nargs, PyObject *kwnames);
+#else
+  #define __Pyx_PyCFunctionFast _PyCFunctionFast
+  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
+#endif
+#if CYTHON_FAST_PYCCALL
+#define __Pyx_PyFastCFunction_Check(func)\
+    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
+#else
+#define __Pyx_PyFastCFunction_Check(func) 0
+#endif
+#if CYTHON_USE_DICT_VERSIONS
+#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
+#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
+    (version_var) = __PYX_GET_DICT_VERSION(dict);\
+    (cache_var) = (value);
+#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
+        static PY_UINT64_T __pyx_dict_version = 0;\
+        static PyObject *__pyx_dict_cached_value = NULL;\
+        if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
+            (VAR) = __pyx_dict_cached_value;\
+        } else {\
+            (VAR) = __pyx_dict_cached_value = (LOOKUP);\
+            __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
+        }\
+    }
+#else
+#define __PYX_GET_DICT_VERSION(dict)  (0)
+#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
+#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
+  #define PyObject_Malloc(s)   PyMem_Malloc(s)
+  #define PyObject_Free(p)     PyMem_Free(p)
+  #define PyObject_Realloc(p)  PyMem_Realloc(p)
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
+  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
+  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
+  #define PyMem_RawFree(p)             PyMem_Free(p)
+#endif
+#if CYTHON_COMPILING_IN_PYSTON
+  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
+  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
+#else
+  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
+  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
+#endif
+#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
+  #define __Pyx_PyThreadState_Current PyThreadState_GET()
+#elif PY_VERSION_HEX >= 0x03060000
+  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
+#elif PY_VERSION_HEX >= 0x03000000
+  #define __Pyx_PyThreadState_Current PyThreadState_GET()
+#else
+  #define __Pyx_PyThreadState_Current _PyThreadState_Current
+#endif
+#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
+#include "pythread.h"
+#define Py_tss_NEEDS_INIT 0
+typedef int Py_tss_t;
+static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
+  *key = PyThread_create_key();
+  return 0; // PyThread_create_key reports success always
+}
+static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
+  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
+  *key = Py_tss_NEEDS_INIT;
+  return key;
+}
+static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
+  PyObject_Free(key);
+}
+static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
+  return *key != Py_tss_NEEDS_INIT;
+}
+static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
+  PyThread_delete_key(*key);
+  *key = Py_tss_NEEDS_INIT;
+}
+static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
+  return PyThread_set_key_value(*key, value);
+}
+static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
+  return PyThread_get_key_value(*key);
+}
+#endif // TSS (Thread Specific Storage) API
+#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
+#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
+#else
+#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
+#endif
+#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
+  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
+  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
+#else
+  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
+  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
+#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
+#else
+#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
+#endif
+#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
+  #define CYTHON_PEP393_ENABLED 1
+  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
+                                              0 : _PyUnicode_Ready((PyObject *)(op)))
+  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
+  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
+  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
+  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
+  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
+  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
+  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
+  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
+#else
+  #define CYTHON_PEP393_ENABLED 0
+  #define PyUnicode_1BYTE_KIND  1
+  #define PyUnicode_2BYTE_KIND  2
+  #define PyUnicode_4BYTE_KIND  4
+  #define __Pyx_PyUnicode_READY(op)       (0)
+  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
+  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
+  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
+  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
+  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
+  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
+  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
+  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
+#endif
+#if CYTHON_COMPILING_IN_PYPY
+  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
+#else
+  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
+      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
+  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
+  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
+#endif
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
+  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
+#endif
+#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
+#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
+#if PY_MAJOR_VERSION >= 3
+  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
+#else
+  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
+#endif
+#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
+  #define PyObject_ASCII(o)            PyObject_Repr(o)
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyBaseString_Type            PyUnicode_Type
+  #define PyStringObject               PyUnicodeObject
+  #define PyString_Type                PyUnicode_Type
+  #define PyString_Check               PyUnicode_Check
+  #define PyString_CheckExact          PyUnicode_CheckExact
+  #define PyObject_Unicode             PyObject_Str
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
+  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
+#else
+  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
+  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
+#endif
+#ifndef PySet_CheckExact
+  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
+#endif
+#if CYTHON_ASSUME_SAFE_MACROS
+  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
+#else
+  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyIntObject                  PyLongObject
+  #define PyInt_Type                   PyLong_Type
+  #define PyInt_Check(op)              PyLong_Check(op)
+  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
+  #define PyInt_FromString             PyLong_FromString
+  #define PyInt_FromUnicode            PyLong_FromUnicode
+  #define PyInt_FromLong               PyLong_FromLong
+  #define PyInt_FromSize_t             PyLong_FromSize_t
+  #define PyInt_FromSsize_t            PyLong_FromSsize_t
+  #define PyInt_AsLong                 PyLong_AsLong
+  #define PyInt_AS_LONG                PyLong_AS_LONG
+  #define PyInt_AsSsize_t              PyLong_AsSsize_t
+  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
+  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+  #define PyNumber_Int                 PyNumber_Long
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define PyBoolObject                 PyLongObject
+#endif
+#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
+  #ifndef PyUnicode_InternFromString
+    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
+  #endif
+#endif
+#if PY_VERSION_HEX < 0x030200A4
+  typedef long Py_hash_t;
+  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
+#else
+  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
+#endif
+#if PY_MAJOR_VERSION >= 3
+  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
+#else
+  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
+#endif
+#if CYTHON_USE_ASYNC_SLOTS
+  #if PY_VERSION_HEX >= 0x030500B1
+    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
+    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
+  #else
+    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
+  #endif
+#else
+  #define __Pyx_PyType_AsAsync(obj) NULL
+#endif
+#ifndef __Pyx_PyAsyncMethodsStruct
+    typedef struct {
+        unaryfunc am_await;
+        unaryfunc am_aiter;
+        unaryfunc am_anext;
+    } __Pyx_PyAsyncMethodsStruct;
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+  #define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#ifdef NAN
+#define __PYX_NAN() ((float) NAN)
+#else
+static CYTHON_INLINE float __PYX_NAN() {
+  float value;
+  memset(&value, 0xFF, sizeof(value));
+  return value;
+}
+#endif
+#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
+#define __Pyx_truncl trunc
+#else
+#define __Pyx_truncl truncl
+#endif
+
+
+#define __PYX_ERR(f_index, lineno, Ln_error) \
+{ \
+  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
+}
+
+#ifndef __PYX_EXTERN_C
+  #ifdef __cplusplus
+    #define __PYX_EXTERN_C extern "C"
+  #else
+    #define __PYX_EXTERN_C extern
+  #endif
+#endif
+
+#define __PYX_HAVE__asyncpg__protocol__protocol
+#define __PYX_HAVE_API__asyncpg__protocol__protocol
+/* Early includes */
+#include <stdint.h>
+#include "debug.h"
+#include <string.h>
+#include <stdio.h>
+#include "pythread.h"
+#include "record/recordobj.h"
+#include "./hton.h"
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
+                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
+
+#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
+#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
+#define __PYX_DEFAULT_STRING_ENCODING ""
+#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
+#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
+#define __Pyx_uchar_cast(c) ((unsigned char)c)
+#define __Pyx_long_cast(x) ((long)x)
+#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
+    (sizeof(type) < sizeof(Py_ssize_t))  ||\
+    (sizeof(type) > sizeof(Py_ssize_t) &&\
+          likely(v < (type)PY_SSIZE_T_MAX ||\
+                 v == (type)PY_SSIZE_T_MAX)  &&\
+          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
+                                v == (type)PY_SSIZE_T_MIN)))  ||\
+    (sizeof(type) == sizeof(Py_ssize_t) &&\
+          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
+                               v == (type)PY_SSIZE_T_MAX)))  )
+static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
+    return (size_t) i < (size_t) limit;
+}
+#if defined (__cplusplus) && __cplusplus >= 201103L
+    #include <cstdlib>
+    #define __Pyx_sst_abs(value) std::abs(value)
+#elif SIZEOF_INT >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) abs(value)
+#elif SIZEOF_LONG >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) labs(value)
+#elif defined (_MSC_VER)
+    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define __Pyx_sst_abs(value) llabs(value)
+#elif defined (__GNUC__)
+    #define __Pyx_sst_abs(value) __builtin_llabs(value)
+#else
+    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
+#endif
+static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
+static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
+#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
+#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
+#define __Pyx_PyBytes_FromString        PyBytes_FromString
+#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
+#if PY_MAJOR_VERSION < 3
+    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
+    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
+#else
+    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
+    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
+#endif
+#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
+#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
+#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
+#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
+#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
+#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
+#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
+static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
+    const Py_UNICODE *u_end = u;
+    while (*u_end++) ;
+    return (size_t)(u_end - u - 1);
+}
+#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
+#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
+#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
+#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
+#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
+static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
+#define __Pyx_PySequence_Tuple(obj)\
+    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+#if CYTHON_ASSUME_SAFE_MACROS
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+#else
+#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
+#endif
+#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
+#if PY_MAJOR_VERSION >= 3
+#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
+#else
+#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
+#endif
+#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
+#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+static int __Pyx_sys_getdefaultencoding_not_ascii;
+static int __Pyx_init_sys_getdefaultencoding_params(void) {
+    PyObject* sys;
+    PyObject* default_encoding = NULL;
+    PyObject* ascii_chars_u = NULL;
+    PyObject* ascii_chars_b = NULL;
+    const char* default_encoding_c;
+    sys = PyImport_ImportModule("sys");
+    if (!sys) goto bad;
+    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
+    Py_DECREF(sys);
+    if (!default_encoding) goto bad;
+    default_encoding_c = PyBytes_AsString(default_encoding);
+    if (!default_encoding_c) goto bad;
+    if (strcmp(default_encoding_c, "ascii") == 0) {
+        __Pyx_sys_getdefaultencoding_not_ascii = 0;
+    } else {
+        char ascii_chars[128];
+        int c;
+        for (c = 0; c < 128; c++) {
+            ascii_chars[c] = c;
+        }
+        __Pyx_sys_getdefaultencoding_not_ascii = 1;
+        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
+        if (!ascii_chars_u) goto bad;
+        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
+        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
+            PyErr_Format(
+                PyExc_ValueError,
+                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
+                default_encoding_c);
+            goto bad;
+        }
+        Py_DECREF(ascii_chars_u);
+        Py_DECREF(ascii_chars_b);
+    }
+    Py_DECREF(default_encoding);
+    return 0;
+bad:
+    Py_XDECREF(default_encoding);
+    Py_XDECREF(ascii_chars_u);
+    Py_XDECREF(ascii_chars_b);
+    return -1;
+}
+#endif
+#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
+#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
+#else
+#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
+#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+static char* __PYX_DEFAULT_STRING_ENCODING;
+static int __Pyx_init_sys_getdefaultencoding_params(void) {
+    PyObject* sys;
+    PyObject* default_encoding = NULL;
+    char* default_encoding_c;
+    sys = PyImport_ImportModule("sys");
+    if (!sys) goto bad;
+    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
+    Py_DECREF(sys);
+    if (!default_encoding) goto bad;
+    default_encoding_c = PyBytes_AsString(default_encoding);
+    if (!default_encoding_c) goto bad;
+    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
+    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
+    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
+    Py_DECREF(default_encoding);
+    return 0;
+bad:
+    Py_XDECREF(default_encoding);
+    return -1;
+}
+#endif
+#endif
+
+
+/* Test for GCC > 2.95 */
+#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
+  #define likely(x)   __builtin_expect(!!(x), 1)
+  #define unlikely(x) __builtin_expect(!!(x), 0)
+#else /* !__GNUC__ or GCC < 2.95 */
+  #define likely(x)   (x)
+  #define unlikely(x) (x)
+#endif /* __GNUC__ */
+static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
+
+static PyObject *__pyx_m = NULL;
+static PyObject *__pyx_d;
+static PyObject *__pyx_b;
+static PyObject *__pyx_cython_runtime = NULL;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static PyObject *__pyx_empty_unicode;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+  "asyncpg/protocol/protocol.pyx",
+  "asyncpg/protocol/settings.pyx",
+  "stringsource",
+  "asyncpg/protocol/codecs/base.pyx",
+  "asyncpg/protocol/codecs/array.pyx",
+  "asyncpg/protocol/coreproto.pyx",
+  "asyncpg/protocol/prepared_stmt.pyx",
+  "asyncpg/protocol/encodings.pyx",
+  "asyncpg/protocol/codecs/pgproto.pyx",
+  "asyncpg/protocol/codecs/range.pyx",
+  "asyncpg/protocol/codecs/record.pyx",
+  "asyncpg/protocol/coreproto.pxd",
+  "asyncpg/protocol/prepared_stmt.pxd",
+  "asyncpg/protocol/protocol.pxd",
+  "asyncpg/pgproto/./frb.pxd",
+  "asyncpg/pgproto/./buffer.pxd",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/type.pxd",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/bool.pxd",
+  ".eggs/Cython-0.29-py3.6-linux-x86_64.egg/Cython/Includes/cpython/complex.pxd",
+  "asyncpg/protocol/pgtypes.pxi",
+};
+
+/*--- Type declarations ---*/
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext;
+struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec;
+struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig;
+struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings;
+struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol;
+struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState;
+struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close;
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation;
+struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer;
+
+/* "asyncpg/pgproto/frb.pxd":10
+ * cdef:
+ * 
+ *     struct FRBuffer:             # <<<<<<<<<<<<<<
+ *         const char* buf
+ *         ssize_t len
+ */
+struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer {
+  char const *buf;
+  Py_ssize_t len;
+};
+
+/* "asyncpg/pgproto/buffer.pxd":56
+ * 
+ * 
+ * ctypedef const char * (*try_consume_message_method)(object, ssize_t*)             # <<<<<<<<<<<<<<
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ * ctypedef int32_t (*take_message_method)(object) except -1
+ */
+typedef char const *(*__pyx_t_7asyncpg_7pgproto_7pgproto_try_consume_message_method)(PyObject *, Py_ssize_t *);
+
+/* "asyncpg/pgproto/buffer.pxd":57
+ * 
+ * ctypedef const char * (*try_consume_message_method)(object, ssize_t*)
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1             # <<<<<<<<<<<<<<
+ * ctypedef int32_t (*take_message_method)(object) except -1
+ * ctypedef char (*get_message_type_method)(object)
+ */
+typedef int32_t (*__pyx_t_7asyncpg_7pgproto_7pgproto_take_message_type_method)(PyObject *, char);
+
+/* "asyncpg/pgproto/buffer.pxd":58
+ * ctypedef const char * (*try_consume_message_method)(object, ssize_t*)
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ * ctypedef int32_t (*take_message_method)(object) except -1             # <<<<<<<<<<<<<<
+ * ctypedef char (*get_message_type_method)(object)
+ * 
+ */
+typedef int32_t (*__pyx_t_7asyncpg_7pgproto_7pgproto_take_message_method)(PyObject *);
+
+/* "asyncpg/pgproto/buffer.pxd":59
+ * ctypedef int32_t (*take_message_type_method)(object, char) except -1
+ * ctypedef int32_t (*take_message_method)(object) except -1
+ * ctypedef char (*get_message_type_method)(object)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+typedef char (*__pyx_t_7asyncpg_7pgproto_7pgproto_get_message_type_method)(PyObject *);
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":14
+ * 
+ * 
+ * ctypedef object (*encode_func)(CodecContext settings,             # <<<<<<<<<<<<<<
+ *                                WriteBuffer buf,
+ *                                object obj)
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_7pgproto_7pgproto_encode_func)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":18
+ *                                object obj)
+ * 
+ * ctypedef object (*decode_func)(CodecContext settings,             # <<<<<<<<<<<<<<
+ *                                FRBuffer *buf)
+ * 
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_7pgproto_7pgproto_decode_func)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec;
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_core_codec;
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_any_core_codec;
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_register_core_codec;
+
+/* "asyncpg/protocol/codecs/base.pxd":25
+ * 
+ * 
+ * cdef enum CodecType:             # <<<<<<<<<<<<<<
+ *     CODEC_UNDEFINED = 0
+ *     CODEC_C         = 1
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType {
+  __pyx_e_7asyncpg_8protocol_8protocol_CODEC_UNDEFINED = 0,
+  __pyx_e_7asyncpg_8protocol_8protocol_CODEC_C = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_CODEC_PY = 2,
+  __pyx_e_7asyncpg_8protocol_8protocol_CODEC_ARRAY = 3,
+  __pyx_e_7asyncpg_8protocol_8protocol_CODEC_COMPOSITE = 4,
+  __pyx_e_7asyncpg_8protocol_8protocol_CODEC_RANGE = 5
+};
+
+/* "asyncpg/protocol/codecs/base.pxd":34
+ * 
+ * 
+ * cdef enum ServerDataFormat:             # <<<<<<<<<<<<<<
+ *     PG_FORMAT_ANY = -1
+ *     PG_FORMAT_TEXT = 0
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat {
+  __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY = -1L,
+  __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT = 0,
+  __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY = 1
+};
+
+/* "asyncpg/protocol/codecs/base.pxd":40
+ * 
+ * 
+ * cdef enum ClientExchangeFormat:             # <<<<<<<<<<<<<<
+ *     PG_XFORMAT_OBJECT = 1
+ *     PG_XFORMAT_TUPLE = 2
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat {
+  __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE = 2
+};
+
+/* "asyncpg/protocol/coreproto.pxd":8
+ * 
+ * 
+ * cdef enum ConnectionStatus:             # <<<<<<<<<<<<<<
+ *     CONNECTION_OK = 1
+ *     CONNECTION_BAD = 2
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus {
+  __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_OK = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD = 2,
+  __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_STARTED = 3
+};
+
+/* "asyncpg/protocol/coreproto.pxd":14
+ * 
+ * 
+ * cdef enum ProtocolState:             # <<<<<<<<<<<<<<
+ *     PROTOCOL_IDLE = 0
+ * 
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState {
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE = 0,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_ERROR_CONSUME = 2,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CANCELLED = 3,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_TERMINATING = 4,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_AUTH = 10,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_PREPARE = 11,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE = 12,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE_MANY = 13,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CLOSE_STMT_PORTAL = 14,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_SIMPLE_QUERY = 15,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_EXECUTE = 16,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND = 17,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT = 18,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DATA = 19,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DONE = 20,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN = 21,
+  __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN_DATA = 22
+};
+
+/* "asyncpg/protocol/coreproto.pxd":37
+ * 
+ * 
+ * cdef enum AuthenticationMessage:             # <<<<<<<<<<<<<<
+ *     AUTH_SUCCESSFUL = 0
+ *     AUTH_REQUIRED_KERBEROS = 2
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage {
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_SUCCESSFUL = 0,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_KERBEROS = 2,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_PASSWORD = 3,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_PASSWORDMD5 = 5,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_SCMCRED = 6,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_GSS = 7,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_GSS_CONTINUE = 8,
+  __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_SSPI = 9
+};
+
+/* "asyncpg/protocol/coreproto.pxd":57
+ * 
+ * 
+ * cdef enum ResultType:             # <<<<<<<<<<<<<<
+ *     RESULT_OK = 1
+ *     RESULT_FAILED = 2
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType {
+  __pyx_e_7asyncpg_8protocol_8protocol_RESULT_OK = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED = 2
+};
+
+/* "asyncpg/protocol/coreproto.pxd":62
+ * 
+ * 
+ * cdef enum TransactionStatus:             # <<<<<<<<<<<<<<
+ *     PQTRANS_IDLE = 0                 # connection idle
+ *     PQTRANS_ACTIVE = 1               # command in progress
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus {
+  __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_IDLE = 0,
+  __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_ACTIVE = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_INTRANS = 2,
+  __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_INERROR = 3,
+  __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_UNKNOWN = 4
+};
+
+/* "asyncpg/protocol/codecs/base.pxd":8
+ * 
+ * 
+ * ctypedef object (*encode_func)(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                                WriteBuffer buf,
+ *                                object obj)
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_encode_func)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+
+/* "asyncpg/protocol/codecs/base.pxd":12
+ *                                object obj)
+ * 
+ * ctypedef object (*decode_func)(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                                FRBuffer *buf)
+ * 
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_decode_func)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+
+/* "asyncpg/protocol/codecs/base.pxd":15
+ *                                FRBuffer *buf)
+ * 
+ * ctypedef object (*codec_encode_func)(Codec codec,             # <<<<<<<<<<<<<<
+ *                                      ConnectionSettings settings,
+ *                                      WriteBuffer buf,
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+
+/* "asyncpg/protocol/codecs/base.pxd":20
+ *                                      object obj)
+ * 
+ * ctypedef object (*codec_decode_func)(Codec codec,             # <<<<<<<<<<<<<<
+ *                                      ConnectionSettings settings,
+ *                                      FRBuffer *buf)
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+
+/* "asyncpg/protocol/settings.pxd":28
+ *     cpdef inline set_builtin_type_codec(
+ *         self, typeoid, typename, typeschema, typekind, alias_to, format)
+ *     cpdef inline Codec get_data_codec(             # <<<<<<<<<<<<<<
+ *         self, uint32_t oid, ServerDataFormat format=*)
+ */
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec {
+  int __pyx_n;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat format;
+};
+
+/* "asyncpg/protocol/coreproto.pxd":70
+ * 
+ * 
+ * ctypedef object (*decode_row_method)(object, const char*, ssize_t)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_decode_row_method)(PyObject *, char const *, Py_ssize_t);
+
+/* "asyncpg/protocol/codecs/array.pyx":658
+ * 
+ * 
+ * cdef enum _ArrayParseState:             # <<<<<<<<<<<<<<
+ *     APS_START = 1
+ *     APS_STRIDE_STARTED = 2
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol__ArrayParseState {
+  __pyx_e_7asyncpg_8protocol_8protocol_APS_START = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED = 2,
+  __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DONE = 3,
+  __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DELIMITED = 4,
+  __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED = 5,
+  __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_DELIMITED = 6
+};
+
+/* "asyncpg/protocol/codecs/range.pyx":18
+ * 
+ * 
+ * cdef enum _RangeArgumentType:             # <<<<<<<<<<<<<<
+ *     _RANGE_ARGUMENT_INVALID = 0
+ *     _RANGE_ARGUMENT_TUPLE = 1
+ */
+enum __pyx_t_7asyncpg_8protocol_8protocol__RangeArgumentType {
+  __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_INVALID = 0,
+  __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_TUPLE = 1,
+  __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_RANGE = 2
+};
+
+/* "asyncpg/protocol/codecs/base.pyx":726
+ * 
+ * 
+ * cdef inline Codec get_core_codec(             # <<<<<<<<<<<<<<
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ */
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_core_codec {
+  int __pyx_n;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat xformat;
+};
+
+/* "asyncpg/protocol/codecs/base.pyx":745
+ * 
+ * 
+ * cdef inline Codec get_any_core_codec(             # <<<<<<<<<<<<<<
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ */
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_any_core_codec {
+  int __pyx_n;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat xformat;
+};
+
+/* "asyncpg/protocol/codecs/base.pyx":766
+ * 
+ * 
+ * cdef register_core_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                          encode_func encode,
+ *                          decode_func decode,
+ */
+struct __pyx_opt_args_7asyncpg_8protocol_8protocol_register_core_codec {
+  int __pyx_n;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat xformat;
+};
+
+/* "asyncpg/protocol/codecs/array.pyx":21
+ * 
+ * 
+ * ctypedef object (*encode_func_ex)(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                                   WriteBuffer buf,
+ *                                   object obj,
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, void const *);
+
+/* "asyncpg/protocol/codecs/array.pyx":27
+ * 
+ * 
+ * ctypedef object (*decode_func_ex)(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                                   FRBuffer *buf,
+ *                                   const void *arg)
+ */
+typedef PyObject *(*__pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, void const *);
+
+/* "asyncpg/pgproto/buffer.pxd":8
+ * 
+ * 
+ * cdef class WriteBuffer:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         # Preallocated small buffer
+ */
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_vtab;
+  int _smallbuf_inuse;
+  char _smallbuf[0x400];
+  char *_buf;
+  Py_ssize_t _size;
+  Py_ssize_t _length;
+  int _view_count;
+  int _message_mode;
+};
+
+
+/* "asyncpg/pgproto/buffer.pxd":62
+ * 
+ * 
+ * cdef class ReadBuffer:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         # A deque of buffers (bytes objects)
+ */
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_vtab;
+  PyObject *_bufs;
+  PyObject *_bufs_append;
+  PyObject *_bufs_popleft;
+  PyObject *_buf0;
+  PyObject *_buf0_prev;
+  int32_t _bufs_len;
+  Py_ssize_t _pos0;
+  Py_ssize_t _len0;
+  Py_ssize_t _length;
+  char _current_message_type;
+  int32_t _current_message_len;
+  Py_ssize_t _current_message_len_unread;
+  int _current_message_ready;
+};
+
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":8
+ * 
+ * 
+ * cdef class CodecContext:             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef get_text_codec(self)
+ */
+struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_vtab;
+};
+
+
+/* "asyncpg/protocol/codecs/base.pxd":45
+ * 
+ * 
+ * cdef class Codec:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint32_t        oid
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_Codec *__pyx_vtab;
+  uint32_t oid;
+  PyObject *name;
+  PyObject *schema;
+  PyObject *kind;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType type;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat format;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat xformat;
+  __pyx_t_7asyncpg_8protocol_8protocol_encode_func c_encoder;
+  __pyx_t_7asyncpg_8protocol_8protocol_decode_func c_decoder;
+  PyObject *py_encoder;
+  PyObject *py_decoder;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *element_codec;
+  Py_UCS4 element_delimiter;
+  PyObject *element_type_oids;
+  PyObject *element_names;
+  PyObject *record_desc;
+  PyObject *element_codecs;
+  __pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func encoder;
+  __pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func decoder;
+};
+
+
+/* "asyncpg/protocol/codecs/base.pxd":164
+ * 
+ * 
+ * cdef class DataCodecConfig:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         dict _derived_type_codecs
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_vtab;
+  PyObject *_derived_type_codecs;
+  PyObject *_custom_type_codecs;
+};
+
+
+/* "asyncpg/protocol/settings.pxd":8
+ * 
+ * 
+ * cdef class ConnectionSettings(pgproto.CodecContext):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         str _encoding
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext __pyx_base;
+  PyObject *_encoding;
+  PyObject *_codec;
+  PyObject *_settings;
+  int _is_utf8;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *_data_codecs;
+};
+
+
+/* "asyncpg/protocol/coreproto.pxd":73
+ * 
+ * 
+ * cdef class CoreProtocol:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ReadBuffer buffer
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_vtab;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *buffer;
+  int _skip_discard;
+  int _discard_data;
+  PyObject *_execute_iter;
+  PyObject *_execute_portal_name;
+  PyObject *_execute_stmt_name;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus con_status;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState state;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus xact_status;
+  PyObject *encoding;
+  PyObject *transport;
+  PyObject *con_params;
+  int32_t backend_pid;
+  int32_t backend_secret;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType result_type;
+  PyObject *result;
+  PyObject *result_param_desc;
+  PyObject *result_row_desc;
+  PyObject *result_status_msg;
+  int result_execute_completed;
+};
+
+
+/* "asyncpg/protocol/prepared_stmt.pxd":8
+ * 
+ * 
+ * cdef class PreparedStatementState:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         readonly str name
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState {
+  PyObject_HEAD
+  struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_vtab;
+  PyObject *name;
+  PyObject *query;
+  int closed;
+  int refs;
+  PyObject *row_desc;
+  PyObject *parameters_desc;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *settings;
+  int16_t args_num;
+  int have_text_args;
+  PyObject *args_codecs;
+  int16_t cols_num;
+  PyObject *cols_desc;
+  int have_text_cols;
+  PyObject *rows_codecs;
+};
+
+
+/* "asyncpg/protocol/protocol.pxd":30
+ * 
+ * 
+ * cdef class BaseProtocol(CoreProtocol):             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol __pyx_base;
+  PyObject *loop;
+  PyObject *address;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *settings;
+  PyObject *cancel_sent_waiter;
+  PyObject *cancel_waiter;
+  PyObject *waiter;
+  int return_extra;
+  PyObject *create_future;
+  PyObject *timeout_handle;
+  PyObject *timeout_callback;
+  PyObject *completed_callback;
+  PyObject *conref;
+  int is_reading;
+  PyObject *last_query;
+  int writing_paused;
+  int closing;
+  uint64_t queries_count;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *statement;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":141
+ * 
+ *     @cython.iterable_coroutine
+ *     async def prepare(self, stmt_name, query, timeout,             # <<<<<<<<<<<<<<
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare {
+  PyObject_HEAD
+  PyObject *__pyx_v_ex;
+  PyObject *__pyx_v_query;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state;
+  PyObject *__pyx_v_stmt_name;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":166
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                            str portal_name, int limit, return_extra,
+ *                            timeout):
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute {
+  PyObject_HEAD
+  PyObject *__pyx_v_args;
+  PyObject *__pyx_v_args_buf;
+  PyObject *__pyx_v_ex;
+  int __pyx_v_limit;
+  PyObject *__pyx_v_portal_name;
+  PyObject *__pyx_v_return_extra;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":199
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute_many(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                                 str portal_name, timeout):
+ * 
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many {
+  PyObject_HEAD
+  PyObject *__pyx_v_arg_bufs;
+  PyObject *__pyx_v_args;
+  PyObject *__pyx_v_data_gen;
+  PyObject *__pyx_v_ex;
+  PyObject *__pyx_v_genexpr;
+  PyObject *__pyx_v_portal_name;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":214
+ *         # this generator expression to keep the memory pressure under
+ *         # control.
+ *         data_gen = (state._encode_bind_msg(b) for b in args)             # <<<<<<<<<<<<<<
+ *         arg_bufs = iter(data_gen)
+ * 
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr {
+  PyObject_HEAD
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *__pyx_outer_scope;
+  PyObject *__pyx_v_b;
+  PyObject *__pyx_t_0;
+  Py_ssize_t __pyx_t_1;
+  PyObject *(*__pyx_t_2)(PyObject *);
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":235
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                    str portal_name, timeout):
+ * 
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind {
+  PyObject_HEAD
+  PyObject *__pyx_v_args;
+  PyObject *__pyx_v_args_buf;
+  PyObject *__pyx_v_ex;
+  PyObject *__pyx_v_portal_name;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":264
+ * 
+ *     @cython.iterable_coroutine
+ *     async def execute(self, PreparedStatementState state,             # <<<<<<<<<<<<<<
+ *                       str portal_name, int limit, return_extra,
+ *                       timeout):
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute {
+  PyObject_HEAD
+  PyObject *__pyx_v_ex;
+  int __pyx_v_limit;
+  PyObject *__pyx_v_portal_name;
+  PyObject *__pyx_v_return_extra;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":294
+ * 
+ *     @cython.iterable_coroutine
+ *     async def query(self, query, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query {
+  PyObject_HEAD
+  PyObject *__pyx_v_ex;
+  PyObject *__pyx_v_query;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":319
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_out(self, copy_stmt, sink, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out {
+  PyObject_HEAD
+  PyObject *__pyx_v_buffer;
+  PyObject *__pyx_v_copy_stmt;
+  PyObject *__pyx_v_done;
+  PyObject *__pyx_v_ex;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  PyObject *__pyx_v_sink;
+  PyObject *__pyx_v_status_msg;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_timer;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+  PyObject *__pyx_t_6;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":374
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_in(self, copy_stmt, reader, data,             # <<<<<<<<<<<<<<
+ *                       records, PreparedStatementState record_stmt, timeout):
+ *         cdef:
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in {
+  PyObject_HEAD
+  PyObject *__pyx_v_aiter;
+  PyObject *__pyx_v_chunk;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec;
+  PyObject *__pyx_v_codecs;
+  PyObject *__pyx_v_copy_stmt;
+  PyObject *__pyx_v_data;
+  PyObject *__pyx_v_e;
+  Py_ssize_t __pyx_v_i;
+  PyObject *__pyx_v_item;
+  PyObject *__pyx_v_iterator;
+  Py_ssize_t __pyx_v_num_cols;
+  PyObject *__pyx_v_reader;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_record_stmt;
+  PyObject *__pyx_v_records;
+  PyObject *__pyx_v_row;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings;
+  PyObject *__pyx_v_status_msg;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_timer;
+  PyObject *__pyx_v_waiter;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_wbuf;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  Py_ssize_t __pyx_t_4;
+  PyObject *(*__pyx_t_5)(PyObject *);
+  PyObject *__pyx_t_6;
+  PyObject *__pyx_t_7;
+  PyObject *__pyx_t_8;
+  PyObject *__pyx_t_9;
+  PyObject *__pyx_t_10;
+  PyObject *__pyx_t_11;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":493
+ * 
+ *     @cython.iterable_coroutine
+ *     async def close_statement(self, PreparedStatementState state, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement {
+  PyObject_HEAD
+  PyObject *__pyx_v_ex;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_v_waiter;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+  PyObject *__pyx_t_3;
+  PyObject *__pyx_t_4;
+  PyObject *__pyx_t_5;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":533
+ * 
+ *     @cython.iterable_coroutine
+ *     async def close(self, timeout):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             return
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close {
+  PyObject_HEAD
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+  PyObject *__pyx_v_timeout;
+  PyObject *__pyx_t_0;
+  PyObject *__pyx_t_1;
+  PyObject *__pyx_t_2;
+};
+
+
+/* "asyncpg/protocol/protocol.pyx":669
+ * 
+ *     @cython.iterable_coroutine
+ *     async def _wait_for_cancellation(self):             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation {
+  PyObject_HEAD
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self;
+};
+
+
+
+/* "asyncpg/pgproto/buffer.pxd":8
+ * 
+ * 
+ * cdef class WriteBuffer:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         # Preallocated small buffer
+ */
+
+struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer {
+  PyObject *(*len)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*_check_readonly)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*_ensure_alloced)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t);
+  PyObject *(*_reallocate)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, Py_ssize_t);
+  PyObject *(*start_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+  PyObject *(*end_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*write_buffer)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*write_byte)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+  PyObject *(*write_bytes)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*write_bytestring)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*write_str)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, PyObject *);
+  PyObject *(*write_utf8)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*write_cstr)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char const *, Py_ssize_t);
+  PyObject *(*write_int16)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int16_t);
+  PyObject *(*write_int32)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t);
+  PyObject *(*write_int64)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int64_t);
+  PyObject *(*write_float)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, float);
+  PyObject *(*write_double)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, double);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*new_message)(char);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*new)(void);
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer;
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+
+
+/* "asyncpg/pgproto/buffer.pxd":62
+ * 
+ * 
+ * cdef class ReadBuffer:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         # A deque of buffers (bytes objects)
+ */
+
+struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer {
+  PyObject *(*len)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char (*get_message_type)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int32_t (*get_message_length)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*read_utf8)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*feed_data)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, PyObject *);
+  PyObject *(*_ensure_first_buf)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*_switch_to_next_buf)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char (*read_byte)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char const *(*_try_read_bytes)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+  PyObject *(*_read_into)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char *, Py_ssize_t);
+  PyObject *(*_read_and_discard)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+  PyObject *(*read_bytes)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t);
+  int32_t (*read_int32)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int16_t (*read_int16)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*read_cstr)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int32_t (*take_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  int32_t (*take_message_type)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char);
+  int32_t (*put_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  char const *(*try_consume_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, Py_ssize_t *);
+  PyObject *(*consume_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*discard_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*redirect_messages)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, char);
+  PyObject *(*consume_messages)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *, char);
+  PyObject *(*finish_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  PyObject *(*_finish_message)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *(*new_message_parser)(PyObject *);
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer;
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *);
+
+
+/* "asyncpg/pgproto/codecs/__init__.pxd":8
+ * 
+ * 
+ * cdef class CodecContext:             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef get_text_codec(self)
+ */
+
+struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext {
+  PyObject *(*get_text_codec)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, int __pyx_skip_dispatch);
+  PyObject *(*is_encoding_utf8)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *);
+};
+static struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext;
+
+
+/* "asyncpg/protocol/codecs/base.pyx":19
+ * 
+ * @cython.final
+ * cdef class Codec:             # <<<<<<<<<<<<<<
+ * 
+ *     def __cinit__(self, uint32_t oid):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_Codec {
+  PyObject *(*init)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, PyObject *, PyObject *, PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, PyObject *, PyObject *, PyObject *, Py_UCS4);
+  PyObject *(*encode_scalar)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*encode_array)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*encode_array_text)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*encode_range)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*encode_composite)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*encode_in_python)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*decode_scalar)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*decode_array)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*decode_array_text)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*decode_range)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*decode_composite)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*decode_in_python)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*encode)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+  PyObject *(*decode)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+  PyObject *(*has_encoder)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+  PyObject *(*has_decoder)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+  PyObject *(*is_binary)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*copy)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*new_array_codec)(uint32_t, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, Py_UCS4);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*new_range_codec)(uint32_t, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*new_composite_codec)(uint32_t, PyObject *, PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, PyObject *, PyObject *, PyObject *);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*new_python_codec)(uint32_t, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat);
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_Codec *__pyx_vtabptr_7asyncpg_8protocol_8protocol_Codec;
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, PyObject *, PyObject *, PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, PyObject *, PyObject *, PyObject *, Py_UCS4);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_scalar(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array_text(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_range(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_composite(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_in_python(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_scalar(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array_text(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_range(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_composite(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_in_python(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_is_binary(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_copy(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_array_codec(uint32_t, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, Py_UCS4);
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_range_codec(uint32_t, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *);
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_composite_codec(uint32_t, PyObject *, PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, PyObject *, PyObject *, PyObject *);
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_python_codec(uint32_t, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat);
+
+
+/* "asyncpg/protocol/codecs/base.pyx":422
+ * 
+ * 
+ * cdef class DataCodecConfig:             # <<<<<<<<<<<<<<
+ *     def __init__(self, cache_key):
+ *         # Codec instance cache for derived types:
+ */
+
+struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_DataCodecConfig {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*get_codec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, uint32_t, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*get_any_local_codec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, uint32_t);
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_vtabptr_7asyncpg_8protocol_8protocol_DataCodecConfig;
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, uint32_t, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat);
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_any_local_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, uint32_t);
+
+
+/* "asyncpg/protocol/settings.pyx":12
+ * 
+ * @cython.final
+ * cdef class ConnectionSettings(pgproto.CodecContext):             # <<<<<<<<<<<<<<
+ * 
+ *     def __cinit__(self, conn_key):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_ConnectionSettings {
+  struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext __pyx_base;
+  PyObject *(*add_setting)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *);
+  PyObject *(*register_data_types)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, int __pyx_skip_dispatch);
+  PyObject *(*add_python_codec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
+  PyObject *(*remove_python_codec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
+  PyObject *(*clear_type_cache)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, int __pyx_skip_dispatch);
+  PyObject *(*set_builtin_type_codec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*get_data_codec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, uint32_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec *__pyx_optional_args);
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_vtabptr_7asyncpg_8protocol_8protocol_ConnectionSettings;
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_setting(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_register_data_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, int __pyx_skip_dispatch);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, int __pyx_skip_dispatch);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, uint32_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec *__pyx_optional_args);
+
+
+/* "asyncpg/protocol/coreproto.pyx":11
+ * 
+ * 
+ * cdef class CoreProtocol:             # <<<<<<<<<<<<<<
+ * 
+ *     def __init__(self, con_params):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol {
+  PyObject *(*_process__auth)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__prepare)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__bind_execute)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__bind_execute_many)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__close_stmt_portal)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__simple_query)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__bind)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__copy_out)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__copy_out_data)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__copy_in)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_process__copy_in_data)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char);
+  PyObject *(*_parse_msg_authentication)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_msg_parameter_status)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_msg_notification)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_msg_backend_key_data)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_msg_ready_for_query)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_data_msgs)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_copy_data_msgs)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_parse_msg_error_response)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_parse_msg_command_complete)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_write_copy_data_msg)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_write_copy_done_msg)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_write_copy_fail_msg)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_auth_password_message_cleartext)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_auth_password_message_md5)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_write)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_read_server_messages)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_push_result)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_reset_result)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_set_state)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState);
+  PyObject *(*_ensure_connected)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*_build_bind_message)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*_connect)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_prepare)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *);
+  PyObject *(*_send_bind_message)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t);
+  PyObject *(*_bind_execute)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t);
+  PyObject *(*_bind_execute_many)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, PyObject *);
+  PyObject *(*_bind)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *);
+  PyObject *(*_execute)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, int32_t);
+  PyObject *(*_close)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, int);
+  PyObject *(*_simple_query)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_copy_out)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_copy_in)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_terminate)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_decode_row)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char const *, Py_ssize_t);
+  PyObject *(*_on_result)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *);
+  PyObject *(*_on_notification)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, PyObject *);
+  PyObject *(*_on_notice)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+  PyObject *(*_set_server_parameter)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *);
+  PyObject *(*_on_connection_lost)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *);
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_vtabptr_7asyncpg_8protocol_8protocol_CoreProtocol;
+
+
+/* "asyncpg/protocol/prepared_stmt.pyx":12
+ * 
+ * @cython.final
+ * cdef class PreparedStatementState:             # <<<<<<<<<<<<<<
+ * 
+ *     def __cinit__(self, str name, str query, BaseProtocol protocol):
+ */
+
+struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_PreparedStatementState {
+  PyObject *(*_encode_bind_msg)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *);
+  PyObject *(*_init_codecs)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, int __pyx_skip_dispatch);
+  PyObject *(*_ensure_rows_decoder)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *);
+  PyObject *(*_ensure_args_encoder)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *);
+  PyObject *(*_set_row_desc)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *);
+  PyObject *(*_set_args_desc)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *);
+  PyObject *(*_decode_row)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, char const *, Py_ssize_t);
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_vtabptr_7asyncpg_8protocol_8protocol_PreparedStatementState;
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__init_codecs(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, int __pyx_skip_dispatch);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_rows_decoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_args_encoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_row_desc(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_args_desc(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *);
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__decode_row(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, char const *, Py_ssize_t);
+
+
+/* "asyncpg/protocol/protocol.pyx":75
+ * 
+ * 
+ * cdef class BaseProtocol(CoreProtocol):             # <<<<<<<<<<<<<<
+ *     def __init__(self, addr, connected_fut, con_params, loop):
+ *         # type of `con_params` is `_ConnectionParameters`
+ */
+
+struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol {
+  struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol __pyx_base;
+  PyObject *(*get_connection)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+  PyObject *(*_get_timeout_impl)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_check_state)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+  PyObject *(*_new_waiter)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_coreproto_error)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+  PyObject *(*_on_result__connect)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__prepare)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__bind_and_exec)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__close_stmt_or_portal)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__simple_query)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__bind)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__copy_out)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_on_result__copy_in)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_handle_waiter_on_connection_lost)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+  PyObject *(*_dispatch_result)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+  PyObject *(*resume_reading)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+  PyObject *(*pause_reading)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_vtabptr_7asyncpg_8protocol_8protocol_BaseProtocol;
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_pause_reading(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *);
+
+/* --- Runtime support code (head) --- */
+/* Refnanny.proto */
+#ifndef CYTHON_REFNANNY
+  #define CYTHON_REFNANNY 0
+#endif
+#if CYTHON_REFNANNY
+  typedef struct {
+    void (*INCREF)(void*, PyObject*, int);
+    void (*DECREF)(void*, PyObject*, int);
+    void (*GOTREF)(void*, PyObject*, int);
+    void (*GIVEREF)(void*, PyObject*, int);
+    void* (*SetupContext)(const char*, int, const char*);
+    void (*FinishContext)(void**);
+  } __Pyx_RefNannyAPIStruct;
+  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
+  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+#ifdef WITH_THREAD
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          if (acquire_gil) {\
+              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+              PyGILState_Release(__pyx_gilstate_save);\
+          } else {\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+          }
+#else
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+#endif
+  #define __Pyx_RefNannyFinishContext()\
+          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+  #define __Pyx_RefNannyDeclarations
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)
+  #define __Pyx_RefNannyFinishContext()
+  #define __Pyx_INCREF(r) Py_INCREF(r)
+  #define __Pyx_DECREF(r) Py_DECREF(r)
+  #define __Pyx_GOTREF(r)
+  #define __Pyx_GIVEREF(r)
+  #define __Pyx_XINCREF(r) Py_XINCREF(r)
+  #define __Pyx_XDECREF(r) Py_XDECREF(r)
+  #define __Pyx_XGOTREF(r)
+  #define __Pyx_XGIVEREF(r)
+#endif
+#define __Pyx_XDECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_XDECREF(tmp);\
+    } while (0)
+#define __Pyx_DECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_DECREF(tmp);\
+    } while (0)
+#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
+#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
+
+/* PyObjectGetAttrStr.proto */
+#if CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
+#else
+#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
+#endif
+
+/* GetBuiltinName.proto */
+static PyObject *__Pyx_GetBuiltinName(PyObject *name);
+
+/* dict_getitem_default.proto */
+static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value);
+
+/* PyObjectCall.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
+#else
+#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
+#endif
+
+/* UnpackUnboundCMethod.proto */
+typedef struct {
+    PyObject *type;
+    PyObject **method_name;
+    PyCFunction func;
+    PyObject *method;
+    int flag;
+} __Pyx_CachedCFunction;
+
+/* CallUnboundCMethod1.proto */
+static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
+#else
+#define __Pyx_CallUnboundCMethod1(cfunc, self, arg)  __Pyx__CallUnboundCMethod1(cfunc, self, arg)
+#endif
+
+/* CallUnboundCMethod2.proto */
+static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2);
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
+static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2);
+#else
+#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2)  __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
+#endif
+
+/* PyFunctionFastCall.proto */
+#if CYTHON_FAST_PYCALL
+#define __Pyx_PyFunction_FastCall(func, args, nargs)\
+    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
+#if 1 || PY_VERSION_HEX < 0x030600B1
+static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
+#else
+#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
+#endif
+#define __Pyx_BUILD_ASSERT_EXPR(cond)\
+    (sizeof(char [1 - 2*!(cond)]) - 1)
+#ifndef Py_MEMBER_SIZE
+#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
+#endif
+  static size_t __pyx_pyframe_localsplus_offset = 0;
+  #include "frameobject.h"
+  #define __Pxy_PyFrame_Initialize_Offsets()\
+    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
+     (void)(__pyx_pyframe_localsplus_offset = PyFrame_Type.tp_basicsize - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
+  #define __Pyx_PyFrame_GetLocalsplus(frame)\
+    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
+#endif
+
+/* PyObjectCallMethO.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
+#endif
+
+/* PyObjectCallNoArg.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
+#else
+#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
+#endif
+
+/* PyCFunctionFastCall.proto */
+#if CYTHON_FAST_PYCCALL
+static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
+#else
+#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
+#endif
+
+/* PyObjectCallOneArg.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
+
+/* RaiseDoubleKeywords.proto */
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
+
+/* ParseKeywords.proto */
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
+    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
+    const char* function_name);
+
+/* RaiseArgTupleInvalid.proto */
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
+
+/* GetModuleGlobalName.proto */
+#if CYTHON_USE_DICT_VERSIONS
+#define __Pyx_GetModuleGlobalName(var, name)  {\
+    static PY_UINT64_T __pyx_dict_version = 0;\
+    static PyObject *__pyx_dict_cached_value = NULL;\
+    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
+        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
+        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
+}
+#define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
+    PY_UINT64_T __pyx_dict_version;\
+    PyObject *__pyx_dict_cached_value;\
+    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
+}
+static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
+#else
+#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
+#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
+static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
+#endif
+
+/* PyObjectCall2Args.proto */
+static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);
+
+/* IncludeStringH.proto */
+#include <string.h>
+
+/* BytesEquals.proto */
+static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);
+
+/* UnicodeEquals.proto */
+static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);
+
+/* PyThreadStateGet.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
+#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
+#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
+#else
+#define __Pyx_PyThreadState_declare
+#define __Pyx_PyThreadState_assign
+#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
+#endif
+
+/* PyErrFetchRestore.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
+#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
+#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
+#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
+#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
+static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
+#else
+#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
+#endif
+#else
+#define __Pyx_PyErr_Clear() PyErr_Clear()
+#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
+#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
+#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
+#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
+#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
+#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
+#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
+#endif
+
+/* RaiseException.proto */
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
+
+/* DictGetItem.proto */
+#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
+static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
+#define __Pyx_PyObject_Dict_GetItem(obj, name)\
+    (likely(PyDict_CheckExact(obj)) ?\
+     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
+#else
+#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
+#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
+#endif
+
+/* GetTopmostException.proto */
+#if CYTHON_USE_EXC_INFO_STACK
+static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
+#endif
+
+/* SaveResetException.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
+#else
+#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
+#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
+#endif
+
+/* PyErrExceptionMatches.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
+static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
+#else
+#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
+#endif
+
+/* GetException.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
+static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#else
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
+#endif
+
+/* GetItemInt.proto */
+#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
+    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
+               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
+#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
+    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
+                                                              int wraparound, int boundscheck);
+#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
+    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
+                                                              int wraparound, int boundscheck);
+static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
+                                                     int is_list, int wraparound, int boundscheck);
+
+/* ObjectGetItem.proto */
+#if CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
+#else
+#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
+#endif
+
+/* ExtTypeTest.proto */
+static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);
+
+/* SliceObject.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
+        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
+        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
+        int has_cstart, int has_cstop, int wraparound);
+
+/* ListAppend.proto */
+#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
+static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
+    PyListObject* L = (PyListObject*) list;
+    Py_ssize_t len = Py_SIZE(list);
+    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
+        Py_INCREF(x);
+        PyList_SET_ITEM(list, len, x);
+        Py_SIZE(list) = len+1;
+        return 0;
+    }
+    return PyList_Append(list, x);
+}
+#else
+#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
+#endif
+
+/* PyIntBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
+#else
+#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
+    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
+#endif
+
+/* py_dict_pop.proto */
+static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value);
+
+/* PyObjectFormatSimple.proto */
+#if CYTHON_COMPILING_IN_PYPY
+    #define __Pyx_PyObject_FormatSimple(s, f) (\
+        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
+        PyObject_Format(s, f))
+#elif PY_MAJOR_VERSION < 3
+    #define __Pyx_PyObject_FormatSimple(s, f) (\
+        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
+        likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\
+        PyObject_Format(s, f))
+#elif CYTHON_USE_TYPE_SLOTS
+    #define __Pyx_PyObject_FormatSimple(s, f) (\
+        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
+        likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\
+        likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\
+        PyObject_Format(s, f))
+#else
+    #define __Pyx_PyObject_FormatSimple(s, f) (\
+        likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
+        PyObject_Format(s, f))
+#endif
+
+/* JoinPyUnicode.proto */
+static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
+                                      Py_UCS4 max_char);
+
+/* py_dict_clear.proto */
+#define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
+
+/* ArgTypeTest.proto */
+#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
+    ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
+        __Pyx__ArgTypeTest(obj, type, name, exact))
+static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);
+
+/* GetAttr.proto */
+static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);
+
+/* GetAttr3.proto */
+static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);
+
+/* PySequenceContains.proto */
+static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
+    int result = PySequence_Contains(seq, item);
+    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
+}
+
+/* SwapException.proto */
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
+static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
+#else
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
+#endif
+
+/* PyIntBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
+#else
+#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\
+    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
+#endif
+
+/* None.proto */
+static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);
+
+/* WriteUnraisableException.proto */
+static void __Pyx_WriteUnraisable(const char *name, int clineno,
+                                  int lineno, const char *filename,
+                                  int full_traceback, int nogil);
+
+/* PyIntBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, long intval, int inplace);
+#else
+#define __Pyx_PyInt_AddCObj(op1, op2, intval, inplace)\
+    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
+#endif
+
+/* PyObjectSetAttrStr.proto */
+#if CYTHON_USE_TYPE_SLOTS
+#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
+static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);
+#else
+#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
+#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
+#endif
+
+/* PyObjectFormatAndDecref.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f);
+static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f);
+
+/* BuildPyUnicode.proto */
+static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
+                                                int prepend_sign, char padding_char);
+
+/* CIntToPyUnicode.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState value, Py_ssize_t width, char padding_char, char format_char);
+
+/* IterNext.proto */
+#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL)
+static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *);
+
+/* decode_c_string_utf16.proto */
+static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) {
+    int byteorder = 0;
+    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
+}
+static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) {
+    int byteorder = -1;
+    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
+}
+static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) {
+    int byteorder = 1;
+    return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
+}
+
+/* decode_c_bytes.proto */
+static CYTHON_INLINE PyObject* __Pyx_decode_c_bytes(
+         const char* cstring, Py_ssize_t length, Py_ssize_t start, Py_ssize_t stop,
+         const char* encoding, const char* errors,
+         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
+
+/* decode_bytes.proto */
+static CYTHON_INLINE PyObject* __Pyx_decode_bytes(
+         PyObject* string, Py_ssize_t start, Py_ssize_t stop,
+         const char* encoding, const char* errors,
+         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
+    return __Pyx_decode_c_bytes(
+        PyBytes_AS_STRING(string), PyBytes_GET_SIZE(string),
+        start, stop, encoding, errors, decode_func);
+}
+
+/* IterFinish.proto */
+static CYTHON_INLINE int __Pyx_IterFinish(void);
+
+/* PyObjectGetMethod.proto */
+static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
+
+/* PyObjectCallMethod0.proto */
+static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);
+
+/* RaiseNeedMoreValuesToUnpack.proto */
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
+
+/* RaiseTooManyValuesToUnpack.proto */
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
+
+/* UnpackItemEndCheck.proto */
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);
+
+/* RaiseNoneIterError.proto */
+static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
+
+/* UnpackTupleError.proto */
+static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index);
+
+/* UnpackTuple2.proto */
+#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\
+    (likely(is_tuple || PyTuple_Check(tuple)) ?\
+        (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\
+            __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\
+            (__Pyx_UnpackTupleError(tuple, 2), -1)) :\
+        __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple))
+static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
+    PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple);
+static int __Pyx_unpack_tuple2_generic(
+    PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple);
+
+/* dict_iter.proto */
+static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
+                                                   Py_ssize_t* p_orig_length, int* p_is_dict);
+static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
+                                              PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);
+
+/* FastTypeChecks.proto */
+#if CYTHON_COMPILING_IN_CPYTHON
+#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
+static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
+#else
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
+#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
+#endif
+#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
+
+/* PyDictContains.proto */
+static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
+    int result = PyDict_Contains(dict, item);
+    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
+}
+
+/* FetchCommonType.proto */
+static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
+
+/* PyObjectCallMethod1.proto */
+static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);
+
+/* CoroutineBase.proto */
+typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyThreadState *, PyObject *);
+#if CYTHON_USE_EXC_INFO_STACK
+#define __Pyx_ExcInfoStruct  _PyErr_StackItem
+#else
+typedef struct {
+    PyObject *exc_type;
+    PyObject *exc_value;
+    PyObject *exc_traceback;
+} __Pyx_ExcInfoStruct;
+#endif
+typedef struct {
+    PyObject_HEAD
+    __pyx_coroutine_body_t body;
+    PyObject *closure;
+    __Pyx_ExcInfoStruct gi_exc_state;
+    PyObject *gi_weakreflist;
+    PyObject *classobj;
+    PyObject *yieldfrom;
+    PyObject *gi_name;
+    PyObject *gi_qualname;
+    PyObject *gi_modulename;
+    PyObject *gi_code;
+    int resume_label;
+    char is_running;
+} __pyx_CoroutineObject;
+static __pyx_CoroutineObject *__Pyx__Coroutine_New(
+    PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
+    PyObject *name, PyObject *qualname, PyObject *module_name);
+static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
+            __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
+            PyObject *name, PyObject *qualname, PyObject *module_name);
+static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self);
+static int __Pyx_Coroutine_clear(PyObject *self);
+static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
+static PyObject *__Pyx_Coroutine_Close(PyObject *self);
+static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
+#if CYTHON_USE_EXC_INFO_STACK
+#define __Pyx_Coroutine_SwapException(self)
+#define __Pyx_Coroutine_ResetAndClearException(self)  __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state)
+#else
+#define __Pyx_Coroutine_SwapException(self) {\
+    __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback);\
+    __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state);\
+    }
+#define __Pyx_Coroutine_ResetAndClearException(self) {\
+    __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback);\
+    (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL;\
+    }
+#endif
+#if CYTHON_FAST_THREAD_STATE
+#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\
+    __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue)
+#else
+#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\
+    __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue)
+#endif
+static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue);
+static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state);
+
+/* PyObject_GenericGetAttrNoDict.proto */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
+#else
+#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
+#endif
+
+/* PatchModuleWithCoroutine.proto */
+static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);
+
+/* PatchGeneratorABC.proto */
+static int __Pyx_patch_abc(void);
+
+/* Coroutine.proto */
+#define __Pyx_Coroutine_USED
+static PyTypeObject *__pyx_CoroutineType = 0;
+static PyTypeObject *__pyx_CoroutineAwaitType = 0;
+#define __Pyx_Coroutine_CheckExact(obj) (Py_TYPE(obj) == __pyx_CoroutineType)
+#define __Pyx_Coroutine_Check(obj) __Pyx_Coroutine_CheckExact(obj)
+#define __Pyx_CoroutineAwait_CheckExact(obj) (Py_TYPE(obj) == __pyx_CoroutineAwaitType)
+#define __Pyx_Coroutine_New(body, code, closure, name, qualname, module_name)\
+    __Pyx__Coroutine_New(__pyx_CoroutineType, body, code, closure, name, qualname, module_name)
+static int __pyx_Coroutine_init(void);
+static PyObject *__Pyx__Coroutine_await(PyObject *coroutine);
+typedef struct {
+    PyObject_HEAD
+    PyObject *coroutine;
+} __pyx_CoroutineAwaitObject;
+static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self, PyObject *arg);
+static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args);
+
+/* GetAwaitIter.proto */
+static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o);
+static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *o);
+
+/* CoroutineYieldFrom.proto */
+static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject *gen, PyObject *source);
+
+/* ReturnWithStopIteration.proto */
+#define __Pyx_ReturnWithStopIteration(value)\
+    if (value == Py_None) PyErr_SetNone(PyExc_StopIteration); else __Pyx__ReturnWithStopIteration(value)
+static void __Pyx__ReturnWithStopIteration(PyObject* value);
+
+/* None.proto */
+static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);
+
+/* PyObjectLookupSpecial.proto */
+#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
+    PyObject *res;
+    PyTypeObject *tp = Py_TYPE(obj);
+#if PY_MAJOR_VERSION < 3
+    if (unlikely(PyInstance_Check(obj)))
+        return __Pyx_PyObject_GetAttrStr(obj, attr_name);
+#endif
+    res = _PyType_Lookup(tp, attr_name);
+    if (likely(res)) {
+        descrgetfunc f = Py_TYPE(res)->tp_descr_get;
+        if (!f) {
+            Py_INCREF(res);
+        } else {
+            res = f(res, obj, (PyObject *)tp);
+        }
+    } else {
+        PyErr_SetObject(PyExc_AttributeError, attr_name);
+    }
+    return res;
+}
+#else
+#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
+#endif
+
+/* CythonFunction.proto */
+#define __Pyx_CyFunction_USED 1
+#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
+#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
+#define __Pyx_CYFUNCTION_CCLASS        0x04
+#define __Pyx_CyFunction_GetClosure(f)\
+    (((__pyx_CyFunctionObject *) (f))->func_closure)
+#define __Pyx_CyFunction_GetClassObj(f)\
+    (((__pyx_CyFunctionObject *) (f))->func_classobj)
+#define __Pyx_CyFunction_Defaults(type, f)\
+    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
+#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
+    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
+typedef struct {
+    PyCFunctionObject func;
+#if PY_VERSION_HEX < 0x030500A0
+    PyObject *func_weakreflist;
+#endif
+    PyObject *func_dict;
+    PyObject *func_name;
+    PyObject *func_qualname;
+    PyObject *func_doc;
+    PyObject *func_globals;
+    PyObject *func_code;
+    PyObject *func_closure;
+    PyObject *func_classobj;
+    void *defaults;
+    int defaults_pyobjects;
+    int flags;
+    PyObject *defaults_tuple;
+    PyObject *defaults_kwdict;
+    PyObject *(*defaults_getter)(PyObject *);
+    PyObject *func_annotations;
+} __pyx_CyFunctionObject;
+static PyTypeObject *__pyx_CyFunctionType = 0;
+#define __Pyx_CyFunction_Check(obj)  (__Pyx_TypeCheck(obj, __pyx_CyFunctionType))
+#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
+    __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
+static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
+                                      int flags, PyObject* qualname,
+                                      PyObject *self,
+                                      PyObject *module, PyObject *globals,
+                                      PyObject* code);
+static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
+                                                         size_t size,
+                                                         int pyobjects);
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
+                                                            PyObject *tuple);
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
+                                                             PyObject *dict);
+static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
+                                                              PyObject *dict);
+static int __pyx_CyFunction_init(void);
+
+/* HasAttr.proto */
+static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);
+
+/* Import.proto */
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
+
+/* ImportFrom.proto */
+static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
+
+/* CallNextTpDealloc.proto */
+static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);
+
+/* CallNextTpTraverse.proto */
+static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse);
+
+/* CallNextTpClear.proto */
+static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc);
+
+/* SetVTable.proto */
+static int __Pyx_SetVtable(PyObject *dict, void *vtable);
+
+/* SetupReduce.proto */
+static int __Pyx_setup_reduce(PyObject* type_obj);
+
+/* PyObject_GenericGetAttr.proto */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
+#else
+#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
+#endif
+
+/* TypeImport.proto */
+#ifndef __PYX_HAVE_RT_ImportType_proto
+#define __PYX_HAVE_RT_ImportType_proto
+enum __Pyx_ImportType_CheckSize {
+   __Pyx_ImportType_CheckSize_Error = 0,
+   __Pyx_ImportType_CheckSize_Warn = 1,
+   __Pyx_ImportType_CheckSize_Ignore = 2
+};
+static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
+#endif
+
+/* GetVTable.proto */
+static void* __Pyx_GetVtable(PyObject *dict);
+
+/* PatchInspect.proto */
+static PyObject* __Pyx_patch_inspect(PyObject* module);
+
+/* PatchAsyncIO.proto */
+static PyObject* __Pyx_patch_asyncio(PyObject* module);
+
+/* SetNameInClass.proto */
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
+#define __Pyx_SetNameInClass(ns, name, value)\
+    (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
+#elif CYTHON_COMPILING_IN_CPYTHON
+#define __Pyx_SetNameInClass(ns, name, value)\
+    (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
+#else
+#define __Pyx_SetNameInClass(ns, name, value)  PyObject_SetItem(ns, name, value)
+#endif
+
+/* CalculateMetaclass.proto */
+static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
+
+/* Py3ClassCreate.proto */
+static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
+                                           PyObject *mkw, PyObject *modname, PyObject *doc);
+static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
+                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);
+
+/* CLineInTraceback.proto */
+#ifdef CYTHON_CLINE_IN_TRACEBACK
+#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
+#else
+static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
+#endif
+
+/* CodeObjectCache.proto */
+typedef struct {
+    PyCodeObject* code_object;
+    int code_line;
+} __Pyx_CodeObjectCacheEntry;
+struct __Pyx_CodeObjectCache {
+    int count;
+    int max_count;
+    __Pyx_CodeObjectCacheEntry* entries;
+};
+static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
+static PyCodeObject *__pyx_find_code_object(int code_line);
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
+
+/* AddTraceback.proto */
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+                               int py_line, const char *filename);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_CodecType(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
+
+/* UnicodeAsUCS4.proto */
+static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_ptrdiff_t(ptrdiff_t value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);
+
+/* CIntToPy.proto */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(PyObject *);
+
+/* CIntFromPy.proto */
+static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *);
+
+/* ObjectAsUCS4.proto */
+#define __Pyx_PyObject_AsPy_UCS4(x)\
+    (likely(PyUnicode_Check(x)) ? __Pyx_PyUnicode_AsPy_UCS4(x) : __Pyx__PyObject_AsPy_UCS4(x))
+static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject*);
+
+/* IterableCoroutine.proto */
+#define __Pyx_IterableCoroutine_USED
+static PyTypeObject *__pyx_IterableCoroutineType = 0;
+#undef __Pyx_Coroutine_Check
+#define __Pyx_Coroutine_Check(obj) (__Pyx_Coroutine_CheckExact(obj) || (Py_TYPE(obj) == __pyx_IterableCoroutineType))
+#define __Pyx_IterableCoroutine_New(body, code, closure, name, qualname, module_name)\
+    __Pyx__Coroutine_New(__pyx_IterableCoroutineType, body, code, closure, name, qualname, module_name)
+static int __pyx_IterableCoroutine_init(void);
+
+/* Generator.proto */
+#define __Pyx_Generator_USED
+static PyTypeObject *__pyx_GeneratorType = 0;
+#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
+#define __Pyx_Generator_New(body, code, closure, name, qualname, module_name)\
+    __Pyx__Coroutine_New(__pyx_GeneratorType, body, code, closure, name, qualname, module_name)
+static PyObject *__Pyx_Generator_Next(PyObject *self);
+static int __pyx_Generator_init(void);
+
+/* CheckBinaryVersion.proto */
+static int __Pyx_check_binary_version(void);
+
+/* VoidPtrExport.proto */
+static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig);
+
+/* FunctionImport.proto */
+static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig);
+
+/* InitStrings.proto */
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_setting(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_val); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_is_encoding_utf8(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_text_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_register_data_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_types, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, PyObject *__pyx_v_format, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, uint32_t __pyx_v_oid, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec *__pyx_optional_args); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, PyObject *__pyx_v_kind, enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType __pyx_v_type, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat, __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_c_encoder, __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_c_decoder, PyObject *__pyx_v_py_encoder, PyObject *__pyx_v_py_decoder, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_element_codec, PyObject *__pyx_v_element_type_oids, PyObject *__pyx_v_element_names, PyObject *__pyx_v_element_codecs, Py_UCS4 __pyx_v_element_delimiter); /* proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_copy(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_scalar(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array_text(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_range(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_composite(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_in_python(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_scalar(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array_text(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_range(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_composite(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_in_python(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_is_binary(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self); /* proto*/
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_array_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_element_codec, Py_UCS4 __pyx_v_element_delimiter); /* proto*/
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_range_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_element_codec); /* proto*/
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_composite_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, PyObject *__pyx_v_element_codecs, PyObject *__pyx_v_element_type_oids, PyObject *__pyx_v_element_names); /* proto*/
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_python_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, PyObject *__pyx_v_kind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_c_encoder, __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_c_decoder, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat); /* proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, uint32_t __pyx_v_oid, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format); /* proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_any_local_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, uint32_t __pyx_v_oid); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__read_server_messages(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__auth(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind_execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind_execute_many(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__close_stmt_portal(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__simple_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_out_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_in_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_command_complete(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_copy_data_msgs(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_data_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_data); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_done_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_fail_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_cause); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_data_msgs(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_backend_key_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_parameter_status(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_notification(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_authentication(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__auth_password_message_cleartext(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__auth_password_message_md5(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_salt); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_ready_for_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_error_response(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_is_error); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__push_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__reset_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __pyx_v_new_state); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__ensure_connected(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__build_bind_message(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__connect(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_stmt_name, PyObject *__pyx_v_query); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__send_bind_message(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data, int32_t __pyx_v_limit); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind_execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data, int32_t __pyx_v_limit); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind_execute_many(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, PyObject *__pyx_v_bind_data); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, int32_t __pyx_v_limit); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__close(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_name, int __pyx_v_is_portal); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__simple_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_query); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__terminate(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_buf); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__decode_row(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED char const *__pyx_v_buf, CYTHON_UNUSED Py_ssize_t __pyx_v_buf_len); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__set_server_parameter(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_name, CYTHON_UNUSED PyObject *__pyx_v_val); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_result(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_notice(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_parsed); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_notification(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_pid, CYTHON_UNUSED PyObject *__pyx_v_channel, CYTHON_UNUSED PyObject *__pyx_v_payload); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_connection_lost(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__init_codecs(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, CYTHON_UNUSED int __pyx_skip_dispatch); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_args); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_rows_decoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_args_encoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_row_desc(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_desc); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_args_desc(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_desc); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__decode_row(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, char const *__pyx_v_cbuf, Py_ssize_t __pyx_v_buf_len); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_get_connection(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_pause_reading(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__handle_waiter_on_connection_lost(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_cause); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__set_server_parameter(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_val); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__check_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__coreproto_error(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__new_waiter(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__connect(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__bind_and_exec(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__close_stmt_or_portal(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__simple_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__decode_row(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, char const *__pyx_v_buf, Py_ssize_t __pyx_v_buf_len); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__dispatch_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_notice(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_parsed); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_notification(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_pid, PyObject *__pyx_v_channel, PyObject *__pyx_v_payload); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_connection_lost(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_exc); /* proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__write(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_buf); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self); /* proto*/
+
+/* Module declarations from 'libc.stdint' */
+
+/* Module declarations from 'asyncpg.pgproto.debug' */
+
+/* Module declarations from 'cython' */
+
+/* Module declarations from 'cpython.version' */
+
+/* Module declarations from '__builtin__' */
+
+/* Module declarations from 'cpython.type' */
+static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
+
+/* Module declarations from 'libc.string' */
+
+/* Module declarations from 'libc.stdio' */
+
+/* Module declarations from 'cpython.object' */
+
+/* Module declarations from 'cpython.ref' */
+
+/* Module declarations from 'cpython.exc' */
+
+/* Module declarations from 'cpython.module' */
+
+/* Module declarations from 'cpython.mem' */
+
+/* Module declarations from 'cpython.tuple' */
+
+/* Module declarations from 'cpython.list' */
+
+/* Module declarations from 'cpython.sequence' */
+
+/* Module declarations from 'cpython.mapping' */
+
+/* Module declarations from 'cpython.iterator' */
+
+/* Module declarations from 'cpython.number' */
+
+/* Module declarations from 'cpython.int' */
+
+/* Module declarations from '__builtin__' */
+
+/* Module declarations from 'cpython.bool' */
+static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;
+
+/* Module declarations from 'cpython.long' */
+
+/* Module declarations from 'cpython.float' */
+
+/* Module declarations from '__builtin__' */
+
+/* Module declarations from 'cpython.complex' */
+static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
+
+/* Module declarations from 'cpython.string' */
+
+/* Module declarations from 'cpython.unicode' */
+
+/* Module declarations from 'cpython.dict' */
+
+/* Module declarations from 'cpython.instance' */
+
+/* Module declarations from 'cpython.function' */
+
+/* Module declarations from 'cpython.method' */
+
+/* Module declarations from 'cpython.weakref' */
+
+/* Module declarations from 'cpython.getargs' */
+
+/* Module declarations from 'cpython.pythread' */
+
+/* Module declarations from 'cpython.pystate' */
+
+/* Module declarations from 'cpython.cobject' */
+
+/* Module declarations from 'cpython.oldbuffer' */
+
+/* Module declarations from 'cpython.set' */
+
+/* Module declarations from 'cpython.buffer' */
+
+/* Module declarations from 'cpython.bytes' */
+
+/* Module declarations from 'cpython.pycapsule' */
+
+/* Module declarations from 'cpython' */
+
+/* Module declarations from 'asyncpg.pgproto.pgproto' */
+static PyTypeObject *__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext = 0;
+static CYTHON_INLINE Py_ssize_t __pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static CYTHON_INLINE void __pyx_f_7asyncpg_7pgproto_7pgproto_frb_set_len(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t); /*proto*/
+static CYTHON_INLINE void __pyx_f_7asyncpg_7pgproto_7pgproto_frb_init(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, char const *, Py_ssize_t); /*proto*/
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t); /*proto*/
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static CYTHON_INLINE struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_frb_check)(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode_tuple)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_bits_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_bits_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_bool_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_bool_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_box_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_box_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_line_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_line_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_point_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_point_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_path_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_path_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_poly_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_poly_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_circle_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_circle_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_int2_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_int2_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_int4_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_int4_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_int8_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_int8_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_float4_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_float4_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_float8_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_float8_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, PyObject *, char **, Py_ssize_t *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_text)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_text)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_binary)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_binary)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_void_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_void_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_tid_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_tid_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_net_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_inet_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_encode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *(*__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_decode)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+
+/* Module declarations from 'asyncpg.pgproto' */
+
+/* Module declarations from 'asyncpg.protocol' */
+
+/* Module declarations from 'asyncpg.protocol.cpythonx' */
+
+/* Module declarations from 'asyncpg.protocol.record' */
+
+/* Module declarations from 'asyncpg.pgproto.hton' */
+
+/* Module declarations from 'asyncpg.protocol.protocol' */
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol_Codec = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol_DataCodecConfig = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol_ConnectionSettings = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol_CoreProtocol = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close = 0;
+static PyTypeObject *__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation = 0;
+static PyObject *__pyx_v_7asyncpg_8protocol_8protocol_ARRAY_TYPES = 0;
+static PyObject *__pyx_7genexpr__pyx_v_7asyncpg_8protocol_8protocol_k;
+static PyObject *__pyx_7genexpr__pyx_v_7asyncpg_8protocol_8protocol_v;
+static PyObject *__pyx_v_7asyncpg_8protocol_8protocol_ENCODINGS_MAP = 0;
+static void *__pyx_v_7asyncpg_8protocol_8protocol_binary_codec_map[((0x1000 + 1) * 2)];
+static void *__pyx_v_7asyncpg_8protocol_8protocol_text_codec_map[((0x1000 + 1) * 2)];
+static PyObject *__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS = 0;
+static Py_UCS4 *__pyx_v_7asyncpg_8protocol_8protocol_APG_NULL;
+static PyObject *__pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE = 0;
+static PyObject *__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k;
+static PyObject *__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v;
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_get_python_encoding(PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_codec_encode_func_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_codec_decode_func_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, void const *); /*proto*/
+static uint32_t __pyx_f_7asyncpg_8protocol_8protocol_pylong_as_oid(PyObject *); /*proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(uint32_t, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_core_codec *__pyx_optional_args); /*proto*/
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol_has_core_codec(uint32_t); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(uint32_t, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_register_core_codec *__pyx_optional_args); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_register_extra_codec(PyObject *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat); /*proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_get_extra_codec(PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat); /*proto*/
+static CYTHON_INLINE uint32_t __pyx_f_7asyncpg_8protocol_8protocol__apg_tolower(uint32_t); /*proto*/
+static int __pyx_f_7asyncpg_8protocol_8protocol_apg_strcasecmp(Py_UCS4 const *, Py_UCS4 const *); /*proto*/
+static int __pyx_f_7asyncpg_8protocol_8protocol_apg_strcasecmp_char(char const *, char const *); /*proto*/
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace(Py_UCS4); /*proto*/
+static Py_UCS4 *__pyx_f_7asyncpg_8protocol_8protocol_apg_parse_int32(Py_UCS4 *, int32_t *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_bits_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_bytea_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_datetime_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_float_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_geometry_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_hstore_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_json_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_int_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_pseudo_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_text_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_tid_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_txid_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_tsearch_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_uuid_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_numeric_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_network_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_monetary_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_all_pgproto_codecs(void); /*proto*/
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol__is_trivial_container(PyObject *); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol__is_array_iterable(PyObject *); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol__is_sub_array_iterable(PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__get_array_shape(PyObject *, int32_t *, int32_t *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__write_array_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, int32_t, int32_t, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex, void const *); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_array_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, uint32_t, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__write_textarray_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, int32_t, int32_t, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex, void const *, Py_UCS4); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_textarray_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex, void const *, Py_UCS4); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_array_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__nested_array_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex, void const *, int32_t, int32_t *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_textarray_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex, void const *, Py_UCS4); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__textarray_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, Py_UCS4 *, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex, void const *, Py_UCS4); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(Py_UCS4 const *, Py_UCS4 const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__infer_array_dims(Py_UCS4 const *, Py_UCS4, int32_t *, int32_t *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_uint4_encode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_uint4_decode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arrayoid_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arrayoid_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_text_encode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_text_decode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arraytext_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arraytext_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_anyarray_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_array_codecs(void); /*proto*/
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol__range_has_lbound(uint8_t); /*proto*/
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol__range_has_ubound(uint8_t); /*proto*/
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol__RangeArgumentType __pyx_f_7asyncpg_8protocol_8protocol__range_type(PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_range_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *, uint32_t, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_range_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex, void const *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_range_codecs(void); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_record_encode_frame(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_anonymous_record_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_record_codecs(void); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__decode_parameters_desc(PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__decode_row_desc(PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_DataCodecConfig__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_CoreProtocol__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_BaseProtocol__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *); /*proto*/
+#define __Pyx_MODULE_NAME "asyncpg.protocol.protocol"
+extern int __pyx_module_is_main_asyncpg__protocol__protocol;
+int __pyx_module_is_main_asyncpg__protocol__protocol = 0;
+
+/* Implementation of 'asyncpg.protocol.protocol' */
+static PyObject *__pyx_builtin_object;
+static PyObject *__pyx_builtin_KeyError;
+static PyObject *__pyx_builtin_AttributeError;
+static PyObject *__pyx_builtin_TypeError;
+static PyObject *__pyx_builtin_NotImplementedError;
+static PyObject *__pyx_builtin_range;
+static PyObject *__pyx_builtin_ValueError;
+static PyObject *__pyx_builtin_OverflowError;
+static PyObject *__pyx_builtin_enumerate;
+static PyObject *__pyx_builtin_reversed;
+static PyObject *__pyx_builtin_chr;
+static PyObject *__pyx_builtin_StopIteration;
+static PyObject *__pyx_builtin_AssertionError;
+static PyObject *__pyx_builtin_BufferError;
+static const char __pyx_k_c[] = "c";
+static const char __pyx_k_d[] = "d";
+static const char __pyx_k_e[] = "e";
+static const char __pyx_k_i[] = "i";
+static const char __pyx_k_n[] = "n";
+static const char __pyx_k_r[] = "r";
+static const char __pyx_k_s[] = "s";
+static const char __pyx_k_v[] = "v";
+static const char __pyx_k_w[] = "w";
+static const char __pyx_k_x[] = "x";
+static const char __pyx_k_y[] = "y";
+static const char __pyx_k_NA[] = "NA";
+static const char __pyx_k__2[] = "_";
+static const char __pyx_k__9[] = "{}[]";
+static const char __pyx_k_et[] = "et";
+static const char __pyx_k_ns[] = "ns";
+static const char __pyx_k_tb[] = "tb";
+static const char __pyx_k_to[] = " to ";
+static const char __pyx_k__18[] = "\"\"";
+static const char __pyx_k__24[] = ".";
+static const char __pyx_k__25[] = "";
+static const char __pyx_k__26[] = "'{}'";
+static const char __pyx_k__28[] = "...";
+static const char __pyx_k_abc[] = "abc";
+static const char __pyx_k_alt[] = "alt";
+static const char __pyx_k_any[] = "any";
+static const char __pyx_k_bit[] = "bit";
+static const char __pyx_k_box[] = "box";
+static const char __pyx_k_chr[] = "chr";
+static const char __pyx_k_cid[] = "cid";
+static const char __pyx_k_doc[] = "__doc__";
+static const char __pyx_k_get[] = "get";
+static const char __pyx_k_int[] = "int";
+static const char __pyx_k_md5[] = "md5";
+static const char __pyx_k_msg[] = "msg";
+static const char __pyx_k_new[] = "new";
+static const char __pyx_k_oid[] = "oid";
+static const char __pyx_k_pop[] = "pop";
+static const char __pyx_k_rec[] = "rec";
+static const char __pyx_k_ref[] = "ref";
+static const char __pyx_k_set[] = "set";
+static const char __pyx_k_tid[] = "tid";
+static const char __pyx_k_was[] = "was";
+static const char __pyx_k_win[] = "win";
+static const char __pyx_k_xid[] = "xid";
+static const char __pyx_k_xml[] = "xml";
+static const char __pyx_k_NULL[] = "NULL";
+static const char __pyx_k_Type[] = "Type";
+static const char __pyx_k_addr[] = "addr";
+static const char __pyx_k_args[] = "args";
+static const char __pyx_k_base[] = "_base";
+static const char __pyx_k_bind[] = "bind";
+static const char __pyx_k_bool[] = "bool";
+static const char __pyx_k_char[] = "char";
+static const char __pyx_k_cidr[] = "cidr";
+static const char __pyx_k_data[] = "data";
+static const char __pyx_k_date[] = "date";
+static const char __pyx_k_desc[] = "desc";
+static const char __pyx_k_dict[] = "__dict__";
+static const char __pyx_k_done[] = "done";
+static const char __pyx_k_elem[] = "elem";
+static const char __pyx_k_exit[] = "__exit__";
+static const char __pyx_k_hint[] = "hint";
+static const char __pyx_k_inet[] = "inet";
+static const char __pyx_k_init[] = "__init__";
+static const char __pyx_k_int2[] = "int2";
+static const char __pyx_k_int4[] = "int4";
+static const char __pyx_k_int8[] = "int8";
+static const char __pyx_k_json[] = "json";
+static const char __pyx_k_kind[] = "kind";
+static const char __pyx_k_line[] = "line";
+static const char __pyx_k_loop[] = "loop";
+static const char __pyx_k_lseg[] = "lseg";
+static const char __pyx_k_main[] = "__main__";
+static const char __pyx_k_name[] = "name";
+static const char __pyx_k_path[] = "path";
+static const char __pyx_k_real[] = "real";
+static const char __pyx_k_self[] = "self";
+static const char __pyx_k_send[] = "send";
+static const char __pyx_k_sink[] = "sink";
+static const char __pyx_k_sjis[] = "sjis";
+static const char __pyx_k_smgr[] = "smgr";
+static const char __pyx_k_tcvn[] = "tcvn";
+static const char __pyx_k_test[] = "__test__";
+static const char __pyx_k_text[] = "text";
+static const char __pyx_k_time[] = "time";
+static const char __pyx_k_user[] = "user";
+static const char __pyx_k_uuid[] = "uuid";
+static const char __pyx_k_void[] = "void";
+static const char __pyx_k_wait[] = "wait";
+static const char __pyx_k_were[] = "were";
+static const char __pyx_k_Codec[] = "Codec";
+static const char __pyx_k_Event[] = "Event";
+static const char __pyx_k_Range[] = "Range";
+static const char __pyx_k_Sized[] = "Sized";
+static const char __pyx_k_Timer[] = "Timer";
+static const char __pyx_k_abort[] = "abort";
+static const char __pyx_k_aiter[] = "__aiter__";
+static const char __pyx_k_anext[] = "__anext__";
+static const char __pyx_k_array[] = "array";
+static const char __pyx_k_ascii[] = "ascii";
+static const char __pyx_k_await[] = "__await__";
+static const char __pyx_k_bytea[] = "bytea";
+static const char __pyx_k_cause[] = "__cause__";
+static const char __pyx_k_clear[] = "clear";
+static const char __pyx_k_close[] = "close";
+static const char __pyx_k_cp866[] = "cp866";
+static const char __pyx_k_cp874[] = "cp874";
+static const char __pyx_k_cp932[] = "cp932";
+static const char __pyx_k_cp936[] = "cp936";
+static const char __pyx_k_cp949[] = "cp949";
+static const char __pyx_k_cp950[] = "cp950";
+static const char __pyx_k_elems[] = "elems";
+static const char __pyx_k_empty[] = "empty";
+static const char __pyx_k_enter[] = "__enter__";
+static const char __pyx_k_euccn[] = "euccn";
+static const char __pyx_k_eucjp[] = "eucjp";
+static const char __pyx_k_euckr[] = "euckr";
+static const char __pyx_k_items[] = "items";
+static const char __pyx_k_jsonb[] = "jsonb";
+static const char __pyx_k_koi8r[] = "koi8r";
+static const char __pyx_k_koi8u[] = "koi8u";
+static const char __pyx_k_limit[] = "limit";
+static const char __pyx_k_lower[] = "lower";
+static const char __pyx_k_money[] = "money";
+static const char __pyx_k_new_2[] = "__new__";
+static const char __pyx_k_oid_2[] = "oid[]";
+static const char __pyx_k_point[] = "point";
+static const char __pyx_k_query[] = "query";
+static const char __pyx_k_range[] = "range";
+static const char __pyx_k_state[] = "state";
+static const char __pyx_k_throw[] = "throw";
+static const char __pyx_k_tuple[] = "tuple";
+static const char __pyx_k_types[] = "types";
+static const char __pyx_k_upper[] = "upper";
+static const char __pyx_k_utf_8[] = "utf-8";
+static const char __pyx_k_vscii[] = "vscii";
+static const char __pyx_k_write[] = "write";
+static const char __pyx_k_Future[] = "Future";
+static const char __pyx_k_NULL_2[] = "\"NULL\"";
+static const char __pyx_k_PGCOPY[] = "PGCOPY\n\377\r\n\000";
+static const char __pyx_k_Record[] = "Record";
+static const char __pyx_k_bigint[] = "bigint";
+static const char __pyx_k_binary[] = "binary";
+static const char __pyx_k_bpchar[] = "bpchar";
+static const char __pyx_k_budget[] = "budget";
+static const char __pyx_k_cancel[] = "cancel";
+static const char __pyx_k_circle[] = "circle";
+static const char __pyx_k_codecs[] = "codecs";
+static const char __pyx_k_compat[] = "compat";
+static const char __pyx_k_config[] = "_config";
+static const char __pyx_k_cp1250[] = "cp1250";
+static const char __pyx_k_cp1251[] = "cp1251";
+static const char __pyx_k_cp1252[] = "cp1252";
+static const char __pyx_k_cp1253[] = "cp1253";
+static const char __pyx_k_cp1254[] = "cp1254";
+static const char __pyx_k_cp1255[] = "cp1255";
+static const char __pyx_k_cp1256[] = "cp1256";
+static const char __pyx_k_cp1257[] = "cp1257";
+static const char __pyx_k_cp1258[] = "cp1258";
+static const char __pyx_k_cp1521[] = "cp1521";
+static const char __pyx_k_decode[] = "decode";
+static const char __pyx_k_encode[] = "encode";
+static const char __pyx_k_euc_cn[] = "euc_cn";
+static const char __pyx_k_euc_jp[] = "euc_jp";
+static const char __pyx_k_euc_kr[] = "euc_kr";
+static const char __pyx_k_family[] = "family";
+static const char __pyx_k_float4[] = "float4";
+static const char __pyx_k_float8[] = "float8";
+static const char __pyx_k_format[] = "format";
+static const char __pyx_k_import[] = "__import__";
+static const char __pyx_k_koi8_r[] = "koi8_r";
+static const char __pyx_k_koi8_u[] = "koi8_u";
+static const char __pyx_k_lookup[] = "lookup";
+static const char __pyx_k_module[] = "__module__";
+static const char __pyx_k_name_2[] = "__name__";
+static const char __pyx_k_object[] = "object";
+static const char __pyx_k_opaque[] = "opaque";
+static const char __pyx_k_pg_lsn[] = "pg_lsn";
+static const char __pyx_k_pickle[] = "pickle";
+static const char __pyx_k_reader[] = "reader";
+static const char __pyx_k_record[] = "record";
+static const char __pyx_k_reduce[] = "__reduce__";
+static const char __pyx_k_scalar[] = "scalar";
+static const char __pyx_k_schema[] = "schema";
+static const char __pyx_k_socket[] = "socket";
+static const char __pyx_k_text_2[] = "text[]";
+static const char __pyx_k_timetz[] = "timetz";
+static const char __pyx_k_update[] = "update";
+static const char __pyx_k_varbit[] = "varbit";
+static const char __pyx_k_win866[] = "win866";
+static const char __pyx_k_win874[] = "win874";
+static const char __pyx_k_win932[] = "win932";
+static const char __pyx_k_win936[] = "win936";
+static const char __pyx_k_win949[] = "win949";
+static const char __pyx_k_win950[] = "win950";
+static const char __pyx_k_AF_UNIX[] = "AF_UNIX";
+static const char __pyx_k_Mapping[] = "Mapping";
+static const char __pyx_k_abstime[] = "abstime";
+static const char __pyx_k_aclitem[] = "aclitem";
+static const char __pyx_k_anyenum[] = "anyenum";
+static const char __pyx_k_apg_exc[] = "apg_exc";
+static const char __pyx_k_asyncio[] = "asyncio";
+static const char __pyx_k_asyncpg[] = "asyncpg";
+static const char __pyx_k_cleanup[] = "_cleanup";
+static const char __pyx_k_copy_in[] = "copy_in";
+static const char __pyx_k_cstring[] = "cstring";
+static const char __pyx_k_decimal[] = "decimal";
+static const char __pyx_k_decoder[] = "decoder";
+static const char __pyx_k_encoder[] = "encoder";
+static const char __pyx_k_execute[] = "execute";
+static const char __pyx_k_genexpr[] = "genexpr";
+static const char __pyx_k_getattr[] = "__getattr__";
+static const char __pyx_k_hashlib[] = "hashlib";
+static const char __pyx_k_inspect[] = "inspect";
+static const char __pyx_k_integer[] = "integer";
+static const char __pyx_k_isempty[] = "isempty";
+static const char __pyx_k_macaddr[] = "macaddr";
+static const char __pyx_k_mapping[] = "mapping";
+static const char __pyx_k_message[] = "message";
+static const char __pyx_k_numeric[] = "numeric";
+static const char __pyx_k_polygon[] = "polygon";
+static const char __pyx_k_prepare[] = "prepare";
+static const char __pyx_k_records[] = "records";
+static const char __pyx_k_regoper[] = "regoper";
+static const char __pyx_k_regproc[] = "regproc";
+static const char __pyx_k_regrole[] = "regrole";
+static const char __pyx_k_regtype[] = "regtype";
+static const char __pyx_k_release[] = "release";
+static const char __pyx_k_reltime[] = "reltime";
+static const char __pyx_k_started[] = "_started";
+static const char __pyx_k_timeout[] = "timeout";
+static const char __pyx_k_trigger[] = "trigger";
+static const char __pyx_k_tsquery[] = "tsquery";
+static const char __pyx_k_typeoid[] = "typeoid";
+static const char __pyx_k_unicode[] = "unicode";
+static const char __pyx_k_unknown[] = "unknown";
+static const char __pyx_k_utf_8_2[] = "utf_8";
+static const char __pyx_k_varchar[] = "varchar";
+static const char __pyx_k_weakref[] = "weakref";
+static const char __pyx_k_win1250[] = "win1250";
+static const char __pyx_k_win1251[] = "win1251";
+static const char __pyx_k_win1252[] = "win1252";
+static const char __pyx_k_win1253[] = "win1253";
+static const char __pyx_k_win1254[] = "win1254";
+static const char __pyx_k_win1255[] = "win1255";
+static const char __pyx_k_win1256[] = "win1256";
+static const char __pyx_k_win1257[] = "win1257";
+static const char __pyx_k_win1258[] = "win1258";
+static const char __pyx_k_xformat[] = "xformat";
+static const char __pyx_k_Iterable[] = "Iterable";
+static const char __pyx_k_KeyError[] = "KeyError";
+static const char __pyx_k_Protocol[] = "Protocol";
+static const char __pyx_k_SizedABC[] = "SizedABC";
+static const char __pyx_k_alias_to[] = "alias_to";
+static const char __pyx_k_anyarray[] = "anyarray";
+static const char __pyx_k_anyrange[] = "anyrange";
+static const char __pyx_k_auth_msg[] = "auth_msg";
+static const char __pyx_k_basetype[] = "basetype";
+static const char __pyx_k_budget_2[] = "_budget";
+static const char __pyx_k_builtins[] = "builtins";
+static const char __pyx_k_conn_key[] = "conn_key";
+static const char __pyx_k_copy_out[] = "copy_out";
+static const char __pyx_k_database[] = "database";
+static const char __pyx_k_elemtype[] = "elemtype";
+static const char __pyx_k_getstate[] = "__getstate__";
+static const char __pyx_k_internal[] = "internal";
+static const char __pyx_k_interval[] = "interval";
+static const char __pyx_k_macaddr8[] = "macaddr8";
+static const char __pyx_k_on_error[] = "_on_error";
+static const char __pyx_k_password[] = "password";
+static const char __pyx_k_position[] = "position";
+static const char __pyx_k_protocol[] = "protocol";
+static const char __pyx_k_pyx_capi[] = "__pyx_capi__";
+static const char __pyx_k_pyx_type[] = "__pyx_type";
+static const char __pyx_k_qualname[] = "__qualname__";
+static const char __pyx_k_regclass[] = "regclass";
+static const char __pyx_k_reversed[] = "reversed";
+static const char __pyx_k_setstate[] = "__setstate__";
+static const char __pyx_k_smallint[] = "smallint";
+static const char __pyx_k_tcvn5712[] = "tcvn5712";
+static const char __pyx_k_tsvector[] = "tsvector";
+static const char __pyx_k_typekind[] = "typekind";
+static const char __pyx_k_typename[] = "typename";
+static const char __pyx_k_wait_for[] = "wait_for";
+static const char __pyx_k_Attribute[] = "Attribute";
+static const char __pyx_k_DataError[] = "DataError";
+static const char __pyx_k_TypeError[] = "TypeError";
+static const char __pyx_k_add_types[] = "add_types";
+static const char __pyx_k_apg_types[] = "apg_types";
+static const char __pyx_k_attrnames[] = "attrnames";
+static const char __pyx_k_cache_key[] = "cache_key";
+static const char __pyx_k_cancelled[] = "cancelled";
+static const char __pyx_k_codec_for[] = " codec for ";
+static const char __pyx_k_composite[] = "composite";
+static const char __pyx_k_copy_stmt[] = "copy_stmt";
+static const char __pyx_k_data_type[] = "data_type";
+static const char __pyx_k_elemdelim[] = "elemdelim";
+static const char __pyx_k_enumerate[] = "enumerate";
+static const char __pyx_k_exception[] = "exception";
+static const char __pyx_k_gtsvector[] = "gtsvector";
+static const char __pyx_k_hexdigest[] = "hexdigest";
+static const char __pyx_k_lower_inc[] = "lower_inc";
+static const char __pyx_k_metaclass[] = "__metaclass__";
+static const char __pyx_k_monotonic[] = "monotonic";
+static const char __pyx_k_prepare_2[] = "__prepare__";
+static const char __pyx_k_pyx_state[] = "__pyx_state";
+static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
+static const char __pyx_k_refcursor[] = "refcursor";
+static const char __pyx_k_regconfig[] = "regconfig";
+static const char __pyx_k_shift_jis[] = "shift_jis";
+static const char __pyx_k_sql_ascii[] = "sql_ascii";
+static const char __pyx_k_stmt_name[] = "stmt_name";
+static const char __pyx_k_timestamp[] = "timestamp";
+static const char __pyx_k_tinterval[] = "tinterval";
+static const char __pyx_k_upper_inc[] = "upper_inc";
+static const char __pyx_k_MappingABC[] = "MappingABC";
+static const char __pyx_k_NO_TIMEOUT[] = "NO_TIMEOUT";
+static const char __pyx_k_ValueError[] = "ValueError";
+static const char __pyx_k_anyelement[] = "anyelement";
+static const char __pyx_k_call_later[] = "call_later";
+static const char __pyx_k_con_params[] = "con_params";
+static const char __pyx_k_exceptions[] = "exceptions";
+static const char __pyx_k_has_bin_io[] = "has_bin_io";
+static const char __pyx_k_memoryview[] = "memoryview";
+static const char __pyx_k_on_timeout[] = "_on_timeout";
+static const char __pyx_k_pg_catalog[] = "pg_catalog";
+static const char __pyx_k_pyx_result[] = "__pyx_result";
+static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
+static const char __pyx_k_set_result[] = "set_result";
+static const char __pyx_k_setsockopt[] = "setsockopt";
+static const char __pyx_k_startswith[] = "startswith";
+static const char __pyx_k_typeschema[] = "typeschema";
+static const char __pyx_k_windows866[] = "windows866";
+static const char __pyx_k_windows874[] = "windows874";
+static const char __pyx_k_windows932[] = "windows932";
+static const char __pyx_k_windows936[] = "windows936";
+static const char __pyx_k_windows949[] = "windows949";
+static const char __pyx_k_windows950[] = "windows950";
+static const char __pyx_k_ARRAY_TYPES[] = "ARRAY_TYPES";
+static const char __pyx_k_BufferError[] = "BufferError";
+static const char __pyx_k_IPPROTO_TCP[] = "IPPROTO_TCP";
+static const char __pyx_k_IterableABC[] = "IterableABC";
+static const char __pyx_k_OrderedDict[] = "OrderedDict";
+static const char __pyx_k_PickleError[] = "PickleError";
+static const char __pyx_k_TCP_NODELAY[] = "TCP_NODELAY";
+static const char __pyx_k_anynonarray[] = "anynonarray";
+static const char __pyx_k_attrtypoids[] = "attrtypoids";
+static const char __pyx_k_collections[] = "collections";
+static const char __pyx_k_fdw_handler[] = "fdw_handler";
+static const char __pyx_k_get_timeout[] = "_get_timeout";
+static const char __pyx_k_hashlib_md5[] = "hashlib_md5";
+static const char __pyx_k_portal_name[] = "portal_name";
+static const char __pyx_k_record_stmt[] = "record_stmt";
+static const char __pyx_k_regoperator[] = "regoperator";
+static const char __pyx_k_there_is_no[] = ": there is no ";
+static const char __pyx_k_timestamptz[] = "timestamptz";
+static const char __pyx_k_tsm_handler[] = "tsm_handler";
+static const char __pyx_k_windows1250[] = "windows1250";
+static const char __pyx_k_windows1251[] = "windows1251";
+static const char __pyx_k_windows1252[] = "windows1252";
+static const char __pyx_k_windows1253[] = "windows1253";
+static const char __pyx_k_windows1254[] = "windows1254";
+static const char __pyx_k_windows1255[] = "windows1255";
+static const char __pyx_k_windows1256[] = "windows1256";
+static const char __pyx_k_windows1257[] = "windows1257";
+static const char __pyx_k_windows1258[] = "windows1258";
+static const char __pyx_k_BaseProtocol[] = "BaseProtocol";
+static const char __pyx_k_CoreProtocol[] = "CoreProtocol";
+static const char __pyx_k_TimeoutError[] = "TimeoutError";
+static const char __pyx_k_Timer___exit[] = "Timer.__exit__";
+static const char __pyx_k_Timer___init[] = "Timer.__init__";
+static const char __pyx_k_apg_exc_base[] = "apg_exc_base";
+static const char __pyx_k_bind_execute[] = "bind_execute";
+static const char __pyx_k_cannot_alias[] = "cannot alias ";
+static const char __pyx_k_euc_jis_2004[] = "euc_jis_2004";
+static const char __pyx_k_pg_ndistinct[] = "pg_ndistinct";
+static const char __pyx_k_pg_node_tree[] = "pg_node_tree";
+static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
+static const char __pyx_k_regnamespace[] = "regnamespace";
+static const char __pyx_k_regprocedure[] = "regprocedure";
+static const char __pyx_k_return_extra[] = "return_extra";
+static const char __pyx_k_stringsource[] = "stringsource";
+static const char __pyx_k_OverflowError[] = "OverflowError";
+static const char __pyx_k_PostgresError[] = "PostgresError";
+static const char __pyx_k_ProtocolError[] = "ProtocolError";
+static const char __pyx_k_StopIteration[] = "StopIteration";
+static const char __pyx_k_Timer___enter[] = "Timer.__enter__";
+static const char __pyx_k_asyncio_tasks[] = "asyncio.tasks";
+static const char __pyx_k_connected_fut[] = "connected_fut";
+static const char __pyx_k_create_future[] = "create_future";
+static const char __pyx_k_create_record[] = "_create_record";
+static const char __pyx_k_event_trigger[] = "event_trigger";
+static const char __pyx_k_not_connected[] = "not connected";
+static const char __pyx_k_pause_reading[] = "pause_reading";
+static const char __pyx_k_range_subtype[] = "range_subtype";
+static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
+static const char __pyx_k_regdictionary[] = "regdictionary";
+static const char __pyx_k_set_exception[] = "set_exception";
+static const char __pyx_k_txid_snapshot[] = "txid_snapshot";
+static const char __pyx_k_AssertionError[] = "AssertionError";
+static const char __pyx_k_AttributeError[] = "AttributeError";
+static const char __pyx_k_InterfaceError[] = "InterfaceError";
+static const char __pyx_k_get_extra_info[] = "get_extra_info";
+static const char __pyx_k_pg_ddl_command[] = "pg_ddl_command";
+static const char __pyx_k_request_cancel[] = "_request_cancel";
+static const char __pyx_k_resume_reading[] = "resume_reading";
+static const char __pyx_k_shift_jis_2004[] = "shift_jis_2004";
+static const char __pyx_k_text_or_binary[] = "'text' or 'binary'";
+static const char __pyx_k_DataCodecConfig[] = "DataCodecConfig";
+static const char __pyx_k_client_encoding[] = "client_encoding";
+static const char __pyx_k_close_statement[] = "close_statement";
+static const char __pyx_k_collections_abc[] = "collections.abc";
+static const char __pyx_k_command_timeout[] = "command_timeout";
+static const char __pyx_k_elem_has_bin_io[] = "elem_has_bin_io";
+static const char __pyx_k_pg_dependencies[] = "pg_dependencies";
+static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
+static const char __pyx_k_server_settings[] = "server_settings";
+static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
+static const char __pyx_k_writing_allowed[] = "writing_allowed";
+static const char __pyx_k_AUTH_METHOD_NAME[] = "AUTH_METHOD_NAME";
+static const char __pyx_k_add_python_codec[] = "add_python_codec";
+static const char __pyx_k_clear_type_cache[] = "clear_type_cache";
+static const char __pyx_k_double_precision[] = "double precision";
+static const char __pyx_k_index_am_handler[] = "index_am_handler";
+static const char __pyx_k_language_handler[] = "language_handler";
+static const char __pyx_k_text_or_binary_2[] = "text or binary";
+static const char __pyx_k_BaseProtocol_bind[] = "BaseProtocol.bind";
+static const char __pyx_k_add_done_callback[] = "add_done_callback";
+static const char __pyx_k_already_connected[] = "already connected";
+static const char __pyx_k_bind_execute_many[] = "bind_execute_many";
+static const char __pyx_k_pg_contrib_hstore[] = "pg_contrib.hstore";
+static const char __pyx_k_BaseProtocol_close[] = "BaseProtocol.close";
+static const char __pyx_k_BaseProtocol_query[] = "BaseProtocol.query";
+static const char __pyx_k_ConnectionSettings[] = "ConnectionSettings";
+static const char __pyx_k_StopAsyncIteration[] = "StopAsyncIteration";
+static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines";
+static const char __pyx_k_asyncpg_exceptions[] = "asyncpg.exceptions";
+static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
+static const char __pyx_k_no_decoder_for_OID[] = "no decoder for OID {}";
+static const char __pyx_k_no_encoder_for_OID[] = "no encoder for OID {}";
+static const char __pyx_k_time_with_timezone[] = "time with timezone";
+static const char __pyx_k_InternalClientError[] = "InternalClientError";
+static const char __pyx_k_NotImplementedError[] = "NotImplementedError";
+static const char __pyx_k_invalid_data_format[] = "invalid data format: {}";
+static const char __pyx_k_on_waiter_completed[] = "_on_waiter_completed";
+static const char __pyx_k_process_log_message[] = "_process_log_message";
+static const char __pyx_k_remove_python_codec[] = "remove_python_codec";
+static const char __pyx_k_BUILTIN_TYPE_OID_MAP[] = "BUILTIN_TYPE_OID_MAP";
+static const char __pyx_k_BaseProtocol_copy_in[] = "BaseProtocol.copy_in";
+static const char __pyx_k_BaseProtocol_execute[] = "BaseProtocol.execute";
+static const char __pyx_k_BaseProtocol_prepare[] = "BaseProtocol.prepare";
+static const char __pyx_k_ConnectionResetError[] = "ConnectionResetError";
+static const char __pyx_k_ConnectionSettings_r[] = "<ConnectionSettings {!r}>";
+static const char __pyx_k_get_remaining_budget[] = "get_remaining_budget";
+static const char __pyx_k_process_notification[] = "_process_notification";
+static const char __pyx_k_text_binary_or_tuple[] = "'text', 'binary' or 'tuple'";
+static const char __pyx_k_BUILTIN_TYPE_NAME_MAP[] = "BUILTIN_TYPE_NAME_MAP";
+static const char __pyx_k_BaseProtocol_copy_out[] = "BaseProtocol.copy_out";
+static const char __pyx_k_OID_value_too_large_r[] = "OID value too large: {!r}";
+static const char __pyx_k_copy_in_locals_lambda[] = "copy_in.<locals>.<lambda>";
+static const char __pyx_k_invalid_array_element[] = "invalid array element: {}";
+static const char __pyx_k_non_homogeneous_array[] = "non-homogeneous array";
+static const char __pyx_k_unexpected_codec_type[] = "unexpected codec type: {}";
+static const char __pyx_k_wait_for_cancellation[] = "_wait_for_cancellation";
+static const char __pyx_k_PreparedStatementState[] = "PreparedStatementState";
+static const char __pyx_k_call_exception_handler[] = "call_exception_handler";
+static const char __pyx_k_cancel_current_command[] = "_cancel_current_command";
+static const char __pyx_k_cannot_process_message[] = "cannot process message ";
+static const char __pyx_k_copy_out_locals_lambda[] = "copy_out.<locals>.<lambda>";
+static const char __pyx_k_create_future_fallback[] = "_create_future_fallback";
+static const char __pyx_k_declare_fallback_codec[] = "declare_fallback_codec";
+static const char __pyx_k_set_builtin_type_codec[] = "set_builtin_type_codec";
+static const char __pyx_k_unexpected_data_format[] = "unexpected data format: {}";
+static const char __pyx_k_unexpected_ndims_value[] = "unexpected ndims value: {}";
+static const char __pyx_k_Codec_oid_elem_oid_core[] = "<Codec oid={} elem_oid={} core={}>";
+static const char __pyx_k_timestamp_with_timezone[] = "timestamp with timezone";
+static const char __pyx_k_OutdatedSchemaCacheError[] = "OutdatedSchemaCacheError";
+static const char __pyx_k_on_result_waiter_is_None[] = "_on_result: waiter is None";
+static const char __pyx_k_on_result_waiter_is_done[] = "_on_result: waiter is done";
+static const char __pyx_k_set_builtin_type_codec_2[] = "_set_builtin_type_codec";
+static const char __pyx_k_unexpected_end_of_string[] = "unexpected end of string";
+static const char __pyx_k_BaseProtocol_bind_execute[] = "BaseProtocol.bind_execute";
+static const char __pyx_k_asyncpg_protocol_protocol[] = "asyncpg.protocol.protocol";
+static const char __pyx_k_malformed_array_literal_r[] = "malformed array literal {!r}: {}";
+static const char __pyx_k_pyx_unpickle_BaseProtocol[] = "__pyx_unpickle_BaseProtocol";
+static const char __pyx_k_pyx_unpickle_CoreProtocol[] = "__pyx_unpickle_CoreProtocol";
+static const char __pyx_k_Timer_get_remaining_budget[] = "Timer.get_remaining_budget";
+static const char __pyx_k_TimoutError_was_not_raised[] = "TimoutError was not raised";
+static const char __pyx_k_unexpected_exchange_format[] = "unexpected exchange format: {}";
+static const char __pyx_k_ConnectionDoesNotExistError[] = "ConnectionDoesNotExistError";
+static const char __pyx_k_BaseProtocol_close_statement[] = "BaseProtocol.close_statement";
+static const char __pyx_k_decode_row_statement_is_None[] = "_decode_row: statement is None";
+static const char __pyx_k_pyx_unpickle_DataCodecConfig[] = "__pyx_unpickle_DataCodecConfig";
+static const char __pyx_k_asyncpg_protocol_protocol_pyx[] = "asyncpg/protocol/protocol.pyx";
+static const char __pyx_k_missing_array_dimension_value[] = "missing array dimension value";
+static const char __pyx_k_BaseProtocol_bind_execute_many[] = "BaseProtocol.bind_execute_many";
+static const char __pyx_k_invalid_array_element_at_index[] = "invalid array element at index {}: {}";
+static const char __pyx_k_missing_after_array_dimensions[] = "missing ']' after array dimensions";
+static const char __pyx_k_Note_that_parameters_are_suppor[] = "  Note that parameters are supported only in SELECT, INSERT, UPDATE, DELETE, and VALUES statements, and will *not* work in statements  like CREATE VIEW or DECLARE CURSOR.";
+static const char __pyx_k_cannot_close_prepared_statement[] = "cannot close prepared statement; refs == {} != 0";
+static const char __pyx_k_cannot_switch_to_state_protocol[] = "cannot switch to state {}; protocol is in the \"failed\" state";
+static const char __pyx_k_got_result_for_unknown_protocol[] = "got result for unknown protocol state {}";
+static const char __pyx_k_on_result__prepare_statement_is[] = "_on_result__prepare: statement is None";
+static const char __pyx_k_parse_data_msgs_first_message_i[] = "_parse_data_msgs: first message is not \"D\"";
+static const char __pyx_k_parse_data_msgs_result_is_not_a[] = "_parse_data_msgs: result is not a list, but {!r}";
+static const char __pyx_k_protocol_is_in_an_unexpected_st[] = ": protocol is in an unexpected state ";
+static const char __pyx_k_r_is_not_a_valid_element_of_com[] = "{!r} is not a valid element of composite type {}";
+static const char __pyx_k_the_server_expects_x_argument_s[] = "the server expects {x} argument{s} for this query, {y} {w} passed";
+static const char __pyx_k_type_does_not_support_the_tuple[] = "{} type does not support the 'tuple' exchange format";
+static const char __pyx_k_type_record_missing_field_types[] = "type record missing field types for composite {}";
+static const char __pyx_k_unexpected_instance_of_anyarray[] = "unexpected instance of 'anyarray' type";
+static const char __pyx_k_unexpected_number_of_attributes[] = "unexpected number of attributes of composite type: {}, expected {}";
+static const char __pyx_k_BaseProtocol__wait_for_cancellat[] = "BaseProtocol._wait_for_cancellation";
+static const char __pyx_k_Check_the_query_against_the_pass[] = "Check the query against the passed list of arguments.";
+static const char __pyx_k_Incompatible_checksums_s_vs_0x19[] = "Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))";
+static const char __pyx_k_Incompatible_checksums_s_vs_0x4e[] = "Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))";
+static const char __pyx_k_Incompatible_checksums_s_vs_0x73[] = "Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))";
+static const char __pyx_k_a_sized_iterable_container_expec[] = "a sized iterable container expected (got type {!r})";
+static const char __pyx_k_asyncpg_Protocol_has_no_referenc[] = "asyncpg.Protocol has no reference to its Connection object and yet a cancellation was requested. Please report this at github.com/magicstack/asyncpg.";
+static const char __pyx_k_bind_execute_many_locals_genexpr[] = "bind_execute_many.<locals>.genexpr";
+static const char __pyx_k_cannot_decode_type_text_encoding[] = "cannot decode type \"{}\".\"{}\": text encoding of range types is not supported";
+static const char __pyx_k_cannot_perform_operation_another[] = "cannot perform operation: another operation is cancelling";
+static const char __pyx_k_cannot_perform_operation_connect[] = "cannot perform operation: connection is closed";
+static const char __pyx_k_cannot_register_core_codec_for_O[] = "cannot register core codec for OID {}: it is greater than MAXSUPPORTEDOID ({})";
+static const char __pyx_k_cannot_switch_to_idle_state_prot[] = "cannot switch to \"idle\" state; protocol is in the \"failed\" state";
+static const char __pyx_k_cannot_switch_to_state_another_o[] = "cannot switch to state {}; another operation ({}) is in progress";
+static const char __pyx_k_connection_was_closed_in_the_mid[] = "connection was closed in the middle of operation";
+static const char __pyx_k_expected_0_1_or_2_elements_in_ra[] = "expected 0, 1 or 2 elements in range (got {})";
+static const char __pyx_k_inconsistent_sub_array_dimension[] = "inconsistent sub-array dimensions at position {}";
+static const char __pyx_k_invalid_format_argument_expected[] = "invalid `format` argument, expected {}, got {!r}";
+static const char __pyx_k_invalid_input_for_query_argument[] = "invalid input for query argument ${n}: {v} ({msg})";
+static const char __pyx_k_invalid_timeout_value_expected_n[] = "invalid timeout value: expected non-negative float (got {!r})";
+static const char __pyx_k_list_tuple_or_Range_object_expec[] = "list, tuple or Range object expected (got type {})";
+static const char __pyx_k_missing_after_array_dimensions_2[] = "missing '=' after array dimensions";
+static const char __pyx_k_missing_codec_information_for_OI[] = "missing codec information for OID {}";
+static const char __pyx_k_no_binary_format_encoder_for_typ[] = "no binary format encoder for type {} (OID {})";
+static const char __pyx_k_no_codec_for_composite_attribute[] = "no codec for composite attribute type {}";
+static const char __pyx_k_no_decoder_for_composite_type_el[] = "no decoder for composite type element in position {} of type OID {}";
+static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
+static const char __pyx_k_number_of_array_dimensions_excee[] = "number of array dimensions ({}) exceed the maximum expected ({})";
+static const char __pyx_k_reader_is_not_an_asynchronous_it[] = "reader is not an asynchronous iterable";
+static const char __pyx_k_specified_array_dimensions_do_no[] = "specified array dimensions do not match array content";
+static const char __pyx_k_the_number_of_columns_in_the_res[] = "the number of columns in the result row ({}) is different from what was described ({})";
+static const char __pyx_k_the_number_of_query_arguments_ca[] = "the number of query arguments cannot exceed 32767";
+static const char __pyx_k_too_many_elements_in_array_value[] = "too many elements in array value";
+static const char __pyx_k_too_many_elements_in_composite_t[] = "too many elements in composite type record";
+static const char __pyx_k_type_record_missing_base_type_fo[] = "type record missing base type for domain {}";
+static const char __pyx_k_unexpected_character_r_at_positi[] = "unexpected character {!r} at position {}";
+static const char __pyx_k_unexpected_data_type_of_composit[] = "unexpected data type of composite type attribute {}: {!r}, expected {!r}";
+static const char __pyx_k_unexpected_trailing_bytes_in_buf[] = "unexpected trailing {} bytes in buffer";
+static const char __pyx_k_unhandled_standard_data_type_r_O[] = "unhandled standard data type {!r} (OID {})";
+static const char __pyx_k_unknown_error_in_protocol_implem[] = "unknown error in protocol implementation";
+static const char __pyx_k_unsupported_authentication_metho[] = "unsupported authentication method requested by the server: {!r}";
+static const char __pyx_k_waiter_is_not_done_while_handlin[] = "waiter is not done while handling critical protocol error";
+static const char __pyx_k_cannot_decode_type_text_encoding_2[] = "cannot decode type \"{}\".\"{}\": text encoding of composite types is not supported";
+static const char __pyx_k_cannot_perform_operation_another_2[] = "cannot perform operation: another operation is in progress";
+static const char __pyx_k_type_record_missing_base_type_fo_2[] = "type record missing base type for range {}";
+static const char __pyx_k_unsupported_authentication_metho_2[] = "unsupported authentication method requested by the server: {}";
+static PyObject *__pyx_n_s_AF_UNIX;
+static PyObject *__pyx_n_u_AF_UNIX;
+static PyObject *__pyx_n_s_ARRAY_TYPES;
+static PyObject *__pyx_n_s_AUTH_METHOD_NAME;
+static PyObject *__pyx_n_s_AssertionError;
+static PyObject *__pyx_n_s_Attribute;
+static PyObject *__pyx_n_s_AttributeError;
+static PyObject *__pyx_n_s_BUILTIN_TYPE_NAME_MAP;
+static PyObject *__pyx_n_s_BUILTIN_TYPE_OID_MAP;
+static PyObject *__pyx_n_s_BaseProtocol;
+static PyObject *__pyx_n_s_BaseProtocol__wait_for_cancellat;
+static PyObject *__pyx_n_s_BaseProtocol_bind;
+static PyObject *__pyx_n_s_BaseProtocol_bind_execute;
+static PyObject *__pyx_n_s_BaseProtocol_bind_execute_many;
+static PyObject *__pyx_n_s_BaseProtocol_close;
+static PyObject *__pyx_n_s_BaseProtocol_close_statement;
+static PyObject *__pyx_n_s_BaseProtocol_copy_in;
+static PyObject *__pyx_n_s_BaseProtocol_copy_out;
+static PyObject *__pyx_n_s_BaseProtocol_execute;
+static PyObject *__pyx_n_s_BaseProtocol_prepare;
+static PyObject *__pyx_n_s_BaseProtocol_query;
+static PyObject *__pyx_n_s_BufferError;
+static PyObject *__pyx_kp_u_Check_the_query_against_the_pass;
+static PyObject *__pyx_n_s_Codec;
+static PyObject *__pyx_kp_u_Codec_oid_elem_oid_core;
+static PyObject *__pyx_n_s_ConnectionDoesNotExistError;
+static PyObject *__pyx_n_s_ConnectionResetError;
+static PyObject *__pyx_n_s_ConnectionSettings;
+static PyObject *__pyx_kp_u_ConnectionSettings_r;
+static PyObject *__pyx_n_s_CoreProtocol;
+static PyObject *__pyx_n_s_DataCodecConfig;
+static PyObject *__pyx_n_s_DataError;
+static PyObject *__pyx_n_s_Event;
+static PyObject *__pyx_n_s_Future;
+static PyObject *__pyx_n_s_IPPROTO_TCP;
+static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x19;
+static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x4e;
+static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x73;
+static PyObject *__pyx_n_s_InterfaceError;
+static PyObject *__pyx_n_s_InternalClientError;
+static PyObject *__pyx_n_s_Iterable;
+static PyObject *__pyx_n_s_IterableABC;
+static PyObject *__pyx_n_s_KeyError;
+static PyObject *__pyx_n_s_Mapping;
+static PyObject *__pyx_n_s_MappingABC;
+static PyObject *__pyx_n_u_NA;
+static PyObject *__pyx_n_s_NO_TIMEOUT;
+static PyObject *__pyx_n_b_NULL;
+static PyObject *__pyx_kp_b_NULL_2;
+static PyObject *__pyx_n_s_NotImplementedError;
+static PyObject *__pyx_kp_u_Note_that_parameters_are_suppor;
+static PyObject *__pyx_kp_u_OID_value_too_large_r;
+static PyObject *__pyx_n_s_OrderedDict;
+static PyObject *__pyx_n_s_OutdatedSchemaCacheError;
+static PyObject *__pyx_n_s_OverflowError;
+static PyObject *__pyx_kp_b_PGCOPY;
+static PyObject *__pyx_n_s_PickleError;
+static PyObject *__pyx_n_s_PostgresError;
+static PyObject *__pyx_n_s_PreparedStatementState;
+static PyObject *__pyx_n_s_Protocol;
+static PyObject *__pyx_n_s_ProtocolError;
+static PyObject *__pyx_n_s_Range;
+static PyObject *__pyx_n_s_Record;
+static PyObject *__pyx_n_s_Sized;
+static PyObject *__pyx_n_s_SizedABC;
+static PyObject *__pyx_n_s_StopAsyncIteration;
+static PyObject *__pyx_n_s_StopIteration;
+static PyObject *__pyx_n_s_TCP_NODELAY;
+static PyObject *__pyx_n_s_TimeoutError;
+static PyObject *__pyx_n_u_TimeoutError;
+static PyObject *__pyx_n_s_Timer;
+static PyObject *__pyx_n_s_Timer___enter;
+static PyObject *__pyx_n_s_Timer___exit;
+static PyObject *__pyx_n_s_Timer___init;
+static PyObject *__pyx_n_s_Timer_get_remaining_budget;
+static PyObject *__pyx_kp_u_TimoutError_was_not_raised;
+static PyObject *__pyx_n_s_Type;
+static PyObject *__pyx_n_s_TypeError;
+static PyObject *__pyx_n_s_ValueError;
+static PyObject *__pyx_kp_b__18;
+static PyObject *__pyx_n_u__2;
+static PyObject *__pyx_kp_u__24;
+static PyObject *__pyx_kp_b__25;
+static PyObject *__pyx_kp_u__25;
+static PyObject *__pyx_kp_u__26;
+static PyObject *__pyx_kp_u__28;
+static PyObject *__pyx_kp_u__9;
+static PyObject *__pyx_kp_u_a_sized_iterable_container_expec;
+static PyObject *__pyx_n_u_abc;
+static PyObject *__pyx_n_s_abort;
+static PyObject *__pyx_n_u_abstime;
+static PyObject *__pyx_n_u_aclitem;
+static PyObject *__pyx_n_s_add_done_callback;
+static PyObject *__pyx_n_s_add_python_codec;
+static PyObject *__pyx_n_s_add_types;
+static PyObject *__pyx_n_s_addr;
+static PyObject *__pyx_n_s_aiter;
+static PyObject *__pyx_n_s_alias_to;
+static PyObject *__pyx_kp_u_already_connected;
+static PyObject *__pyx_n_u_alt;
+static PyObject *__pyx_n_s_anext;
+static PyObject *__pyx_n_u_any;
+static PyObject *__pyx_n_u_anyarray;
+static PyObject *__pyx_n_u_anyelement;
+static PyObject *__pyx_n_u_anyenum;
+static PyObject *__pyx_n_u_anynonarray;
+static PyObject *__pyx_n_u_anyrange;
+static PyObject *__pyx_n_s_apg_exc;
+static PyObject *__pyx_n_s_apg_exc_base;
+static PyObject *__pyx_n_s_apg_types;
+static PyObject *__pyx_n_s_args;
+static PyObject *__pyx_n_u_array;
+static PyObject *__pyx_n_u_ascii;
+static PyObject *__pyx_n_s_asyncio;
+static PyObject *__pyx_n_s_asyncio_coroutines;
+static PyObject *__pyx_n_s_asyncio_tasks;
+static PyObject *__pyx_n_s_asyncpg;
+static PyObject *__pyx_kp_u_asyncpg_Protocol_has_no_referenc;
+static PyObject *__pyx_n_s_asyncpg_exceptions;
+static PyObject *__pyx_n_s_asyncpg_protocol_protocol;
+static PyObject *__pyx_kp_s_asyncpg_protocol_protocol_pyx;
+static PyObject *__pyx_n_u_attrnames;
+static PyObject *__pyx_n_u_attrtypoids;
+static PyObject *__pyx_n_s_auth_msg;
+static PyObject *__pyx_n_s_await;
+static PyObject *__pyx_n_s_base;
+static PyObject *__pyx_n_u_basetype;
+static PyObject *__pyx_n_u_bigint;
+static PyObject *__pyx_n_u_binary;
+static PyObject *__pyx_n_s_bind;
+static PyObject *__pyx_n_s_bind_execute;
+static PyObject *__pyx_n_s_bind_execute_many;
+static PyObject *__pyx_n_s_bind_execute_many_locals_genexpr;
+static PyObject *__pyx_n_u_bit;
+static PyObject *__pyx_n_u_bool;
+static PyObject *__pyx_n_u_box;
+static PyObject *__pyx_n_u_bpchar;
+static PyObject *__pyx_n_s_budget;
+static PyObject *__pyx_n_s_budget_2;
+static PyObject *__pyx_n_s_builtins;
+static PyObject *__pyx_n_u_bytea;
+static PyObject *__pyx_n_b_c;
+static PyObject *__pyx_n_s_cache_key;
+static PyObject *__pyx_n_s_call_exception_handler;
+static PyObject *__pyx_n_s_call_later;
+static PyObject *__pyx_n_s_cancel;
+static PyObject *__pyx_n_s_cancel_current_command;
+static PyObject *__pyx_n_s_cancelled;
+static PyObject *__pyx_kp_u_cannot_alias;
+static PyObject *__pyx_kp_u_cannot_close_prepared_statement;
+static PyObject *__pyx_kp_u_cannot_decode_type_text_encoding;
+static PyObject *__pyx_kp_u_cannot_decode_type_text_encoding_2;
+static PyObject *__pyx_kp_u_cannot_perform_operation_another;
+static PyObject *__pyx_kp_u_cannot_perform_operation_another_2;
+static PyObject *__pyx_kp_u_cannot_perform_operation_connect;
+static PyObject *__pyx_kp_u_cannot_process_message;
+static PyObject *__pyx_kp_u_cannot_register_core_codec_for_O;
+static PyObject *__pyx_kp_u_cannot_switch_to_idle_state_prot;
+static PyObject *__pyx_kp_u_cannot_switch_to_state_another_o;
+static PyObject *__pyx_kp_u_cannot_switch_to_state_protocol;
+static PyObject *__pyx_n_s_cause;
+static PyObject *__pyx_n_u_char;
+static PyObject *__pyx_n_s_chr;
+static PyObject *__pyx_n_u_cid;
+static PyObject *__pyx_n_u_cidr;
+static PyObject *__pyx_n_u_circle;
+static PyObject *__pyx_n_s_cleanup;
+static PyObject *__pyx_n_s_clear;
+static PyObject *__pyx_n_s_clear_type_cache;
+static PyObject *__pyx_n_b_client_encoding;
+static PyObject *__pyx_n_u_client_encoding;
+static PyObject *__pyx_n_s_cline_in_traceback;
+static PyObject *__pyx_n_s_close;
+static PyObject *__pyx_n_s_close_statement;
+static PyObject *__pyx_kp_u_codec_for;
+static PyObject *__pyx_n_s_codecs;
+static PyObject *__pyx_n_s_collections;
+static PyObject *__pyx_n_s_collections_abc;
+static PyObject *__pyx_n_s_command_timeout;
+static PyObject *__pyx_n_s_compat;
+static PyObject *__pyx_n_u_composite;
+static PyObject *__pyx_n_s_con_params;
+static PyObject *__pyx_n_s_config;
+static PyObject *__pyx_n_s_conn_key;
+static PyObject *__pyx_n_s_connected_fut;
+static PyObject *__pyx_kp_u_connection_was_closed_in_the_mid;
+static PyObject *__pyx_n_s_copy_in;
+static PyObject *__pyx_n_s_copy_in_locals_lambda;
+static PyObject *__pyx_n_s_copy_out;
+static PyObject *__pyx_n_s_copy_out_locals_lambda;
+static PyObject *__pyx_n_s_copy_stmt;
+static PyObject *__pyx_n_u_cp1250;
+static PyObject *__pyx_n_u_cp1251;
+static PyObject *__pyx_n_u_cp1252;
+static PyObject *__pyx_n_u_cp1253;
+static PyObject *__pyx_n_u_cp1254;
+static PyObject *__pyx_n_u_cp1255;
+static PyObject *__pyx_n_u_cp1256;
+static PyObject *__pyx_n_u_cp1257;
+static PyObject *__pyx_n_u_cp1258;
+static PyObject *__pyx_n_u_cp1521;
+static PyObject *__pyx_n_u_cp866;
+static PyObject *__pyx_n_u_cp874;
+static PyObject *__pyx_n_u_cp932;
+static PyObject *__pyx_n_u_cp936;
+static PyObject *__pyx_n_u_cp949;
+static PyObject *__pyx_n_u_cp950;
+static PyObject *__pyx_n_s_create_future;
+static PyObject *__pyx_n_s_create_future_fallback;
+static PyObject *__pyx_n_s_create_record;
+static PyObject *__pyx_n_u_cstring;
+static PyObject *__pyx_n_b_d;
+static PyObject *__pyx_n_s_data;
+static PyObject *__pyx_n_s_data_type;
+static PyObject *__pyx_n_s_database;
+static PyObject *__pyx_n_u_database;
+static PyObject *__pyx_n_u_date;
+static PyObject *__pyx_n_u_decimal;
+static PyObject *__pyx_n_s_declare_fallback_codec;
+static PyObject *__pyx_n_s_decode;
+static PyObject *__pyx_kp_u_decode_row_statement_is_None;
+static PyObject *__pyx_n_s_decoder;
+static PyObject *__pyx_n_s_desc;
+static PyObject *__pyx_n_s_dict;
+static PyObject *__pyx_n_s_doc;
+static PyObject *__pyx_n_s_done;
+static PyObject *__pyx_kp_u_double_precision;
+static PyObject *__pyx_n_b_e;
+static PyObject *__pyx_n_s_e;
+static PyObject *__pyx_n_s_elem;
+static PyObject *__pyx_n_u_elem_has_bin_io;
+static PyObject *__pyx_n_u_elemdelim;
+static PyObject *__pyx_n_s_elems;
+static PyObject *__pyx_n_u_elemtype;
+static PyObject *__pyx_n_s_empty;
+static PyObject *__pyx_n_s_encode;
+static PyObject *__pyx_n_s_encoder;
+static PyObject *__pyx_n_s_enter;
+static PyObject *__pyx_n_s_enumerate;
+static PyObject *__pyx_n_s_et;
+static PyObject *__pyx_n_u_euc_cn;
+static PyObject *__pyx_n_u_euc_jis_2004;
+static PyObject *__pyx_n_u_euc_jp;
+static PyObject *__pyx_n_u_euc_kr;
+static PyObject *__pyx_n_u_euccn;
+static PyObject *__pyx_n_u_eucjp;
+static PyObject *__pyx_n_u_euckr;
+static PyObject *__pyx_n_u_event_trigger;
+static PyObject *__pyx_n_s_exception;
+static PyObject *__pyx_n_s_exceptions;
+static PyObject *__pyx_n_s_execute;
+static PyObject *__pyx_n_s_exit;
+static PyObject *__pyx_kp_u_expected_0_1_or_2_elements_in_ra;
+static PyObject *__pyx_n_s_family;
+static PyObject *__pyx_n_u_fdw_handler;
+static PyObject *__pyx_n_u_float4;
+static PyObject *__pyx_n_u_float8;
+static PyObject *__pyx_n_s_format;
+static PyObject *__pyx_n_s_genexpr;
+static PyObject *__pyx_n_s_get;
+static PyObject *__pyx_n_s_get_extra_info;
+static PyObject *__pyx_n_s_get_remaining_budget;
+static PyObject *__pyx_n_s_get_timeout;
+static PyObject *__pyx_n_s_getattr;
+static PyObject *__pyx_n_s_getstate;
+static PyObject *__pyx_kp_u_got_result_for_unknown_protocol;
+static PyObject *__pyx_n_u_gtsvector;
+static PyObject *__pyx_n_u_has_bin_io;
+static PyObject *__pyx_n_s_hashlib;
+static PyObject *__pyx_n_s_hashlib_md5;
+static PyObject *__pyx_n_s_hexdigest;
+static PyObject *__pyx_n_s_hint;
+static PyObject *__pyx_n_s_i;
+static PyObject *__pyx_n_s_import;
+static PyObject *__pyx_kp_u_inconsistent_sub_array_dimension;
+static PyObject *__pyx_n_u_index_am_handler;
+static PyObject *__pyx_n_u_inet;
+static PyObject *__pyx_n_s_init;
+static PyObject *__pyx_n_s_inspect;
+static PyObject *__pyx_n_u_int;
+static PyObject *__pyx_n_u_int2;
+static PyObject *__pyx_n_u_int4;
+static PyObject *__pyx_n_u_int8;
+static PyObject *__pyx_n_u_integer;
+static PyObject *__pyx_n_u_internal;
+static PyObject *__pyx_n_u_interval;
+static PyObject *__pyx_kp_u_invalid_array_element;
+static PyObject *__pyx_kp_u_invalid_array_element_at_index;
+static PyObject *__pyx_kp_u_invalid_data_format;
+static PyObject *__pyx_kp_u_invalid_format_argument_expected;
+static PyObject *__pyx_kp_u_invalid_input_for_query_argument;
+static PyObject *__pyx_kp_u_invalid_timeout_value_expected_n;
+static PyObject *__pyx_n_s_isempty;
+static PyObject *__pyx_n_s_items;
+static PyObject *__pyx_n_u_json;
+static PyObject *__pyx_n_u_jsonb;
+static PyObject *__pyx_n_u_kind;
+static PyObject *__pyx_n_u_koi8_r;
+static PyObject *__pyx_n_u_koi8_u;
+static PyObject *__pyx_n_u_koi8r;
+static PyObject *__pyx_n_u_koi8u;
+static PyObject *__pyx_n_u_language_handler;
+static PyObject *__pyx_n_s_limit;
+static PyObject *__pyx_n_u_line;
+static PyObject *__pyx_kp_u_list_tuple_or_Range_object_expec;
+static PyObject *__pyx_n_s_lookup;
+static PyObject *__pyx_n_s_loop;
+static PyObject *__pyx_n_s_lower;
+static PyObject *__pyx_n_s_lower_inc;
+static PyObject *__pyx_n_u_lseg;
+static PyObject *__pyx_n_u_macaddr;
+static PyObject *__pyx_n_u_macaddr8;
+static PyObject *__pyx_n_s_main;
+static PyObject *__pyx_kp_u_malformed_array_literal_r;
+static PyObject *__pyx_n_s_mapping;
+static PyObject *__pyx_n_b_md5;
+static PyObject *__pyx_n_s_md5;
+static PyObject *__pyx_n_s_memoryview;
+static PyObject *__pyx_n_u_message;
+static PyObject *__pyx_n_s_metaclass;
+static PyObject *__pyx_kp_u_missing_after_array_dimensions;
+static PyObject *__pyx_kp_u_missing_after_array_dimensions_2;
+static PyObject *__pyx_kp_u_missing_array_dimension_value;
+static PyObject *__pyx_kp_u_missing_codec_information_for_OI;
+static PyObject *__pyx_n_s_module;
+static PyObject *__pyx_n_u_money;
+static PyObject *__pyx_n_s_monotonic;
+static PyObject *__pyx_n_s_msg;
+static PyObject *__pyx_n_s_n;
+static PyObject *__pyx_n_s_name;
+static PyObject *__pyx_n_u_name;
+static PyObject *__pyx_n_s_name_2;
+static PyObject *__pyx_n_s_new;
+static PyObject *__pyx_n_s_new_2;
+static PyObject *__pyx_kp_u_no_binary_format_encoder_for_typ;
+static PyObject *__pyx_kp_u_no_codec_for_composite_attribute;
+static PyObject *__pyx_kp_u_no_decoder_for_OID;
+static PyObject *__pyx_kp_u_no_decoder_for_composite_type_el;
+static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
+static PyObject *__pyx_kp_u_no_encoder_for_OID;
+static PyObject *__pyx_kp_u_non_homogeneous_array;
+static PyObject *__pyx_kp_u_not_connected;
+static PyObject *__pyx_n_u_ns;
+static PyObject *__pyx_kp_u_number_of_array_dimensions_excee;
+static PyObject *__pyx_n_u_numeric;
+static PyObject *__pyx_n_s_object;
+static PyObject *__pyx_n_s_oid;
+static PyObject *__pyx_n_u_oid;
+static PyObject *__pyx_kp_u_oid_2;
+static PyObject *__pyx_n_s_on_error;
+static PyObject *__pyx_kp_u_on_result__prepare_statement_is;
+static PyObject *__pyx_kp_u_on_result_waiter_is_None;
+static PyObject *__pyx_kp_u_on_result_waiter_is_done;
+static PyObject *__pyx_n_s_on_timeout;
+static PyObject *__pyx_n_s_on_waiter_completed;
+static PyObject *__pyx_n_u_opaque;
+static PyObject *__pyx_kp_u_parse_data_msgs_first_message_i;
+static PyObject *__pyx_kp_u_parse_data_msgs_result_is_not_a;
+static PyObject *__pyx_n_s_password;
+static PyObject *__pyx_n_u_path;
+static PyObject *__pyx_n_s_pause_reading;
+static PyObject *__pyx_n_u_pg_catalog;
+static PyObject *__pyx_kp_u_pg_contrib_hstore;
+static PyObject *__pyx_n_u_pg_ddl_command;
+static PyObject *__pyx_n_u_pg_dependencies;
+static PyObject *__pyx_n_u_pg_lsn;
+static PyObject *__pyx_n_u_pg_ndistinct;
+static PyObject *__pyx_n_u_pg_node_tree;
+static PyObject *__pyx_n_s_pickle;
+static PyObject *__pyx_n_u_point;
+static PyObject *__pyx_n_u_polygon;
+static PyObject *__pyx_n_s_pop;
+static PyObject *__pyx_n_s_portal_name;
+static PyObject *__pyx_n_s_position;
+static PyObject *__pyx_n_s_prepare;
+static PyObject *__pyx_n_s_prepare_2;
+static PyObject *__pyx_n_s_process_log_message;
+static PyObject *__pyx_n_s_process_notification;
+static PyObject *__pyx_n_s_protocol;
+static PyObject *__pyx_kp_u_protocol_is_in_an_unexpected_st;
+static PyObject *__pyx_n_s_pyx_PickleError;
+static PyObject *__pyx_n_s_pyx_capi;
+static PyObject *__pyx_n_s_pyx_checksum;
+static PyObject *__pyx_n_s_pyx_result;
+static PyObject *__pyx_n_s_pyx_state;
+static PyObject *__pyx_n_s_pyx_type;
+static PyObject *__pyx_n_s_pyx_unpickle_BaseProtocol;
+static PyObject *__pyx_n_s_pyx_unpickle_CoreProtocol;
+static PyObject *__pyx_n_s_pyx_unpickle_DataCodecConfig;
+static PyObject *__pyx_n_s_pyx_vtable;
+static PyObject *__pyx_n_s_qualname;
+static PyObject *__pyx_n_s_query;
+static PyObject *__pyx_n_b_r;
+static PyObject *__pyx_kp_u_r_is_not_a_valid_element_of_com;
+static PyObject *__pyx_n_s_range;
+static PyObject *__pyx_n_u_range;
+static PyObject *__pyx_n_u_range_subtype;
+static PyObject *__pyx_n_s_reader;
+static PyObject *__pyx_kp_u_reader_is_not_an_asynchronous_it;
+static PyObject *__pyx_n_u_real;
+static PyObject *__pyx_n_s_rec;
+static PyObject *__pyx_n_u_record;
+static PyObject *__pyx_n_s_record_stmt;
+static PyObject *__pyx_n_s_records;
+static PyObject *__pyx_n_s_reduce;
+static PyObject *__pyx_n_s_reduce_cython;
+static PyObject *__pyx_n_s_reduce_ex;
+static PyObject *__pyx_n_s_ref;
+static PyObject *__pyx_n_u_refcursor;
+static PyObject *__pyx_n_u_regclass;
+static PyObject *__pyx_n_u_regconfig;
+static PyObject *__pyx_n_u_regdictionary;
+static PyObject *__pyx_n_u_regnamespace;
+static PyObject *__pyx_n_u_regoper;
+static PyObject *__pyx_n_u_regoperator;
+static PyObject *__pyx_n_u_regproc;
+static PyObject *__pyx_n_u_regprocedure;
+static PyObject *__pyx_n_u_regrole;
+static PyObject *__pyx_n_u_regtype;
+static PyObject *__pyx_n_s_release;
+static PyObject *__pyx_n_u_reltime;
+static PyObject *__pyx_n_s_remove_python_codec;
+static PyObject *__pyx_n_s_request_cancel;
+static PyObject *__pyx_n_s_resume_reading;
+static PyObject *__pyx_n_s_return_extra;
+static PyObject *__pyx_n_s_reversed;
+static PyObject *__pyx_n_s_s;
+static PyObject *__pyx_n_u_s;
+static PyObject *__pyx_n_u_scalar;
+static PyObject *__pyx_n_s_schema;
+static PyObject *__pyx_n_s_self;
+static PyObject *__pyx_n_s_send;
+static PyObject *__pyx_n_s_server_settings;
+static PyObject *__pyx_n_s_set;
+static PyObject *__pyx_n_s_set_builtin_type_codec;
+static PyObject *__pyx_n_s_set_builtin_type_codec_2;
+static PyObject *__pyx_n_s_set_exception;
+static PyObject *__pyx_n_s_set_result;
+static PyObject *__pyx_n_s_setsockopt;
+static PyObject *__pyx_n_s_setstate;
+static PyObject *__pyx_n_s_setstate_cython;
+static PyObject *__pyx_n_u_shift_jis;
+static PyObject *__pyx_n_u_shift_jis_2004;
+static PyObject *__pyx_n_s_sink;
+static PyObject *__pyx_n_u_sjis;
+static PyObject *__pyx_n_u_smallint;
+static PyObject *__pyx_n_u_smgr;
+static PyObject *__pyx_n_s_socket;
+static PyObject *__pyx_n_u_socket;
+static PyObject *__pyx_kp_u_specified_array_dimensions_do_no;
+static PyObject *__pyx_n_u_sql_ascii;
+static PyObject *__pyx_n_s_started;
+static PyObject *__pyx_n_s_startswith;
+static PyObject *__pyx_n_s_state;
+static PyObject *__pyx_n_s_stmt_name;
+static PyObject *__pyx_kp_s_stringsource;
+static PyObject *__pyx_n_s_tb;
+static PyObject *__pyx_n_u_tcvn;
+static PyObject *__pyx_n_u_tcvn5712;
+static PyObject *__pyx_n_s_test;
+static PyObject *__pyx_n_u_text;
+static PyObject *__pyx_kp_u_text_2;
+static PyObject *__pyx_kp_u_text_binary_or_tuple;
+static PyObject *__pyx_kp_u_text_or_binary;
+static PyObject *__pyx_kp_u_text_or_binary_2;
+static PyObject *__pyx_kp_u_the_number_of_columns_in_the_res;
+static PyObject *__pyx_kp_u_the_number_of_query_arguments_ca;
+static PyObject *__pyx_kp_u_the_server_expects_x_argument_s;
+static PyObject *__pyx_kp_u_there_is_no;
+static PyObject *__pyx_n_s_throw;
+static PyObject *__pyx_n_u_tid;
+static PyObject *__pyx_n_s_time;
+static PyObject *__pyx_n_u_time;
+static PyObject *__pyx_kp_u_time_with_timezone;
+static PyObject *__pyx_n_s_timeout;
+static PyObject *__pyx_n_u_timestamp;
+static PyObject *__pyx_kp_u_timestamp_with_timezone;
+static PyObject *__pyx_n_u_timestamptz;
+static PyObject *__pyx_n_u_timetz;
+static PyObject *__pyx_n_u_tinterval;
+static PyObject *__pyx_kp_u_to;
+static PyObject *__pyx_kp_u_too_many_elements_in_array_value;
+static PyObject *__pyx_kp_u_too_many_elements_in_composite_t;
+static PyObject *__pyx_n_u_trigger;
+static PyObject *__pyx_n_u_tsm_handler;
+static PyObject *__pyx_n_u_tsquery;
+static PyObject *__pyx_n_u_tsvector;
+static PyObject *__pyx_n_u_tuple;
+static PyObject *__pyx_n_u_txid_snapshot;
+static PyObject *__pyx_kp_u_type_does_not_support_the_tuple;
+static PyObject *__pyx_kp_u_type_record_missing_base_type_fo;
+static PyObject *__pyx_kp_u_type_record_missing_base_type_fo_2;
+static PyObject *__pyx_kp_u_type_record_missing_field_types;
+static PyObject *__pyx_n_s_typekind;
+static PyObject *__pyx_n_s_typename;
+static PyObject *__pyx_n_s_typeoid;
+static PyObject *__pyx_n_s_types;
+static PyObject *__pyx_n_s_typeschema;
+static PyObject *__pyx_kp_u_unexpected_character_r_at_positi;
+static PyObject *__pyx_kp_u_unexpected_codec_type;
+static PyObject *__pyx_kp_u_unexpected_data_format;
+static PyObject *__pyx_kp_u_unexpected_data_type_of_composit;
+static PyObject *__pyx_kp_u_unexpected_end_of_string;
+static PyObject *__pyx_kp_u_unexpected_exchange_format;
+static PyObject *__pyx_kp_u_unexpected_instance_of_anyarray;
+static PyObject *__pyx_kp_u_unexpected_ndims_value;
+static PyObject *__pyx_kp_u_unexpected_number_of_attributes;
+static PyObject *__pyx_kp_u_unexpected_trailing_bytes_in_buf;
+static PyObject *__pyx_kp_u_unhandled_standard_data_type_r_O;
+static PyObject *__pyx_n_u_unicode;
+static PyObject *__pyx_n_u_unknown;
+static PyObject *__pyx_kp_u_unknown_error_in_protocol_implem;
+static PyObject *__pyx_kp_u_unsupported_authentication_metho;
+static PyObject *__pyx_kp_u_unsupported_authentication_metho_2;
+static PyObject *__pyx_n_s_update;
+static PyObject *__pyx_n_s_upper;
+static PyObject *__pyx_n_s_upper_inc;
+static PyObject *__pyx_n_s_user;
+static PyObject *__pyx_n_u_user;
+static PyObject *__pyx_kp_u_utf_8;
+static PyObject *__pyx_n_u_utf_8_2;
+static PyObject *__pyx_n_u_uuid;
+static PyObject *__pyx_n_s_v;
+static PyObject *__pyx_n_u_varbit;
+static PyObject *__pyx_n_u_varchar;
+static PyObject *__pyx_n_u_void;
+static PyObject *__pyx_n_u_vscii;
+static PyObject *__pyx_n_s_w;
+static PyObject *__pyx_n_s_wait;
+static PyObject *__pyx_n_s_wait_for;
+static PyObject *__pyx_n_s_wait_for_cancellation;
+static PyObject *__pyx_kp_u_waiter_is_not_done_while_handlin;
+static PyObject *__pyx_n_u_was;
+static PyObject *__pyx_n_s_weakref;
+static PyObject *__pyx_n_u_were;
+static PyObject *__pyx_n_u_win;
+static PyObject *__pyx_n_u_win1250;
+static PyObject *__pyx_n_u_win1251;
+static PyObject *__pyx_n_u_win1252;
+static PyObject *__pyx_n_u_win1253;
+static PyObject *__pyx_n_u_win1254;
+static PyObject *__pyx_n_u_win1255;
+static PyObject *__pyx_n_u_win1256;
+static PyObject *__pyx_n_u_win1257;
+static PyObject *__pyx_n_u_win1258;
+static PyObject *__pyx_n_u_win866;
+static PyObject *__pyx_n_u_win874;
+static PyObject *__pyx_n_u_win932;
+static PyObject *__pyx_n_u_win936;
+static PyObject *__pyx_n_u_win949;
+static PyObject *__pyx_n_u_win950;
+static PyObject *__pyx_n_u_windows1250;
+static PyObject *__pyx_n_u_windows1251;
+static PyObject *__pyx_n_u_windows1252;
+static PyObject *__pyx_n_u_windows1253;
+static PyObject *__pyx_n_u_windows1254;
+static PyObject *__pyx_n_u_windows1255;
+static PyObject *__pyx_n_u_windows1256;
+static PyObject *__pyx_n_u_windows1257;
+static PyObject *__pyx_n_u_windows1258;
+static PyObject *__pyx_n_u_windows866;
+static PyObject *__pyx_n_u_windows874;
+static PyObject *__pyx_n_u_windows932;
+static PyObject *__pyx_n_u_windows936;
+static PyObject *__pyx_n_u_windows949;
+static PyObject *__pyx_n_u_windows950;
+static PyObject *__pyx_n_s_write;
+static PyObject *__pyx_n_s_writing_allowed;
+static PyObject *__pyx_n_s_x;
+static PyObject *__pyx_n_s_xformat;
+static PyObject *__pyx_n_u_xid;
+static PyObject *__pyx_n_u_xml;
+static PyObject *__pyx_n_s_y;
+static int __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings___cinit__(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_conn_key); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_2get_text_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_4register_data_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_types); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_6add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, PyObject *__pyx_v_format); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_8remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_10clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_12set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_14get_data_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, uint32_t __pyx_v_oid, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_16__getattr__(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_name); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_18__repr__(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_20__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_22__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
+static int __pyx_pf_7asyncpg_8protocol_8protocol_5Codec___cinit__(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, uint32_t __pyx_v_oid); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Codec_2__repr__(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Codec_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Codec_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
+static int __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig___init__(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_cache_key); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_2add_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_types); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_4add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, PyObject *__pyx_v_format, PyObject *__pyx_v_xformat); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_6remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, CYTHON_UNUSED PyObject *__pyx_v_typename, CYTHON_UNUSED PyObject *__pyx_v_typeschema); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_8_set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_10set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_12clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_14declare_fallback_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_16__reduce_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_18__setstate_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
+static int __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol___init__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_con_params); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_11backend_pid___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_14backend_secret___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_2__reduce_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_4__setstate_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
+static int __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState___cinit__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_query, struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_protocol); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_2_get_parameters(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4_get_attributes(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_6_init_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_8_init_codecs(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_10attach(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_12detach(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_14mark_closed(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4name___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_5query___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_6closed___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4refs___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_16__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_18__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
+static int __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol___init__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_addr, PyObject *__pyx_v_connected_fut, PyObject *__pyx_v_con_params, PyObject *__pyx_v_loop); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_2set_connection(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_connection); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_4get_server_pid(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_6get_settings(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_8is_in_transaction(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_10prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_stmt_name, PyObject *__pyx_v_query, PyObject *__pyx_v_timeout, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_13bind_execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_args, PyObject *__pyx_v_portal_name, int __pyx_v_limit, PyObject *__pyx_v_return_extra, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many_genexpr(PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_16bind_execute_many(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_args, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_19bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_args, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_22execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_portal_name, int __pyx_v_limit, PyObject *__pyx_v_return_extra, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_25query(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_query, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_lambda_funcdef_lambda1(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_28copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt, PyObject *__pyx_v_sink, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_lambda_funcdef_lambda2(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_31copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt, PyObject *__pyx_v_reader, PyObject *__pyx_v_data, PyObject *__pyx_v_records, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_record_stmt, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_34close_statement(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_37is_closed(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_39is_connected(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_41abort(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_43close(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_46_request_cancel(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_48_on_timeout(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_fut); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_50_on_waiter_completed(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_fut); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_52_create_future_fallback(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_54_get_timeout(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_56_is_cancelling(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_58_wait_for_cancellation(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_61data_received(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_data); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_63connection_made(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_transport); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_65connection_lost(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_exc); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_67pause_writing(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_69resume_writing(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_13queries_count___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_71__reduce_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_73__setstate_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_budget); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer_2__enter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer_4__exit__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_et, CYTHON_UNUSED PyObject *__pyx_v_e, CYTHON_UNUSED PyObject *__pyx_v_tb); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer_6get_remaining_budget(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol__create_record(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mapping, PyObject *__pyx_v_elems); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_2__pyx_unpickle_DataCodecConfig(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_4__pyx_unpickle_CoreProtocol(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_6__pyx_unpickle_BaseProtocol(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_Codec(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_DataCodecConfig(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_ConnectionSettings(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_CoreProtocol(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_PreparedStatementState(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_BaseProtocol(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, &__pyx_n_s_get, 0, 0, 0};
+static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0};
+static PyObject *__pyx_int_0;
+static PyObject *__pyx_int_1;
+static PyObject *__pyx_int_4;
+static PyObject *__pyx_int_6;
+static PyObject *__pyx_int_16;
+static PyObject *__pyx_int_17;
+static PyObject *__pyx_int_18;
+static PyObject *__pyx_int_19;
+static PyObject *__pyx_int_20;
+static PyObject *__pyx_int_21;
+static PyObject *__pyx_int_23;
+static PyObject *__pyx_int_24;
+static PyObject *__pyx_int_25;
+static PyObject *__pyx_int_26;
+static PyObject *__pyx_int_27;
+static PyObject *__pyx_int_28;
+static PyObject *__pyx_int_29;
+static PyObject *__pyx_int_32;
+static PyObject *__pyx_int_40;
+static PyObject *__pyx_int_114;
+static PyObject *__pyx_int_142;
+static PyObject *__pyx_int_194;
+static PyObject *__pyx_int_210;
+static PyObject *__pyx_int_325;
+static PyObject *__pyx_int_600;
+static PyObject *__pyx_int_601;
+static PyObject *__pyx_int_602;
+static PyObject *__pyx_int_603;
+static PyObject *__pyx_int_604;
+static PyObject *__pyx_int_628;
+static PyObject *__pyx_int_650;
+static PyObject *__pyx_int_700;
+static PyObject *__pyx_int_701;
+static PyObject *__pyx_int_702;
+static PyObject *__pyx_int_703;
+static PyObject *__pyx_int_704;
+static PyObject *__pyx_int_705;
+static PyObject *__pyx_int_718;
+static PyObject *__pyx_int_774;
+static PyObject *__pyx_int_790;
+static PyObject *__pyx_int_829;
+static PyObject *__pyx_int_869;
+static PyObject *__pyx_int_1009;
+static PyObject *__pyx_int_1028;
+static PyObject *__pyx_int_1033;
+static PyObject *__pyx_int_1042;
+static PyObject *__pyx_int_1043;
+static PyObject *__pyx_int_1082;
+static PyObject *__pyx_int_1083;
+static PyObject *__pyx_int_1114;
+static PyObject *__pyx_int_1184;
+static PyObject *__pyx_int_1186;
+static PyObject *__pyx_int_1266;
+static PyObject *__pyx_int_1560;
+static PyObject *__pyx_int_1562;
+static PyObject *__pyx_int_1700;
+static PyObject *__pyx_int_1790;
+static PyObject *__pyx_int_2202;
+static PyObject *__pyx_int_2203;
+static PyObject *__pyx_int_2204;
+static PyObject *__pyx_int_2205;
+static PyObject *__pyx_int_2206;
+static PyObject *__pyx_int_2249;
+static PyObject *__pyx_int_2275;
+static PyObject *__pyx_int_2276;
+static PyObject *__pyx_int_2277;
+static PyObject *__pyx_int_2278;
+static PyObject *__pyx_int_2279;
+static PyObject *__pyx_int_2280;
+static PyObject *__pyx_int_2281;
+static PyObject *__pyx_int_2282;
+static PyObject *__pyx_int_2283;
+static PyObject *__pyx_int_2776;
+static PyObject *__pyx_int_2950;
+static PyObject *__pyx_int_2970;
+static PyObject *__pyx_int_3115;
+static PyObject *__pyx_int_3220;
+static PyObject *__pyx_int_3310;
+static PyObject *__pyx_int_3361;
+static PyObject *__pyx_int_3402;
+static PyObject *__pyx_int_3500;
+static PyObject *__pyx_int_3614;
+static PyObject *__pyx_int_3615;
+static PyObject *__pyx_int_3642;
+static PyObject *__pyx_int_3734;
+static PyObject *__pyx_int_3769;
+static PyObject *__pyx_int_3802;
+static PyObject *__pyx_int_3831;
+static PyObject *__pyx_int_3838;
+static PyObject *__pyx_int_4089;
+static PyObject *__pyx_int_4096;
+static PyObject *__pyx_int_524288;
+static PyObject *__pyx_int_26708044;
+static PyObject *__pyx_int_81883559;
+static PyObject *__pyx_int_120810133;
+static enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_k_;
+static PyObject *__pyx_k__10;
+static PyObject *__pyx_k__11;
+static enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_k__12;
+static enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_k__13;
+static enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_k__14;
+static PyObject *__pyx_slice__8;
+static PyObject *__pyx_tuple__3;
+static PyObject *__pyx_tuple__4;
+static PyObject *__pyx_tuple__5;
+static PyObject *__pyx_tuple__6;
+static PyObject *__pyx_tuple__7;
+static PyObject *__pyx_slice__27;
+static PyObject *__pyx_tuple__15;
+static PyObject *__pyx_tuple__16;
+static PyObject *__pyx_tuple__17;
+static PyObject *__pyx_tuple__19;
+static PyObject *__pyx_tuple__20;
+static PyObject *__pyx_tuple__21;
+static PyObject *__pyx_tuple__22;
+static PyObject *__pyx_tuple__23;
+static PyObject *__pyx_tuple__29;
+static PyObject *__pyx_tuple__30;
+static PyObject *__pyx_tuple__31;
+static PyObject *__pyx_tuple__32;
+static PyObject *__pyx_tuple__33;
+static PyObject *__pyx_tuple__34;
+static PyObject *__pyx_tuple__36;
+static PyObject *__pyx_tuple__38;
+static PyObject *__pyx_tuple__40;
+static PyObject *__pyx_tuple__42;
+static PyObject *__pyx_tuple__44;
+static PyObject *__pyx_tuple__46;
+static PyObject *__pyx_tuple__48;
+static PyObject *__pyx_codeobj__35;
+static PyObject *__pyx_codeobj__37;
+static PyObject *__pyx_codeobj__39;
+static PyObject *__pyx_codeobj__41;
+static PyObject *__pyx_codeobj__43;
+static PyObject *__pyx_codeobj__45;
+static PyObject *__pyx_codeobj__47;
+static PyObject *__pyx_codeobj__49;
+/* Late includes */
+
+/* "asyncpg/protocol/encodings.pyx":62
+ * 
+ * 
+ * cdef get_python_encoding(pg_encoding):             # <<<<<<<<<<<<<<
+ *     return ENCODINGS_MAP.get(pg_encoding.lower(), pg_encoding.lower())
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_get_python_encoding(PyObject *__pyx_v_pg_encoding) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("get_python_encoding", 0);
+
+  /* "asyncpg/protocol/encodings.pyx":63
+ * 
+ * cdef get_python_encoding(pg_encoding):
+ *     return ENCODINGS_MAP.get(pg_encoding.lower(), pg_encoding.lower())             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  if (unlikely(__pyx_v_7asyncpg_8protocol_8protocol_ENCODINGS_MAP == Py_None)) {
+    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
+    __PYX_ERR(7, 63, __pyx_L1_error)
+  }
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_pg_encoding, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(7, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(7, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_pg_encoding, __pyx_n_s_lower); if (unlikely(!__pyx_t_3)) __PYX_ERR(7, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(7, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_7asyncpg_8protocol_8protocol_ENCODINGS_MAP, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(7, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/encodings.pyx":62
+ * 
+ * 
+ * cdef get_python_encoding(pg_encoding):             # <<<<<<<<<<<<<<
+ *     return ENCODINGS_MAP.get(pg_encoding.lower(), pg_encoding.lower())
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.get_python_encoding", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":14
+ * cdef class ConnectionSettings(pgproto.CodecContext):
+ * 
+ *     def __cinit__(self, conn_key):             # <<<<<<<<<<<<<<
+ *         self._encoding = 'utf-8'
+ *         self._is_utf8 = True
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_conn_key = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_conn_key,0};
+    PyObject* values[1] = {0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_conn_key)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 14, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+    }
+    __pyx_v_conn_key = values[0];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 14, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings___cinit__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), __pyx_v_conn_key);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings___cinit__(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_conn_key) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("__cinit__", 0);
+
+  /* "asyncpg/protocol/settings.pyx":15
+ * 
+ *     def __cinit__(self, conn_key):
+ *         self._encoding = 'utf-8'             # <<<<<<<<<<<<<<
+ *         self._is_utf8 = True
+ *         self._settings = {}
+ */
+  __Pyx_INCREF(__pyx_kp_u_utf_8);
+  __Pyx_GIVEREF(__pyx_kp_u_utf_8);
+  __Pyx_GOTREF(__pyx_v_self->_encoding);
+  __Pyx_DECREF(__pyx_v_self->_encoding);
+  __pyx_v_self->_encoding = __pyx_kp_u_utf_8;
+
+  /* "asyncpg/protocol/settings.pyx":16
+ *     def __cinit__(self, conn_key):
+ *         self._encoding = 'utf-8'
+ *         self._is_utf8 = True             # <<<<<<<<<<<<<<
+ *         self._settings = {}
+ *         self._codec = codecs.lookup('utf-8')
+ */
+  __pyx_v_self->_is_utf8 = 1;
+
+  /* "asyncpg/protocol/settings.pyx":17
+ *         self._encoding = 'utf-8'
+ *         self._is_utf8 = True
+ *         self._settings = {}             # <<<<<<<<<<<<<<
+ *         self._codec = codecs.lookup('utf-8')
+ *         self._data_codecs = DataCodecConfig(conn_key)
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_settings);
+  __Pyx_DECREF(__pyx_v_self->_settings);
+  __pyx_v_self->_settings = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":18
+ *         self._is_utf8 = True
+ *         self._settings = {}
+ *         self._codec = codecs.lookup('utf-8')             # <<<<<<<<<<<<<<
+ *         self._data_codecs = DataCodecConfig(conn_key)
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_codecs); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_lookup); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_utf_8);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_codec);
+  __Pyx_DECREF(__pyx_v_self->_codec);
+  __pyx_v_self->_codec = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":19
+ *         self._settings = {}
+ *         self._codec = codecs.lookup('utf-8')
+ *         self._data_codecs = DataCodecConfig(conn_key)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef add_setting(self, str name, str val):
+ */
+  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_DataCodecConfig), __pyx_v_conn_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_data_codecs);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->_data_codecs));
+  __pyx_v_self->_data_codecs = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":14
+ * cdef class ConnectionSettings(pgproto.CodecContext):
+ * 
+ *     def __cinit__(self, conn_key):             # <<<<<<<<<<<<<<
+ *         self._encoding = 'utf-8'
+ *         self._is_utf8 = True
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":21
+ *         self._data_codecs = DataCodecConfig(conn_key)
+ * 
+ *     cdef add_setting(self, str name, str val):             # <<<<<<<<<<<<<<
+ *         self._settings[name] = val
+ *         if name == 'client_encoding':
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_setting(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_val) {
+  PyObject *__pyx_v_py_enc = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("add_setting", 0);
+
+  /* "asyncpg/protocol/settings.pyx":22
+ * 
+ *     cdef add_setting(self, str name, str val):
+ *         self._settings[name] = val             # <<<<<<<<<<<<<<
+ *         if name == 'client_encoding':
+ *             py_enc = get_python_encoding(val)
+ */
+  if (unlikely(__pyx_v_self->_settings == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(1, 22, __pyx_L1_error)
+  }
+  if (unlikely(PyDict_SetItem(__pyx_v_self->_settings, __pyx_v_name, __pyx_v_val) < 0)) __PYX_ERR(1, 22, __pyx_L1_error)
+
+  /* "asyncpg/protocol/settings.pyx":23
+ *     cdef add_setting(self, str name, str val):
+ *         self._settings[name] = val
+ *         if name == 'client_encoding':             # <<<<<<<<<<<<<<
+ *             py_enc = get_python_encoding(val)
+ *             self._codec = codecs.lookup(py_enc)
+ */
+  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_name, __pyx_n_u_client_encoding, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 23, __pyx_L1_error)
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/settings.pyx":24
+ *         self._settings[name] = val
+ *         if name == 'client_encoding':
+ *             py_enc = get_python_encoding(val)             # <<<<<<<<<<<<<<
+ *             self._codec = codecs.lookup(py_enc)
+ *             self._encoding = self._codec.name
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_get_python_encoding(__pyx_v_val); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 24, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_v_py_enc = __pyx_t_3;
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/settings.pyx":25
+ *         if name == 'client_encoding':
+ *             py_enc = get_python_encoding(val)
+ *             self._codec = codecs.lookup(py_enc)             # <<<<<<<<<<<<<<
+ *             self._encoding = self._codec.name
+ *             self._is_utf8 = self._encoding == 'utf-8'
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_codecs); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 25, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_lookup); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 25, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_py_enc) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_py_enc);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 25, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_self->_codec);
+    __Pyx_DECREF(__pyx_v_self->_codec);
+    __pyx_v_self->_codec = __pyx_t_3;
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/settings.pyx":26
+ *             py_enc = get_python_encoding(val)
+ *             self._codec = codecs.lookup(py_enc)
+ *             self._encoding = self._codec.name             # <<<<<<<<<<<<<<
+ *             self._is_utf8 = self._encoding == 'utf-8'
+ * 
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_codec, __pyx_n_s_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 26, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 26, __pyx_L1_error)
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_self->_encoding);
+    __Pyx_DECREF(__pyx_v_self->_encoding);
+    __pyx_v_self->_encoding = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/settings.pyx":27
+ *             self._codec = codecs.lookup(py_enc)
+ *             self._encoding = self._codec.name
+ *             self._is_utf8 = self._encoding == 'utf-8'             # <<<<<<<<<<<<<<
+ * 
+ *     cdef is_encoding_utf8(self):
+ */
+    __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->_encoding, __pyx_kp_u_utf_8, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 27, __pyx_L1_error)
+    __pyx_v_self->_is_utf8 = __pyx_t_2;
+
+    /* "asyncpg/protocol/settings.pyx":23
+ *     cdef add_setting(self, str name, str val):
+ *         self._settings[name] = val
+ *         if name == 'client_encoding':             # <<<<<<<<<<<<<<
+ *             py_enc = get_python_encoding(val)
+ *             self._codec = codecs.lookup(py_enc)
+ */
+  }
+
+  /* "asyncpg/protocol/settings.pyx":21
+ *         self._data_codecs = DataCodecConfig(conn_key)
+ * 
+ *     cdef add_setting(self, str name, str val):             # <<<<<<<<<<<<<<
+ *         self._settings[name] = val
+ *         if name == 'client_encoding':
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.add_setting", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_py_enc);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":29
+ *             self._is_utf8 = self._encoding == 'utf-8'
+ * 
+ *     cdef is_encoding_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self._is_utf8
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_is_encoding_utf8(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("is_encoding_utf8", 0);
+
+  /* "asyncpg/protocol/settings.pyx":30
+ * 
+ *     cdef is_encoding_utf8(self):
+ *         return self._is_utf8             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef get_text_codec(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->_is_utf8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 30, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/settings.pyx":29
+ *             self._is_utf8 = self._encoding == 'utf-8'
+ * 
+ *     cdef is_encoding_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self._is_utf8
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.is_encoding_utf8", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":32
+ *         return self._is_utf8
+ * 
+ *     cpdef get_text_codec(self):             # <<<<<<<<<<<<<<
+ *         return self._codec
+ * 
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_3get_text_codec(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_text_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_text_codec", 0);
+
+  /* "asyncpg/protocol/settings.pyx":33
+ * 
+ *     cpdef get_text_codec(self):
+ *         return self._codec             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef inline register_data_types(self, types):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->_codec);
+  __pyx_r = __pyx_v_self->_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/settings.pyx":32
+ *         return self._is_utf8
+ * 
+ *     cpdef get_text_codec(self):             # <<<<<<<<<<<<<<
+ *         return self._codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_3get_text_codec(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_3get_text_codec(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_text_codec (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_2get_text_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_2get_text_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("get_text_codec", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_text_codec(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 32, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.get_text_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":35
+ *         return self._codec
+ * 
+ *     cpdef inline register_data_types(self, types):             # <<<<<<<<<<<<<<
+ *         self._data_codecs.add_types(types)
+ * 
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_5register_data_types(PyObject *__pyx_v_self, PyObject *__pyx_v_types); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_register_data_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_types, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("register_data_types", 0);
+
+  /* "asyncpg/protocol/settings.pyx":36
+ * 
+ *     cpdef inline register_data_types(self, types):
+ *         self._data_codecs.add_types(types)             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef inline add_python_codec(self, typeoid, typename, typeschema,
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_data_codecs), __pyx_n_s_add_types); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_types) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_types);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 36, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":35
+ *         return self._codec
+ * 
+ *     cpdef inline register_data_types(self, types):             # <<<<<<<<<<<<<<
+ *         self._data_codecs.add_types(types)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.register_data_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_5register_data_types(PyObject *__pyx_v_self, PyObject *__pyx_v_types); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_5register_data_types(PyObject *__pyx_v_self, PyObject *__pyx_v_types) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("register_data_types (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_4register_data_types(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), ((PyObject *)__pyx_v_types));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_4register_data_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_types) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("register_data_types", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_register_data_types(__pyx_v_self, __pyx_v_types, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.register_data_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":38
+ *         self._data_codecs.add_types(types)
+ * 
+ *     cpdef inline add_python_codec(self, typeoid, typename, typeschema,             # <<<<<<<<<<<<<<
+ *                                   typekind, encoder, decoder, format):
+ *         cdef:
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_7add_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, PyObject *__pyx_v_format, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v__format;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("add_python_codec", 0);
+
+  /* "asyncpg/protocol/settings.pyx":44
+ *             ClientExchangeFormat xformat
+ * 
+ *         if format == 'binary':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_BINARY
+ *             xformat = PG_XFORMAT_OBJECT
+ */
+  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_format, __pyx_n_u_binary, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 44, __pyx_L1_error)
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/settings.pyx":45
+ * 
+ *         if format == 'binary':
+ *             _format = PG_FORMAT_BINARY             # <<<<<<<<<<<<<<
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'text':
+ */
+    __pyx_v__format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY;
+
+    /* "asyncpg/protocol/settings.pyx":46
+ *         if format == 'binary':
+ *             _format = PG_FORMAT_BINARY
+ *             xformat = PG_XFORMAT_OBJECT             # <<<<<<<<<<<<<<
+ *         elif format == 'text':
+ *             _format = PG_FORMAT_TEXT
+ */
+    __pyx_v_xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT;
+
+    /* "asyncpg/protocol/settings.pyx":44
+ *             ClientExchangeFormat xformat
+ * 
+ *         if format == 'binary':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_BINARY
+ *             xformat = PG_XFORMAT_OBJECT
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":47
+ *             _format = PG_FORMAT_BINARY
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'text':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_TEXT
+ *             xformat = PG_XFORMAT_OBJECT
+ */
+  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_format, __pyx_n_u_text, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 47, __pyx_L1_error)
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/settings.pyx":48
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'text':
+ *             _format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'tuple':
+ */
+    __pyx_v__format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+    /* "asyncpg/protocol/settings.pyx":49
+ *         elif format == 'text':
+ *             _format = PG_FORMAT_TEXT
+ *             xformat = PG_XFORMAT_OBJECT             # <<<<<<<<<<<<<<
+ *         elif format == 'tuple':
+ *             _format = PG_FORMAT_ANY
+ */
+    __pyx_v_xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT;
+
+    /* "asyncpg/protocol/settings.pyx":47
+ *             _format = PG_FORMAT_BINARY
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'text':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_TEXT
+ *             xformat = PG_XFORMAT_OBJECT
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":50
+ *             _format = PG_FORMAT_TEXT
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'tuple':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_ANY
+ *             xformat = PG_XFORMAT_TUPLE
+ */
+  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_format, __pyx_n_u_tuple, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 50, __pyx_L1_error)
+  if (likely(__pyx_t_1)) {
+
+    /* "asyncpg/protocol/settings.pyx":51
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'tuple':
+ *             _format = PG_FORMAT_ANY             # <<<<<<<<<<<<<<
+ *             xformat = PG_XFORMAT_TUPLE
+ *         else:
+ */
+    __pyx_v__format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY;
+
+    /* "asyncpg/protocol/settings.pyx":52
+ *         elif format == 'tuple':
+ *             _format = PG_FORMAT_ANY
+ *             xformat = PG_XFORMAT_TUPLE             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise exceptions.InterfaceError(
+ */
+    __pyx_v_xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+
+    /* "asyncpg/protocol/settings.pyx":50
+ *             _format = PG_FORMAT_TEXT
+ *             xformat = PG_XFORMAT_OBJECT
+ *         elif format == 'tuple':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_ANY
+ *             xformat = PG_XFORMAT_TUPLE
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":54
+ *             xformat = PG_XFORMAT_TUPLE
+ *         else:
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'invalid `format` argument, expected {}, got {!r}'.format(
+ *                     "'text', 'binary' or 'tuple'", format
+ */
+  /*else*/ {
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 54, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 54, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/settings.pyx":55
+ *         else:
+ *             raise exceptions.InterfaceError(
+ *                 'invalid `format` argument, expected {}, got {!r}'.format(             # <<<<<<<<<<<<<<
+ *                     "'text', 'binary' or 'tuple'", format
+ *                 ))
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_format_argument_expected, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 55, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+
+    /* "asyncpg/protocol/settings.pyx":56
+ *             raise exceptions.InterfaceError(
+ *                 'invalid `format` argument, expected {}, got {!r}'.format(
+ *                     "'text', 'binary' or 'tuple'", format             # <<<<<<<<<<<<<<
+ *                 ))
+ * 
+ */
+    __pyx_t_6 = NULL;
+    __pyx_t_7 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+        __pyx_t_7 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_kp_u_text_binary_or_tuple, __pyx_v_format};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 55, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_kp_u_text_binary_or_tuple, __pyx_v_format};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 55, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+    } else
+    #endif
+    {
+      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 55, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      if (__pyx_t_6) {
+        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
+      }
+      __Pyx_INCREF(__pyx_kp_u_text_binary_or_tuple);
+      __Pyx_GIVEREF(__pyx_kp_u_text_binary_or_tuple);
+      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_kp_u_text_binary_or_tuple);
+      __Pyx_INCREF(__pyx_v_format);
+      __Pyx_GIVEREF(__pyx_v_format);
+      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_format);
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 55, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 54, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(1, 54, __pyx_L1_error)
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/settings.pyx":59
+ *                 ))
+ * 
+ *         self._data_codecs.add_python_codec(typeoid, typename, typeschema,             # <<<<<<<<<<<<<<
+ *                                            typekind, encoder, decoder,
+ *                                            _format, xformat)
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_data_codecs), __pyx_n_s_add_python_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+
+  /* "asyncpg/protocol/settings.pyx":61
+ *         self._data_codecs.add_python_codec(typeoid, typename, typeschema,
+ *                                            typekind, encoder, decoder,
+ *                                            _format, xformat)             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef inline remove_python_codec(self, typeoid, typename, typeschema):
+ */
+  __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v__format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(__pyx_v_xformat); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_8 = NULL;
+  __pyx_t_7 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_8)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_8);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+      __pyx_t_7 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[9] = {__pyx_t_8, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_encoder, __pyx_v_decoder, __pyx_t_3, __pyx_t_5};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 8+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 59, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+    PyObject *__pyx_temp[9] = {__pyx_t_8, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_encoder, __pyx_v_decoder, __pyx_t_3, __pyx_t_5};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 8+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 59, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_6 = PyTuple_New(8+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 59, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    if (__pyx_t_8) {
+      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8); __pyx_t_8 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_typename);
+    __Pyx_GIVEREF(__pyx_v_typename);
+    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_v_typename);
+    __Pyx_INCREF(__pyx_v_typeschema);
+    __Pyx_GIVEREF(__pyx_v_typeschema);
+    PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_7, __pyx_v_typeschema);
+    __Pyx_INCREF(__pyx_v_typekind);
+    __Pyx_GIVEREF(__pyx_v_typekind);
+    PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_7, __pyx_v_typekind);
+    __Pyx_INCREF(__pyx_v_encoder);
+    __Pyx_GIVEREF(__pyx_v_encoder);
+    PyTuple_SET_ITEM(__pyx_t_6, 4+__pyx_t_7, __pyx_v_encoder);
+    __Pyx_INCREF(__pyx_v_decoder);
+    __Pyx_GIVEREF(__pyx_v_decoder);
+    PyTuple_SET_ITEM(__pyx_t_6, 5+__pyx_t_7, __pyx_v_decoder);
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_6, 6+__pyx_t_7, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_6, 7+__pyx_t_7, __pyx_t_5);
+    __pyx_t_3 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 59, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":38
+ *         self._data_codecs.add_types(types)
+ * 
+ *     cpdef inline add_python_codec(self, typeoid, typename, typeschema,             # <<<<<<<<<<<<<<
+ *                                   typekind, encoder, decoder, format):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.add_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_7add_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_7add_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  PyObject *__pyx_v_typename = 0;
+  PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_v_typekind = 0;
+  PyObject *__pyx_v_encoder = 0;
+  PyObject *__pyx_v_decoder = 0;
+  PyObject *__pyx_v_format = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("add_python_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,&__pyx_n_s_typekind,&__pyx_n_s_encoder,&__pyx_n_s_decoder,&__pyx_n_s_format,0};
+    PyObject* values[7] = {0,0,0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
+        CYTHON_FALLTHROUGH;
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, 1); __PYX_ERR(1, 38, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, 2); __PYX_ERR(1, 38, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typekind)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, 3); __PYX_ERR(1, 38, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoder)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, 4); __PYX_ERR(1, 38, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_decoder)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, 5); __PYX_ERR(1, 38, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  6:
+        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, 6); __PYX_ERR(1, 38, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_python_codec") < 0)) __PYX_ERR(1, 38, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+      values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+    __pyx_v_typekind = values[3];
+    __pyx_v_encoder = values[4];
+    __pyx_v_decoder = values[5];
+    __pyx_v_format = values[6];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 38, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.add_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_6add_python_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_encoder, __pyx_v_decoder, __pyx_v_format);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_6add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, PyObject *__pyx_v_format) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("add_python_codec", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_python_codec(__pyx_v_self, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_encoder, __pyx_v_decoder, __pyx_v_format, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.add_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":63
+ *                                            _format, xformat)
+ * 
+ *     cpdef inline remove_python_codec(self, typeoid, typename, typeschema):             # <<<<<<<<<<<<<<
+ *         self._data_codecs.remove_python_codec(typeoid, typename, typeschema)
+ * 
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_9remove_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("remove_python_codec", 0);
+
+  /* "asyncpg/protocol/settings.pyx":64
+ * 
+ *     cpdef inline remove_python_codec(self, typeoid, typename, typeschema):
+ *         self._data_codecs.remove_python_codec(typeoid, typename, typeschema)             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef inline clear_type_cache(self):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_data_codecs), __pyx_n_s_remove_python_codec); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 64, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  __pyx_t_4 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+      __pyx_t_4 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema};
+    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 64, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema};
+    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 64, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+  } else
+  #endif
+  {
+    __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 64, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    if (__pyx_t_3) {
+      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_typename);
+    __Pyx_GIVEREF(__pyx_v_typename);
+    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_typename);
+    __Pyx_INCREF(__pyx_v_typeschema);
+    __Pyx_GIVEREF(__pyx_v_typeschema);
+    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_typeschema);
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 64, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":63
+ *                                            _format, xformat)
+ * 
+ *     cpdef inline remove_python_codec(self, typeoid, typename, typeschema):             # <<<<<<<<<<<<<<
+ *         self._data_codecs.remove_python_codec(typeoid, typename, typeschema)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.remove_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_9remove_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_9remove_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  PyObject *__pyx_v_typename = 0;
+  PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("remove_python_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("remove_python_codec", 1, 3, 3, 1); __PYX_ERR(1, 63, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("remove_python_codec", 1, 3, 3, 2); __PYX_ERR(1, 63, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "remove_python_codec") < 0)) __PYX_ERR(1, 63, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("remove_python_codec", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 63, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.remove_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_8remove_python_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_8remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("remove_python_codec", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_remove_python_codec(__pyx_v_self, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 63, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.remove_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":66
+ *         self._data_codecs.remove_python_codec(typeoid, typename, typeschema)
+ * 
+ *     cpdef inline clear_type_cache(self):             # <<<<<<<<<<<<<<
+ *         self._data_codecs.clear_type_cache()
+ * 
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_11clear_type_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("clear_type_cache", 0);
+
+  /* "asyncpg/protocol/settings.pyx":67
+ * 
+ *     cpdef inline clear_type_cache(self):
+ *         self._data_codecs.clear_type_cache()             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef inline set_builtin_type_codec(self, typeoid, typename, typeschema,
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_data_codecs), __pyx_n_s_clear_type_cache); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 67, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 67, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":66
+ *         self._data_codecs.remove_python_codec(typeoid, typename, typeschema)
+ * 
+ *     cpdef inline clear_type_cache(self):             # <<<<<<<<<<<<<<
+ *         self._data_codecs.clear_type_cache()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.clear_type_cache", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_11clear_type_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_11clear_type_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("clear_type_cache (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_10clear_type_cache(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_10clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("clear_type_cache", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_clear_type_cache(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 66, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.clear_type_cache", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":69
+ *         self._data_codecs.clear_type_cache()
+ * 
+ *     cpdef inline set_builtin_type_codec(self, typeoid, typename, typeschema,             # <<<<<<<<<<<<<<
+ *                                         typekind, alias_to, format):
+ *         cdef:
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_13set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v__format;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("set_builtin_type_codec", 0);
+
+  /* "asyncpg/protocol/settings.pyx":74
+ *             ServerDataFormat _format
+ * 
+ *         if format is None:             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_ANY
+ *         elif format == 'binary':
+ */
+  __pyx_t_1 = (__pyx_v_format == Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/settings.pyx":75
+ * 
+ *         if format is None:
+ *             _format = PG_FORMAT_ANY             # <<<<<<<<<<<<<<
+ *         elif format == 'binary':
+ *             _format = PG_FORMAT_BINARY
+ */
+    __pyx_v__format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY;
+
+    /* "asyncpg/protocol/settings.pyx":74
+ *             ServerDataFormat _format
+ * 
+ *         if format is None:             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_ANY
+ *         elif format == 'binary':
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":76
+ *         if format is None:
+ *             _format = PG_FORMAT_ANY
+ *         elif format == 'binary':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_BINARY
+ *         elif format == 'text':
+ */
+  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_format, __pyx_n_u_binary, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 76, __pyx_L1_error)
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/settings.pyx":77
+ *             _format = PG_FORMAT_ANY
+ *         elif format == 'binary':
+ *             _format = PG_FORMAT_BINARY             # <<<<<<<<<<<<<<
+ *         elif format == 'text':
+ *             _format = PG_FORMAT_TEXT
+ */
+    __pyx_v__format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY;
+
+    /* "asyncpg/protocol/settings.pyx":76
+ *         if format is None:
+ *             _format = PG_FORMAT_ANY
+ *         elif format == 'binary':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_BINARY
+ *         elif format == 'text':
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":78
+ *         elif format == 'binary':
+ *             _format = PG_FORMAT_BINARY
+ *         elif format == 'text':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_TEXT
+ *         else:
+ */
+  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_format, __pyx_n_u_text, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 78, __pyx_L1_error)
+  if (likely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/settings.pyx":79
+ *             _format = PG_FORMAT_BINARY
+ *         elif format == 'text':
+ *             _format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise exceptions.InterfaceError(
+ */
+    __pyx_v__format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+    /* "asyncpg/protocol/settings.pyx":78
+ *         elif format == 'binary':
+ *             _format = PG_FORMAT_BINARY
+ *         elif format == 'text':             # <<<<<<<<<<<<<<
+ *             _format = PG_FORMAT_TEXT
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":81
+ *             _format = PG_FORMAT_TEXT
+ *         else:
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'invalid `format` argument, expected {}, got {!r}'.format(
+ *                     "'text' or 'binary'", format
+ */
+  /*else*/ {
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 81, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 81, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/settings.pyx":82
+ *         else:
+ *             raise exceptions.InterfaceError(
+ *                 'invalid `format` argument, expected {}, got {!r}'.format(             # <<<<<<<<<<<<<<
+ *                     "'text' or 'binary'", format
+ *                 ))
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_format_argument_expected, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 82, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+
+    /* "asyncpg/protocol/settings.pyx":83
+ *             raise exceptions.InterfaceError(
+ *                 'invalid `format` argument, expected {}, got {!r}'.format(
+ *                     "'text' or 'binary'", format             # <<<<<<<<<<<<<<
+ *                 ))
+ * 
+ */
+    __pyx_t_7 = NULL;
+    __pyx_t_8 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_7)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+        __pyx_t_8 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_kp_u_text_or_binary, __pyx_v_format};
+      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 82, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_kp_u_text_or_binary, __pyx_v_format};
+      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 82, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+    } else
+    #endif
+    {
+      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 82, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      if (__pyx_t_7) {
+        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+      }
+      __Pyx_INCREF(__pyx_kp_u_text_or_binary);
+      __Pyx_GIVEREF(__pyx_kp_u_text_or_binary);
+      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_kp_u_text_or_binary);
+      __Pyx_INCREF(__pyx_v_format);
+      __Pyx_GIVEREF(__pyx_v_format);
+      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_format);
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 82, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 81, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(1, 81, __pyx_L1_error)
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/settings.pyx":86
+ *                 ))
+ * 
+ *         self._data_codecs.set_builtin_type_codec(typeoid, typename, typeschema,             # <<<<<<<<<<<<<<
+ *                                                  typekind, alias_to, _format)
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_data_codecs), __pyx_n_s_set_builtin_type_codec); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 86, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+
+  /* "asyncpg/protocol/settings.pyx":87
+ * 
+ *         self._data_codecs.set_builtin_type_codec(typeoid, typename, typeschema,
+ *                                                  typekind, alias_to, _format)             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,
+ */
+  __pyx_t_4 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v__format); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 87, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_6 = NULL;
+  __pyx_t_8 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+      __pyx_t_8 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_5)) {
+    PyObject *__pyx_temp[7] = {__pyx_t_6, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_t_4};
+    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 6+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 86, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+    PyObject *__pyx_temp[7] = {__pyx_t_6, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_t_4};
+    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 6+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 86, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_9 = PyTuple_New(6+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 86, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    if (__pyx_t_6) {
+      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_typename);
+    __Pyx_GIVEREF(__pyx_v_typename);
+    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_typename);
+    __Pyx_INCREF(__pyx_v_typeschema);
+    __Pyx_GIVEREF(__pyx_v_typeschema);
+    PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_v_typeschema);
+    __Pyx_INCREF(__pyx_v_typekind);
+    __Pyx_GIVEREF(__pyx_v_typekind);
+    PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_8, __pyx_v_typekind);
+    __Pyx_INCREF(__pyx_v_alias_to);
+    __Pyx_GIVEREF(__pyx_v_alias_to);
+    PyTuple_SET_ITEM(__pyx_t_9, 4+__pyx_t_8, __pyx_v_alias_to);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_9, 5+__pyx_t_8, __pyx_t_4);
+    __pyx_t_4 = 0;
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 86, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":69
+ *         self._data_codecs.clear_type_cache()
+ * 
+ *     cpdef inline set_builtin_type_codec(self, typeoid, typename, typeschema,             # <<<<<<<<<<<<<<
+ *                                         typekind, alias_to, format):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_13set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_13set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  PyObject *__pyx_v_typename = 0;
+  PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_v_typekind = 0;
+  PyObject *__pyx_v_alias_to = 0;
+  PyObject *__pyx_v_format = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("set_builtin_type_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,&__pyx_n_s_typekind,&__pyx_n_s_alias_to,&__pyx_n_s_format,0};
+    PyObject* values[6] = {0,0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 1, 6, 6, 1); __PYX_ERR(1, 69, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 1, 6, 6, 2); __PYX_ERR(1, 69, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typekind)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 1, 6, 6, 3); __PYX_ERR(1, 69, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alias_to)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 1, 6, 6, 4); __PYX_ERR(1, 69, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 1, 6, 6, 5); __PYX_ERR(1, 69, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_builtin_type_codec") < 0)) __PYX_ERR(1, 69, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+    __pyx_v_typekind = values[3];
+    __pyx_v_alias_to = values[4];
+    __pyx_v_format = values[5];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 69, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_12set_builtin_type_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_v_format);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_12set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("set_builtin_type_codec", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_set_builtin_type_codec(__pyx_v_self, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_v_format, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 69, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":89
+ *                                                  typekind, alias_to, _format)
+ * 
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):
+ *         if format == PG_FORMAT_ANY:
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_15get_data_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, uint32_t __pyx_v_oid, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec *__pyx_optional_args) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format = __pyx_k_;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = NULL;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  int __pyx_t_3;
+  __Pyx_RefNannySetupContext("get_data_codec", 0);
+  if (__pyx_optional_args) {
+    if (__pyx_optional_args->__pyx_n > 0) {
+      __pyx_v_format = __pyx_optional_args->format;
+    }
+  }
+
+  /* "asyncpg/protocol/settings.pyx":91
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):
+ *         if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+ *             if codec is None:
+ */
+  __pyx_t_1 = ((__pyx_v_format == __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/settings.pyx":92
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):
+ *         if format == PG_FORMAT_ANY:
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)             # <<<<<<<<<<<<<<
+ *             if codec is None:
+ *                 codec = self._data_codecs.get_codec(oid, PG_FORMAT_TEXT)
+ */
+    __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self->_data_codecs, __pyx_v_oid, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 92, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/settings.pyx":93
+ *         if format == PG_FORMAT_ANY:
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+ *             if codec is None:             # <<<<<<<<<<<<<<
+ *                 codec = self._data_codecs.get_codec(oid, PG_FORMAT_TEXT)
+ *             return codec
+ */
+    __pyx_t_1 = (((PyObject *)__pyx_v_codec) == Py_None);
+    __pyx_t_3 = (__pyx_t_1 != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/protocol/settings.pyx":94
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+ *             if codec is None:
+ *                 codec = self._data_codecs.get_codec(oid, PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ *             return codec
+ *         else:
+ */
+      __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self->_data_codecs, __pyx_v_oid, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 94, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2));
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/settings.pyx":93
+ *         if format == PG_FORMAT_ANY:
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+ *             if codec is None:             # <<<<<<<<<<<<<<
+ *                 codec = self._data_codecs.get_codec(oid, PG_FORMAT_TEXT)
+ *             return codec
+ */
+    }
+
+    /* "asyncpg/protocol/settings.pyx":95
+ *             if codec is None:
+ *                 codec = self._data_codecs.get_codec(oid, PG_FORMAT_TEXT)
+ *             return codec             # <<<<<<<<<<<<<<
+ *         else:
+ *             return self._data_codecs.get_codec(oid, format)
+ */
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+    __pyx_r = __pyx_v_codec;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/settings.pyx":91
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):
+ *         if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+ *             if codec is None:
+ */
+  }
+
+  /* "asyncpg/protocol/settings.pyx":97
+ *             return codec
+ *         else:
+ *             return self._data_codecs.get_codec(oid, format)             # <<<<<<<<<<<<<<
+ * 
+ *     def __getattr__(self, name):
+ */
+  /*else*/ {
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self->_data_codecs, __pyx_v_oid, __pyx_v_format)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 97, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+    __pyx_t_2 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/settings.pyx":89
+ *                                                  typekind, alias_to, _format)
+ * 
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):
+ *         if format == PG_FORMAT_ANY:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.get_data_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_15get_data_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_15get_data_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  uint32_t __pyx_v_oid;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_data_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_oid,&__pyx_n_s_format,0};
+    PyObject* values[2] = {0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_oid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (kw_args > 0) {
+          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format);
+          if (value) { values[1] = value; kw_args--; }
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_data_codec") < 0)) __PYX_ERR(1, 89, __pyx_L3_error)
+      }
+    } else {
+      switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+    }
+    __pyx_v_oid = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_oid == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 89, __pyx_L3_error)
+    if (values[1]) {
+      __pyx_v_format = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(values[1])); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 90, __pyx_L3_error)
+    } else {
+      __pyx_v_format = __pyx_k_;
+    }
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("get_data_codec", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 89, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.get_data_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_14get_data_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), __pyx_v_oid, __pyx_v_format);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_14get_data_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, uint32_t __pyx_v_oid, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec __pyx_t_2;
+  __Pyx_RefNannySetupContext("get_data_codec", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.format = __pyx_v_format;
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_8protocol_8protocol_ConnectionSettings->get_data_codec(__pyx_v_self, __pyx_v_oid, 1, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 89, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.get_data_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":99
+ *             return self._data_codecs.get_codec(oid, format)
+ * 
+ *     def __getattr__(self, name):             # <<<<<<<<<<<<<<
+ *         if not name.startswith('_'):
+ *             try:
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_17__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_name); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_17__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_name) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_16__getattr__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), ((PyObject *)__pyx_v_name));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_16__getattr__(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, PyObject *__pyx_v_name) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  __Pyx_RefNannySetupContext("__getattr__", 0);
+
+  /* "asyncpg/protocol/settings.pyx":100
+ * 
+ *     def __getattr__(self, name):
+ *         if not name.startswith('_'):             # <<<<<<<<<<<<<<
+ *             try:
+ *                 return self._settings[name]
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_name, __pyx_n_s_startswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 100, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_u__2) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u__2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 100, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 100, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_5 = ((!__pyx_t_4) != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/protocol/settings.pyx":101
+ *     def __getattr__(self, name):
+ *         if not name.startswith('_'):
+ *             try:             # <<<<<<<<<<<<<<
+ *                 return self._settings[name]
+ *             except KeyError:
+ */
+    {
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_8);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/settings.pyx":102
+ *         if not name.startswith('_'):
+ *             try:
+ *                 return self._settings[name]             # <<<<<<<<<<<<<<
+ *             except KeyError:
+ *                 raise AttributeError(name) from None
+ */
+        __Pyx_XDECREF(__pyx_r);
+        if (unlikely(__pyx_v_self->_settings == Py_None)) {
+          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+          __PYX_ERR(1, 102, __pyx_L4_error)
+        }
+        __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->_settings, __pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 102, __pyx_L4_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __pyx_r = __pyx_t_1;
+        __pyx_t_1 = 0;
+        goto __pyx_L8_try_return;
+
+        /* "asyncpg/protocol/settings.pyx":101
+ *     def __getattr__(self, name):
+ *         if not name.startswith('_'):
+ *             try:             # <<<<<<<<<<<<<<
+ *                 return self._settings[name]
+ *             except KeyError:
+ */
+      }
+      __pyx_L4_error:;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/settings.pyx":103
+ *             try:
+ *                 return self._settings[name]
+ *             except KeyError:             # <<<<<<<<<<<<<<
+ *                 raise AttributeError(name) from None
+ * 
+ */
+      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
+      if (__pyx_t_9) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) __PYX_ERR(1, 103, __pyx_L6_except_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_GOTREF(__pyx_t_3);
+
+        /* "asyncpg/protocol/settings.pyx":104
+ *                 return self._settings[name]
+ *             except KeyError:
+ *                 raise AttributeError(name) from None             # <<<<<<<<<<<<<<
+ * 
+ *         return object.__getattr__(self, name)
+ */
+        __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_AttributeError, __pyx_v_name); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 104, __pyx_L6_except_error)
+        __Pyx_GOTREF(__pyx_t_10);
+        __Pyx_Raise(__pyx_t_10, 0, 0, Py_None);
+        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        __PYX_ERR(1, 104, __pyx_L6_except_error)
+      }
+      goto __pyx_L6_except_error;
+      __pyx_L6_except_error:;
+
+      /* "asyncpg/protocol/settings.pyx":101
+ *     def __getattr__(self, name):
+ *         if not name.startswith('_'):
+ *             try:             # <<<<<<<<<<<<<<
+ *                 return self._settings[name]
+ *             except KeyError:
+ */
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+      goto __pyx_L1_error;
+      __pyx_L8_try_return:;
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+      goto __pyx_L0;
+    }
+
+    /* "asyncpg/protocol/settings.pyx":100
+ * 
+ *     def __getattr__(self, name):
+ *         if not name.startswith('_'):             # <<<<<<<<<<<<<<
+ *             try:
+ *                 return self._settings[name]
+ */
+  }
+
+  /* "asyncpg/protocol/settings.pyx":106
+ *                 raise AttributeError(name) from None
+ * 
+ *         return object.__getattr__(self, name)             # <<<<<<<<<<<<<<
+ * 
+ *     def __repr__(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_builtin_object, __pyx_n_s_getattr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 106, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = NULL;
+  __pyx_t_9 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_1)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_1);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+      __pyx_t_9 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_self), __pyx_v_name};
+    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_self), __pyx_v_name};
+    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_GOTREF(__pyx_t_3);
+  } else
+  #endif
+  {
+    __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    if (__pyx_t_1) {
+      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL;
+    }
+    __Pyx_INCREF(((PyObject *)__pyx_v_self));
+    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
+    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, ((PyObject *)__pyx_v_self));
+    __Pyx_INCREF(__pyx_v_name);
+    __Pyx_GIVEREF(__pyx_v_name);
+    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_name);
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 106, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/settings.pyx":99
+ *             return self._data_codecs.get_codec(oid, format)
+ * 
+ *     def __getattr__(self, name):             # <<<<<<<<<<<<<<
+ *         if not name.startswith('_'):
+ *             try:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/settings.pyx":108
+ *         return object.__getattr__(self, name)
+ * 
+ *     def __repr__(self):             # <<<<<<<<<<<<<<
+ *         return '<ConnectionSettings {!r}>'.format(self._settings)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_19__repr__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_19__repr__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_18__repr__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_18__repr__(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("__repr__", 0);
+
+  /* "asyncpg/protocol/settings.pyx":109
+ * 
+ *     def __repr__(self):
+ *         return '<ConnectionSettings {!r}>'.format(self._settings)             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_ConnectionSettings_r, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 109, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->_settings) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->_settings);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 109, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/settings.pyx":108
+ *         return object.__getattr__(self, name)
+ * 
+ *     def __repr__(self):             # <<<<<<<<<<<<<<
+ *         return '<ConnectionSettings {!r}>'.format(self._settings)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_21__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_21__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_20__reduce_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_20__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 2, __pyx_L1_error)
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_23__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_23__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_22__setstate_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_18ConnectionSettings_22__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 4, __pyx_L1_error)
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.ConnectionSettings.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":21
+ * cdef class Codec:
+ * 
+ *     def __cinit__(self, uint32_t oid):             # <<<<<<<<<<<<<<
+ *         self.oid = oid
+ *         self.type = CODEC_UNDEFINED
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_8protocol_8protocol_5Codec_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_8protocol_8protocol_5Codec_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  uint32_t __pyx_v_oid;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_oid,0};
+    PyObject* values[1] = {0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_oid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(3, 21, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+    }
+    __pyx_v_oid = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_oid == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 21, __pyx_L3_error)
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 21, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Codec___cinit__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_self), __pyx_v_oid);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_8protocol_8protocol_5Codec___cinit__(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, uint32_t __pyx_v_oid) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":22
+ * 
+ *     def __cinit__(self, uint32_t oid):
+ *         self.oid = oid             # <<<<<<<<<<<<<<
+ *         self.type = CODEC_UNDEFINED
+ * 
+ */
+  __pyx_v_self->oid = __pyx_v_oid;
+
+  /* "asyncpg/protocol/codecs/base.pyx":23
+ *     def __cinit__(self, uint32_t oid):
+ *         self.oid = oid
+ *         self.type = CODEC_UNDEFINED             # <<<<<<<<<<<<<<
+ * 
+ *     cdef init(self, str name, str schema, str kind,
+ */
+  __pyx_v_self->type = __pyx_e_7asyncpg_8protocol_8protocol_CODEC_UNDEFINED;
+
+  /* "asyncpg/protocol/codecs/base.pyx":21
+ * cdef class Codec:
+ * 
+ *     def __cinit__(self, uint32_t oid):             # <<<<<<<<<<<<<<
+ *         self.oid = oid
+ *         self.type = CODEC_UNDEFINED
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":25
+ *         self.type = CODEC_UNDEFINED
+ * 
+ *     cdef init(self, str name, str schema, str kind,             # <<<<<<<<<<<<<<
+ *               CodecType type, ServerDataFormat format,
+ *               ClientExchangeFormat xformat,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, PyObject *__pyx_v_kind, enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType __pyx_v_type, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat, __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_c_encoder, __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_c_decoder, PyObject *__pyx_v_py_encoder, PyObject *__pyx_v_py_decoder, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_element_codec, PyObject *__pyx_v_element_type_oids, PyObject *__pyx_v_element_names, PyObject *__pyx_v_element_codecs, Py_UCS4 __pyx_v_element_delimiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("init", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":34
+ *               Py_UCS4 element_delimiter):
+ * 
+ *         self.name = name             # <<<<<<<<<<<<<<
+ *         self.schema = schema
+ *         self.kind = kind
+ */
+  __Pyx_INCREF(__pyx_v_name);
+  __Pyx_GIVEREF(__pyx_v_name);
+  __Pyx_GOTREF(__pyx_v_self->name);
+  __Pyx_DECREF(__pyx_v_self->name);
+  __pyx_v_self->name = __pyx_v_name;
+
+  /* "asyncpg/protocol/codecs/base.pyx":35
+ * 
+ *         self.name = name
+ *         self.schema = schema             # <<<<<<<<<<<<<<
+ *         self.kind = kind
+ *         self.type = type
+ */
+  __Pyx_INCREF(__pyx_v_schema);
+  __Pyx_GIVEREF(__pyx_v_schema);
+  __Pyx_GOTREF(__pyx_v_self->schema);
+  __Pyx_DECREF(__pyx_v_self->schema);
+  __pyx_v_self->schema = __pyx_v_schema;
+
+  /* "asyncpg/protocol/codecs/base.pyx":36
+ *         self.name = name
+ *         self.schema = schema
+ *         self.kind = kind             # <<<<<<<<<<<<<<
+ *         self.type = type
+ *         self.format = format
+ */
+  __Pyx_INCREF(__pyx_v_kind);
+  __Pyx_GIVEREF(__pyx_v_kind);
+  __Pyx_GOTREF(__pyx_v_self->kind);
+  __Pyx_DECREF(__pyx_v_self->kind);
+  __pyx_v_self->kind = __pyx_v_kind;
+
+  /* "asyncpg/protocol/codecs/base.pyx":37
+ *         self.schema = schema
+ *         self.kind = kind
+ *         self.type = type             # <<<<<<<<<<<<<<
+ *         self.format = format
+ *         self.xformat = xformat
+ */
+  __pyx_v_self->type = __pyx_v_type;
+
+  /* "asyncpg/protocol/codecs/base.pyx":38
+ *         self.kind = kind
+ *         self.type = type
+ *         self.format = format             # <<<<<<<<<<<<<<
+ *         self.xformat = xformat
+ *         self.c_encoder = c_encoder
+ */
+  __pyx_v_self->format = __pyx_v_format;
+
+  /* "asyncpg/protocol/codecs/base.pyx":39
+ *         self.type = type
+ *         self.format = format
+ *         self.xformat = xformat             # <<<<<<<<<<<<<<
+ *         self.c_encoder = c_encoder
+ *         self.c_decoder = c_decoder
+ */
+  __pyx_v_self->xformat = __pyx_v_xformat;
+
+  /* "asyncpg/protocol/codecs/base.pyx":40
+ *         self.format = format
+ *         self.xformat = xformat
+ *         self.c_encoder = c_encoder             # <<<<<<<<<<<<<<
+ *         self.c_decoder = c_decoder
+ *         self.py_encoder = py_encoder
+ */
+  __pyx_v_self->c_encoder = __pyx_v_c_encoder;
+
+  /* "asyncpg/protocol/codecs/base.pyx":41
+ *         self.xformat = xformat
+ *         self.c_encoder = c_encoder
+ *         self.c_decoder = c_decoder             # <<<<<<<<<<<<<<
+ *         self.py_encoder = py_encoder
+ *         self.py_decoder = py_decoder
+ */
+  __pyx_v_self->c_decoder = __pyx_v_c_decoder;
+
+  /* "asyncpg/protocol/codecs/base.pyx":42
+ *         self.c_encoder = c_encoder
+ *         self.c_decoder = c_decoder
+ *         self.py_encoder = py_encoder             # <<<<<<<<<<<<<<
+ *         self.py_decoder = py_decoder
+ *         self.element_codec = element_codec
+ */
+  __Pyx_INCREF(__pyx_v_py_encoder);
+  __Pyx_GIVEREF(__pyx_v_py_encoder);
+  __Pyx_GOTREF(__pyx_v_self->py_encoder);
+  __Pyx_DECREF(__pyx_v_self->py_encoder);
+  __pyx_v_self->py_encoder = __pyx_v_py_encoder;
+
+  /* "asyncpg/protocol/codecs/base.pyx":43
+ *         self.c_decoder = c_decoder
+ *         self.py_encoder = py_encoder
+ *         self.py_decoder = py_decoder             # <<<<<<<<<<<<<<
+ *         self.element_codec = element_codec
+ *         self.element_type_oids = element_type_oids
+ */
+  __Pyx_INCREF(__pyx_v_py_decoder);
+  __Pyx_GIVEREF(__pyx_v_py_decoder);
+  __Pyx_GOTREF(__pyx_v_self->py_decoder);
+  __Pyx_DECREF(__pyx_v_self->py_decoder);
+  __pyx_v_self->py_decoder = __pyx_v_py_decoder;
+
+  /* "asyncpg/protocol/codecs/base.pyx":44
+ *         self.py_encoder = py_encoder
+ *         self.py_decoder = py_decoder
+ *         self.element_codec = element_codec             # <<<<<<<<<<<<<<
+ *         self.element_type_oids = element_type_oids
+ *         self.element_codecs = element_codecs
+ */
+  __Pyx_INCREF(((PyObject *)__pyx_v_element_codec));
+  __Pyx_GIVEREF(((PyObject *)__pyx_v_element_codec));
+  __Pyx_GOTREF(__pyx_v_self->element_codec);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->element_codec));
+  __pyx_v_self->element_codec = __pyx_v_element_codec;
+
+  /* "asyncpg/protocol/codecs/base.pyx":45
+ *         self.py_decoder = py_decoder
+ *         self.element_codec = element_codec
+ *         self.element_type_oids = element_type_oids             # <<<<<<<<<<<<<<
+ *         self.element_codecs = element_codecs
+ *         self.element_delimiter = element_delimiter
+ */
+  __Pyx_INCREF(__pyx_v_element_type_oids);
+  __Pyx_GIVEREF(__pyx_v_element_type_oids);
+  __Pyx_GOTREF(__pyx_v_self->element_type_oids);
+  __Pyx_DECREF(__pyx_v_self->element_type_oids);
+  __pyx_v_self->element_type_oids = __pyx_v_element_type_oids;
+
+  /* "asyncpg/protocol/codecs/base.pyx":46
+ *         self.element_codec = element_codec
+ *         self.element_type_oids = element_type_oids
+ *         self.element_codecs = element_codecs             # <<<<<<<<<<<<<<
+ *         self.element_delimiter = element_delimiter
+ *         self.element_names = element_names
+ */
+  __Pyx_INCREF(__pyx_v_element_codecs);
+  __Pyx_GIVEREF(__pyx_v_element_codecs);
+  __Pyx_GOTREF(__pyx_v_self->element_codecs);
+  __Pyx_DECREF(__pyx_v_self->element_codecs);
+  __pyx_v_self->element_codecs = __pyx_v_element_codecs;
+
+  /* "asyncpg/protocol/codecs/base.pyx":47
+ *         self.element_type_oids = element_type_oids
+ *         self.element_codecs = element_codecs
+ *         self.element_delimiter = element_delimiter             # <<<<<<<<<<<<<<
+ *         self.element_names = element_names
+ * 
+ */
+  __pyx_v_self->element_delimiter = __pyx_v_element_delimiter;
+
+  /* "asyncpg/protocol/codecs/base.pyx":48
+ *         self.element_codecs = element_codecs
+ *         self.element_delimiter = element_delimiter
+ *         self.element_names = element_names             # <<<<<<<<<<<<<<
+ * 
+ *         if element_names is not None:
+ */
+  __Pyx_INCREF(__pyx_v_element_names);
+  __Pyx_GIVEREF(__pyx_v_element_names);
+  __Pyx_GOTREF(__pyx_v_self->element_names);
+  __Pyx_DECREF(__pyx_v_self->element_names);
+  __pyx_v_self->element_names = __pyx_v_element_names;
+
+  /* "asyncpg/protocol/codecs/base.pyx":50
+ *         self.element_names = element_names
+ * 
+ *         if element_names is not None:             # <<<<<<<<<<<<<<
+ *             self.record_desc = record.ApgRecordDesc_New(
+ *                 element_names, tuple(element_names))
+ */
+  __pyx_t_1 = (__pyx_v_element_names != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":52
+ *         if element_names is not None:
+ *             self.record_desc = record.ApgRecordDesc_New(
+ *                 element_names, tuple(element_names))             # <<<<<<<<<<<<<<
+ *         else:
+ *             self.record_desc = None
+ */
+    __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_v_element_names); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 52, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/protocol/codecs/base.pyx":51
+ * 
+ *         if element_names is not None:
+ *             self.record_desc = record.ApgRecordDesc_New(             # <<<<<<<<<<<<<<
+ *                 element_names, tuple(element_names))
+ *         else:
+ */
+    __pyx_t_4 = ApgRecordDesc_New(__pyx_v_element_names, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 51, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GIVEREF(__pyx_t_4);
+    __Pyx_GOTREF(__pyx_v_self->record_desc);
+    __Pyx_DECREF(__pyx_v_self->record_desc);
+    __pyx_v_self->record_desc = __pyx_t_4;
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":50
+ *         self.element_names = element_names
+ * 
+ *         if element_names is not None:             # <<<<<<<<<<<<<<
+ *             self.record_desc = record.ApgRecordDesc_New(
+ *                 element_names, tuple(element_names))
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":54
+ *                 element_names, tuple(element_names))
+ *         else:
+ *             self.record_desc = None             # <<<<<<<<<<<<<<
+ * 
+ *         if type == CODEC_C:
+ */
+  /*else*/ {
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_v_self->record_desc);
+    __Pyx_DECREF(__pyx_v_self->record_desc);
+    __pyx_v_self->record_desc = Py_None;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/codecs/base.pyx":56
+ *             self.record_desc = None
+ * 
+ *         if type == CODEC_C:             # <<<<<<<<<<<<<<
+ *             self.encoder = <codec_encode_func>&self.encode_scalar
+ *             self.decoder = <codec_decode_func>&self.decode_scalar
+ */
+  switch (__pyx_v_type) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_C:
+
+    /* "asyncpg/protocol/codecs/base.pyx":57
+ * 
+ *         if type == CODEC_C:
+ *             self.encoder = <codec_encode_func>&self.encode_scalar             # <<<<<<<<<<<<<<
+ *             self.decoder = <codec_decode_func>&self.decode_scalar
+ *         elif type == CODEC_ARRAY:
+ */
+    __pyx_v_self->encoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_scalar));
+
+    /* "asyncpg/protocol/codecs/base.pyx":58
+ *         if type == CODEC_C:
+ *             self.encoder = <codec_encode_func>&self.encode_scalar
+ *             self.decoder = <codec_decode_func>&self.decode_scalar             # <<<<<<<<<<<<<<
+ *         elif type == CODEC_ARRAY:
+ *             if format == PG_FORMAT_BINARY:
+ */
+    __pyx_v_self->decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_scalar));
+
+    /* "asyncpg/protocol/codecs/base.pyx":56
+ *             self.record_desc = None
+ * 
+ *         if type == CODEC_C:             # <<<<<<<<<<<<<<
+ *             self.encoder = <codec_encode_func>&self.encode_scalar
+ *             self.decoder = <codec_decode_func>&self.decode_scalar
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_ARRAY:
+
+    /* "asyncpg/protocol/codecs/base.pyx":60
+ *             self.decoder = <codec_decode_func>&self.decode_scalar
+ *         elif type == CODEC_ARRAY:
+ *             if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 self.encoder = <codec_encode_func>&self.encode_array
+ *                 self.decoder = <codec_decode_func>&self.decode_array
+ */
+    __pyx_t_2 = ((__pyx_v_format == __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":61
+ *         elif type == CODEC_ARRAY:
+ *             if format == PG_FORMAT_BINARY:
+ *                 self.encoder = <codec_encode_func>&self.encode_array             # <<<<<<<<<<<<<<
+ *                 self.decoder = <codec_decode_func>&self.decode_array
+ *             else:
+ */
+      __pyx_v_self->encoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array));
+
+      /* "asyncpg/protocol/codecs/base.pyx":62
+ *             if format == PG_FORMAT_BINARY:
+ *                 self.encoder = <codec_encode_func>&self.encode_array
+ *                 self.decoder = <codec_decode_func>&self.decode_array             # <<<<<<<<<<<<<<
+ *             else:
+ *                 self.encoder = <codec_encode_func>&self.encode_array_text
+ */
+      __pyx_v_self->decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array));
+
+      /* "asyncpg/protocol/codecs/base.pyx":60
+ *             self.decoder = <codec_decode_func>&self.decode_scalar
+ *         elif type == CODEC_ARRAY:
+ *             if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 self.encoder = <codec_encode_func>&self.encode_array
+ *                 self.decoder = <codec_decode_func>&self.decode_array
+ */
+      goto __pyx_L4;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":64
+ *                 self.decoder = <codec_decode_func>&self.decode_array
+ *             else:
+ *                 self.encoder = <codec_encode_func>&self.encode_array_text             # <<<<<<<<<<<<<<
+ *                 self.decoder = <codec_decode_func>&self.decode_array_text
+ *         elif type == CODEC_RANGE:
+ */
+    /*else*/ {
+      __pyx_v_self->encoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array_text));
+
+      /* "asyncpg/protocol/codecs/base.pyx":65
+ *             else:
+ *                 self.encoder = <codec_encode_func>&self.encode_array_text
+ *                 self.decoder = <codec_decode_func>&self.decode_array_text             # <<<<<<<<<<<<<<
+ *         elif type == CODEC_RANGE:
+ *             if format != PG_FORMAT_BINARY:
+ */
+      __pyx_v_self->decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array_text));
+    }
+    __pyx_L4:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":59
+ *             self.encoder = <codec_encode_func>&self.encode_scalar
+ *             self.decoder = <codec_decode_func>&self.decode_scalar
+ *         elif type == CODEC_ARRAY:             # <<<<<<<<<<<<<<
+ *             if format == PG_FORMAT_BINARY:
+ *                 self.encoder = <codec_encode_func>&self.encode_array
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_RANGE:
+
+    /* "asyncpg/protocol/codecs/base.pyx":67
+ *                 self.decoder = <codec_decode_func>&self.decode_array_text
+ *         elif type == CODEC_RANGE:
+ *             if format != PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 raise NotImplementedError(
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ */
+    __pyx_t_2 = ((__pyx_v_format != __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY) != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":70
+ *                 raise NotImplementedError(
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ *                     'range types is not supported'.format(schema, name))             # <<<<<<<<<<<<<<
+ *             self.encoder = <codec_encode_func>&self.encode_range
+ *             self.decoder = <codec_decode_func>&self.decode_range
+ */
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_cannot_decode_type_text_encoding, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 70, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_5 = NULL;
+      __pyx_t_6 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_5)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_5);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+          __pyx_t_6 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_3)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_schema, __pyx_v_name};
+        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 70, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_GOTREF(__pyx_t_4);
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_schema, __pyx_v_name};
+        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 70, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_GOTREF(__pyx_t_4);
+      } else
+      #endif
+      {
+        __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 70, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        if (__pyx_t_5) {
+          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+        }
+        __Pyx_INCREF(__pyx_v_schema);
+        __Pyx_GIVEREF(__pyx_v_schema);
+        PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_schema);
+        __Pyx_INCREF(__pyx_v_name);
+        __Pyx_GIVEREF(__pyx_v_name);
+        PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_name);
+        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 70, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":68
+ *         elif type == CODEC_RANGE:
+ *             if format != PG_FORMAT_BINARY:
+ *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ *                     'range types is not supported'.format(schema, name))
+ */
+      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 68, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(3, 68, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":67
+ *                 self.decoder = <codec_decode_func>&self.decode_array_text
+ *         elif type == CODEC_RANGE:
+ *             if format != PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 raise NotImplementedError(
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":71
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ *                     'range types is not supported'.format(schema, name))
+ *             self.encoder = <codec_encode_func>&self.encode_range             # <<<<<<<<<<<<<<
+ *             self.decoder = <codec_decode_func>&self.decode_range
+ *         elif type == CODEC_COMPOSITE:
+ */
+    __pyx_v_self->encoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_range));
+
+    /* "asyncpg/protocol/codecs/base.pyx":72
+ *                     'range types is not supported'.format(schema, name))
+ *             self.encoder = <codec_encode_func>&self.encode_range
+ *             self.decoder = <codec_decode_func>&self.decode_range             # <<<<<<<<<<<<<<
+ *         elif type == CODEC_COMPOSITE:
+ *             if format != PG_FORMAT_BINARY:
+ */
+    __pyx_v_self->decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_range));
+
+    /* "asyncpg/protocol/codecs/base.pyx":66
+ *                 self.encoder = <codec_encode_func>&self.encode_array_text
+ *                 self.decoder = <codec_decode_func>&self.decode_array_text
+ *         elif type == CODEC_RANGE:             # <<<<<<<<<<<<<<
+ *             if format != PG_FORMAT_BINARY:
+ *                 raise NotImplementedError(
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_COMPOSITE:
+
+    /* "asyncpg/protocol/codecs/base.pyx":74
+ *             self.decoder = <codec_decode_func>&self.decode_range
+ *         elif type == CODEC_COMPOSITE:
+ *             if format != PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 raise NotImplementedError(
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ */
+    __pyx_t_2 = ((__pyx_v_format != __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY) != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":77
+ *                 raise NotImplementedError(
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ *                     'composite types is not supported'.format(schema, name))             # <<<<<<<<<<<<<<
+ *             self.encoder = <codec_encode_func>&self.encode_composite
+ *             self.decoder = <codec_decode_func>&self.decode_composite
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_cannot_decode_type_text_encoding_2, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 77, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_7 = NULL;
+      __pyx_t_6 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_7)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_7);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+          __pyx_t_6 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_4)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_schema, __pyx_v_name};
+        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 77, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_GOTREF(__pyx_t_3);
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_schema, __pyx_v_name};
+        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 77, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_GOTREF(__pyx_t_3);
+      } else
+      #endif
+      {
+        __pyx_t_5 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 77, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        if (__pyx_t_7) {
+          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
+        }
+        __Pyx_INCREF(__pyx_v_schema);
+        __Pyx_GIVEREF(__pyx_v_schema);
+        PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_6, __pyx_v_schema);
+        __Pyx_INCREF(__pyx_v_name);
+        __Pyx_GIVEREF(__pyx_v_name);
+        PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_6, __pyx_v_name);
+        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 77, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":75
+ *         elif type == CODEC_COMPOSITE:
+ *             if format != PG_FORMAT_BINARY:
+ *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ *                     'composite types is not supported'.format(schema, name))
+ */
+      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 75, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __PYX_ERR(3, 75, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":74
+ *             self.decoder = <codec_decode_func>&self.decode_range
+ *         elif type == CODEC_COMPOSITE:
+ *             if format != PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 raise NotImplementedError(
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":78
+ *                     'cannot decode type "{}"."{}": text encoding of '
+ *                     'composite types is not supported'.format(schema, name))
+ *             self.encoder = <codec_encode_func>&self.encode_composite             # <<<<<<<<<<<<<<
+ *             self.decoder = <codec_decode_func>&self.decode_composite
+ *         elif type == CODEC_PY:
+ */
+    __pyx_v_self->encoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_composite));
+
+    /* "asyncpg/protocol/codecs/base.pyx":79
+ *                     'composite types is not supported'.format(schema, name))
+ *             self.encoder = <codec_encode_func>&self.encode_composite
+ *             self.decoder = <codec_decode_func>&self.decode_composite             # <<<<<<<<<<<<<<
+ *         elif type == CODEC_PY:
+ *             self.encoder = <codec_encode_func>&self.encode_in_python
+ */
+    __pyx_v_self->decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_composite));
+
+    /* "asyncpg/protocol/codecs/base.pyx":73
+ *             self.encoder = <codec_encode_func>&self.encode_range
+ *             self.decoder = <codec_decode_func>&self.decode_range
+ *         elif type == CODEC_COMPOSITE:             # <<<<<<<<<<<<<<
+ *             if format != PG_FORMAT_BINARY:
+ *                 raise NotImplementedError(
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_PY:
+
+    /* "asyncpg/protocol/codecs/base.pyx":81
+ *             self.decoder = <codec_decode_func>&self.decode_composite
+ *         elif type == CODEC_PY:
+ *             self.encoder = <codec_encode_func>&self.encode_in_python             # <<<<<<<<<<<<<<
+ *             self.decoder = <codec_decode_func>&self.decode_in_python
+ *         else:
+ */
+    __pyx_v_self->encoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_in_python));
+
+    /* "asyncpg/protocol/codecs/base.pyx":82
+ *         elif type == CODEC_PY:
+ *             self.encoder = <codec_encode_func>&self.encode_in_python
+ *             self.decoder = <codec_decode_func>&self.decode_in_python             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise exceptions.InternalClientError(
+ */
+    __pyx_v_self->decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_codec_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_in_python));
+
+    /* "asyncpg/protocol/codecs/base.pyx":80
+ *             self.encoder = <codec_encode_func>&self.encode_composite
+ *             self.decoder = <codec_decode_func>&self.decode_composite
+ *         elif type == CODEC_PY:             # <<<<<<<<<<<<<<
+ *             self.encoder = <codec_encode_func>&self.encode_in_python
+ *             self.decoder = <codec_decode_func>&self.decode_in_python
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/codecs/base.pyx":84
+ *             self.decoder = <codec_decode_func>&self.decode_in_python
+ *         else:
+ *             raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                 'unexpected codec type: {}'.format(type))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":85
+ *         else:
+ *             raise exceptions.InternalClientError(
+ *                 'unexpected codec type: {}'.format(type))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef Codec copy(self):
+ */
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_codec_type, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 85, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_CodecType(__pyx_v_type); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 85, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_9 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_9)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_9);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8);
+    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 85, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __pyx_t_7 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_7)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(3, 84, __pyx_L1_error)
+    break;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":25
+ *         self.type = CODEC_UNDEFINED
+ * 
+ *     cdef init(self, str name, str schema, str kind,             # <<<<<<<<<<<<<<
+ *               CodecType type, ServerDataFormat format,
+ *               ClientExchangeFormat xformat,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.init", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":87
+ *                 'unexpected codec type: {}'.format(type))
+ * 
+ *     cdef Codec copy(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_copy(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  __Pyx_RefNannySetupContext("copy", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":90
+ *         cdef Codec codec
+ * 
+ *         codec = Codec(self.oid)             # <<<<<<<<<<<<<<
+ *         codec.init(self.name, self.schema, self.kind,
+ *                    self.type, self.format, self.xformat,
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 90, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 90, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":91
+ * 
+ *         codec = Codec(self.oid)
+ *         codec.init(self.name, self.schema, self.kind,             # <<<<<<<<<<<<<<
+ *                    self.type, self.format, self.xformat,
+ *                    self.c_encoder, self.c_decoder,
+ */
+  __pyx_t_2 = __pyx_v_self->name;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_t_1 = __pyx_v_self->schema;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_3 = __pyx_v_self->kind;
+  __Pyx_INCREF(__pyx_t_3);
+
+  /* "asyncpg/protocol/codecs/base.pyx":94
+ *                    self.type, self.format, self.xformat,
+ *                    self.c_encoder, self.c_decoder,
+ *                    self.py_encoder, self.py_decoder,             # <<<<<<<<<<<<<<
+ *                    self.element_codec,
+ *                    self.element_type_oids, self.element_names,
+ */
+  __pyx_t_4 = __pyx_v_self->py_encoder;
+  __Pyx_INCREF(__pyx_t_4);
+  __pyx_t_5 = __pyx_v_self->py_decoder;
+  __Pyx_INCREF(__pyx_t_5);
+
+  /* "asyncpg/protocol/codecs/base.pyx":95
+ *                    self.c_encoder, self.c_decoder,
+ *                    self.py_encoder, self.py_decoder,
+ *                    self.element_codec,             # <<<<<<<<<<<<<<
+ *                    self.element_type_oids, self.element_names,
+ *                    self.element_codecs, self.element_delimiter)
+ */
+  __pyx_t_6 = ((PyObject *)__pyx_v_self->element_codec);
+  __Pyx_INCREF(__pyx_t_6);
+
+  /* "asyncpg/protocol/codecs/base.pyx":96
+ *                    self.py_encoder, self.py_decoder,
+ *                    self.element_codec,
+ *                    self.element_type_oids, self.element_names,             # <<<<<<<<<<<<<<
+ *                    self.element_codecs, self.element_delimiter)
+ * 
+ */
+  __pyx_t_7 = __pyx_v_self->element_type_oids;
+  __Pyx_INCREF(__pyx_t_7);
+  __pyx_t_8 = __pyx_v_self->element_names;
+  __Pyx_INCREF(__pyx_t_8);
+
+  /* "asyncpg/protocol/codecs/base.pyx":97
+ *                    self.element_codec,
+ *                    self.element_type_oids, self.element_names,
+ *                    self.element_codecs, self.element_delimiter)             # <<<<<<<<<<<<<<
+ * 
+ *         return codec
+ */
+  __pyx_t_9 = __pyx_v_self->element_codecs;
+  __Pyx_INCREF(__pyx_t_9);
+
+  /* "asyncpg/protocol/codecs/base.pyx":91
+ * 
+ *         codec = Codec(self.oid)
+ *         codec.init(self.name, self.schema, self.kind,             # <<<<<<<<<<<<<<
+ *                    self.type, self.format, self.xformat,
+ *                    self.c_encoder, self.c_decoder,
+ */
+  __pyx_t_10 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, ((PyObject*)__pyx_t_2), ((PyObject*)__pyx_t_1), ((PyObject*)__pyx_t_3), __pyx_v_self->type, __pyx_v_self->format, __pyx_v_self->xformat, __pyx_v_self->c_encoder, __pyx_v_self->c_decoder, __pyx_t_4, __pyx_t_5, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_6), ((PyObject*)__pyx_t_7), __pyx_t_8, ((PyObject*)__pyx_t_9), __pyx_v_self->element_delimiter); if (unlikely(!__pyx_t_10)) __PYX_ERR(3, 91, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_10);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":99
+ *                    self.element_codecs, self.element_delimiter)
+ * 
+ *         return codec             # <<<<<<<<<<<<<<
+ * 
+ *     cdef encode_scalar(self, ConnectionSettings settings, WriteBuffer buf,
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = __pyx_v_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":87
+ *                 'unexpected codec type: {}'.format(type))
+ * 
+ *     cdef Codec copy(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":101
+ *         return codec
+ * 
+ *     cdef encode_scalar(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                        object obj):
+ *         self.c_encoder(settings, buf, obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_scalar(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("encode_scalar", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":103
+ *     cdef encode_scalar(self, ConnectionSettings settings, WriteBuffer buf,
+ *                        object obj):
+ *         self.c_encoder(settings, buf, obj)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef encode_array(self, ConnectionSettings settings, WriteBuffer buf,
+ */
+  __pyx_t_1 = __pyx_v_self->c_encoder(__pyx_v_settings, __pyx_v_buf, __pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 103, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":101
+ *         return codec
+ * 
+ *     cdef encode_scalar(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                        object obj):
+ *         self.c_encoder(settings, buf, obj)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":105
+ *         self.c_encoder(settings, buf, obj)
+ * 
+ *     cdef encode_array(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                       object obj):
+ *         array_encode(settings, buf, obj, self.element_codec.oid,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("encode_array", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":107
+ *     cdef encode_array(self, ConnectionSettings settings, WriteBuffer buf,
+ *                       object obj):
+ *         array_encode(settings, buf, obj, self.element_codec.oid,             # <<<<<<<<<<<<<<
+ *                      codec_encode_func_ex,
+ *                      <void*>(<cpython.PyObject>self.element_codec))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_array_encode(__pyx_v_settings, __pyx_v_buf, __pyx_v_obj, __pyx_v_self->element_codec->oid, __pyx_f_7asyncpg_8protocol_8protocol_codec_encode_func_ex, ((void *)__pyx_v_self->element_codec)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 107, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":105
+ *         self.c_encoder(settings, buf, obj)
+ * 
+ *     cdef encode_array(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                       object obj):
+ *         array_encode(settings, buf, obj, self.element_codec.oid,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":111
+ *                      <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef encode_array_text(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                            object obj):
+ *         return textarray_encode(settings, buf, obj,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array_text(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("encode_array_text", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":113
+ *     cdef encode_array_text(self, ConnectionSettings settings, WriteBuffer buf,
+ *                            object obj):
+ *         return textarray_encode(settings, buf, obj,             # <<<<<<<<<<<<<<
+ *                                 codec_encode_func_ex,
+ *                                 <void*>(<cpython.PyObject>self.element_codec),
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/protocol/codecs/base.pyx":116
+ *                                 codec_encode_func_ex,
+ *                                 <void*>(<cpython.PyObject>self.element_codec),
+ *                                 self.element_delimiter)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef encode_range(self, ConnectionSettings settings, WriteBuffer buf,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_textarray_encode(__pyx_v_settings, __pyx_v_buf, __pyx_v_obj, __pyx_f_7asyncpg_8protocol_8protocol_codec_encode_func_ex, ((void *)__pyx_v_self->element_codec), __pyx_v_self->element_delimiter); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 113, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":111
+ *                      <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef encode_array_text(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                            object obj):
+ *         return textarray_encode(settings, buf, obj,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_array_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":118
+ *                                 self.element_delimiter)
+ * 
+ *     cdef encode_range(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                       object obj):
+ *         range_encode(settings, buf, obj, self.element_codec.oid,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_range(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("encode_range", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":120
+ *     cdef encode_range(self, ConnectionSettings settings, WriteBuffer buf,
+ *                       object obj):
+ *         range_encode(settings, buf, obj, self.element_codec.oid,             # <<<<<<<<<<<<<<
+ *                      codec_encode_func_ex,
+ *                      <void*>(<cpython.PyObject>self.element_codec))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_range_encode(__pyx_v_settings, __pyx_v_buf, __pyx_v_obj, __pyx_v_self->element_codec->oid, __pyx_f_7asyncpg_8protocol_8protocol_codec_encode_func_ex, ((void *)__pyx_v_self->element_codec)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 120, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":118
+ *                                 self.element_delimiter)
+ * 
+ *     cdef encode_range(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                       object obj):
+ *         range_encode(settings, buf, obj, self.element_codec.oid,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":124
+ *                      <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef encode_composite(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                           object obj):
+ *         cdef:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_composite(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_elem_data = 0;
+  int __pyx_v_i;
+  PyObject *__pyx_v_elem_codecs = 0;
+  Py_ssize_t __pyx_v_count;
+  Py_ssize_t __pyx_v_composite_size;
+  PyObject *__pyx_v_rec = 0;
+  PyObject *__pyx_v_field = NULL;
+  PyObject *__pyx_v_item = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  Py_ssize_t __pyx_t_4;
+  Py_ssize_t __pyx_t_5;
+  Py_ssize_t __pyx_t_6;
+  int __pyx_t_7;
+  PyObject *(*__pyx_t_8)(PyObject *);
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  int32_t __pyx_t_19;
+  __Pyx_RefNannySetupContext("encode_composite", 0);
+  __Pyx_INCREF(__pyx_v_obj);
+
+  /* "asyncpg/protocol/codecs/base.pyx":129
+ *             WriteBuffer elem_data
+ *             int i
+ *             list elem_codecs = self.element_codecs             # <<<<<<<<<<<<<<
+ *             ssize_t count
+ *             ssize_t composite_size
+ */
+  __pyx_t_1 = __pyx_v_self->element_codecs;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_elem_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":134
+ *             tuple rec
+ * 
+ *         if isinstance(obj, MappingABC):             # <<<<<<<<<<<<<<
+ *             # Input is dict-like, form a tuple
+ *             composite_size = len(self.element_type_oids)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_MappingABC); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 134, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(3, 134, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":136
+ *         if isinstance(obj, MappingABC):
+ *             # Input is dict-like, form a tuple
+ *             composite_size = len(self.element_type_oids)             # <<<<<<<<<<<<<<
+ *             rec = cpython.PyTuple_New(composite_size)
+ * 
+ */
+    __pyx_t_1 = __pyx_v_self->element_type_oids;
+    __Pyx_INCREF(__pyx_t_1);
+    if (unlikely(__pyx_t_1 == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+      __PYX_ERR(3, 136, __pyx_L1_error)
+    }
+    __pyx_t_4 = PyTuple_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(3, 136, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_v_composite_size = __pyx_t_4;
+
+    /* "asyncpg/protocol/codecs/base.pyx":137
+ *             # Input is dict-like, form a tuple
+ *             composite_size = len(self.element_type_oids)
+ *             rec = cpython.PyTuple_New(composite_size)             # <<<<<<<<<<<<<<
+ * 
+ *             for i in range(composite_size):
+ */
+    __pyx_t_1 = PyTuple_New(__pyx_v_composite_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 137, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_v_rec = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":139
+ *             rec = cpython.PyTuple_New(composite_size)
+ * 
+ *             for i in range(composite_size):             # <<<<<<<<<<<<<<
+ *                 cpython.Py_INCREF(None)
+ *                 cpython.PyTuple_SET_ITEM(rec, i, None)
+ */
+    __pyx_t_5 = __pyx_v_composite_size;
+    __pyx_t_6 = __pyx_t_5;
+    for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
+      __pyx_v_i = __pyx_t_7;
+
+      /* "asyncpg/protocol/codecs/base.pyx":140
+ * 
+ *             for i in range(composite_size):
+ *                 cpython.Py_INCREF(None)             # <<<<<<<<<<<<<<
+ *                 cpython.PyTuple_SET_ITEM(rec, i, None)
+ * 
+ */
+      Py_INCREF(Py_None);
+
+      /* "asyncpg/protocol/codecs/base.pyx":141
+ *             for i in range(composite_size):
+ *                 cpython.Py_INCREF(None)
+ *                 cpython.PyTuple_SET_ITEM(rec, i, None)             # <<<<<<<<<<<<<<
+ * 
+ *             for field in obj:
+ */
+      PyTuple_SET_ITEM(__pyx_v_rec, __pyx_v_i, Py_None);
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":143
+ *                 cpython.PyTuple_SET_ITEM(rec, i, None)
+ * 
+ *             for field in obj:             # <<<<<<<<<<<<<<
+ *                 try:
+ *                     i = self.element_names[field]
+ */
+    if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+      __pyx_t_1 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
+      __pyx_t_8 = NULL;
+    } else {
+      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 143, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 143, __pyx_L1_error)
+    }
+    for (;;) {
+      if (likely(!__pyx_t_8)) {
+        if (likely(PyList_CheckExact(__pyx_t_1))) {
+          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_9 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_9); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(3, 143, __pyx_L1_error)
+          #else
+          __pyx_t_9 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 143, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          #endif
+        } else {
+          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_9); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(3, 143, __pyx_L1_error)
+          #else
+          __pyx_t_9 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 143, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          #endif
+        }
+      } else {
+        __pyx_t_9 = __pyx_t_8(__pyx_t_1);
+        if (unlikely(!__pyx_t_9)) {
+          PyObject* exc_type = PyErr_Occurred();
+          if (exc_type) {
+            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+            else __PYX_ERR(3, 143, __pyx_L1_error)
+          }
+          break;
+        }
+        __Pyx_GOTREF(__pyx_t_9);
+      }
+      __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_9);
+      __pyx_t_9 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":144
+ * 
+ *             for field in obj:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     i = self.element_names[field]
+ *                 except KeyError:
+ */
+      {
+        __Pyx_PyThreadState_declare
+        __Pyx_PyThreadState_assign
+        __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
+        __Pyx_XGOTREF(__pyx_t_10);
+        __Pyx_XGOTREF(__pyx_t_11);
+        __Pyx_XGOTREF(__pyx_t_12);
+        /*try:*/ {
+
+          /* "asyncpg/protocol/codecs/base.pyx":145
+ *             for field in obj:
+ *                 try:
+ *                     i = self.element_names[field]             # <<<<<<<<<<<<<<
+ *                 except KeyError:
+ *                     raise ValueError(
+ */
+          __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_self->element_names, __pyx_v_field); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 145, __pyx_L8_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 145, __pyx_L8_error)
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __pyx_v_i = __pyx_t_7;
+
+          /* "asyncpg/protocol/codecs/base.pyx":144
+ * 
+ *             for field in obj:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     i = self.element_names[field]
+ *                 except KeyError:
+ */
+        }
+        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        goto __pyx_L15_try_end;
+        __pyx_L8_error:;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":146
+ *                 try:
+ *                     i = self.element_names[field]
+ *                 except KeyError:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         '{!r} is not a valid element of composite '
+ */
+        __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
+        if (__pyx_t_7) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_composite", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_13, &__pyx_t_14) < 0) __PYX_ERR(3, 146, __pyx_L10_except_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_GOTREF(__pyx_t_13);
+          __Pyx_GOTREF(__pyx_t_14);
+
+          /* "asyncpg/protocol/codecs/base.pyx":149
+ *                     raise ValueError(
+ *                         '{!r} is not a valid element of composite '
+ *                         'type {}'.format(field, self.name)) from None             # <<<<<<<<<<<<<<
+ * 
+ *                 item = obj[field]
+ */
+          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_r_is_not_a_valid_element_of_com, __pyx_n_s_format); if (unlikely(!__pyx_t_16)) __PYX_ERR(3, 149, __pyx_L10_except_error)
+          __Pyx_GOTREF(__pyx_t_16);
+          __pyx_t_17 = NULL;
+          __pyx_t_7 = 0;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) {
+            __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16);
+            if (likely(__pyx_t_17)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
+              __Pyx_INCREF(__pyx_t_17);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_16, function);
+              __pyx_t_7 = 1;
+            }
+          }
+          #if CYTHON_FAST_PYCALL
+          if (PyFunction_Check(__pyx_t_16)) {
+            PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_v_field, __pyx_v_self->name};
+            __pyx_t_15 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_15)) __PYX_ERR(3, 149, __pyx_L10_except_error)
+            __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+            __Pyx_GOTREF(__pyx_t_15);
+          } else
+          #endif
+          #if CYTHON_FAST_PYCCALL
+          if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
+            PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_v_field, __pyx_v_self->name};
+            __pyx_t_15 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_15)) __PYX_ERR(3, 149, __pyx_L10_except_error)
+            __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+            __Pyx_GOTREF(__pyx_t_15);
+          } else
+          #endif
+          {
+            __pyx_t_18 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_18)) __PYX_ERR(3, 149, __pyx_L10_except_error)
+            __Pyx_GOTREF(__pyx_t_18);
+            if (__pyx_t_17) {
+              __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_17); __pyx_t_17 = NULL;
+            }
+            __Pyx_INCREF(__pyx_v_field);
+            __Pyx_GIVEREF(__pyx_v_field);
+            PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_7, __pyx_v_field);
+            __Pyx_INCREF(__pyx_v_self->name);
+            __Pyx_GIVEREF(__pyx_v_self->name);
+            PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_7, __pyx_v_self->name);
+            __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_18, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(3, 149, __pyx_L10_except_error)
+            __Pyx_GOTREF(__pyx_t_15);
+            __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+          }
+          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+
+          /* "asyncpg/protocol/codecs/base.pyx":147
+ *                     i = self.element_names[field]
+ *                 except KeyError:
+ *                     raise ValueError(             # <<<<<<<<<<<<<<
+ *                         '{!r} is not a valid element of composite '
+ *                         'type {}'.format(field, self.name)) from None
+ */
+          __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_15); if (unlikely(!__pyx_t_16)) __PYX_ERR(3, 147, __pyx_L10_except_error)
+          __Pyx_GOTREF(__pyx_t_16);
+          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+
+          /* "asyncpg/protocol/codecs/base.pyx":149
+ *                     raise ValueError(
+ *                         '{!r} is not a valid element of composite '
+ *                         'type {}'.format(field, self.name)) from None             # <<<<<<<<<<<<<<
+ * 
+ *                 item = obj[field]
+ */
+          __Pyx_Raise(__pyx_t_16, 0, 0, Py_None);
+          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+          __PYX_ERR(3, 147, __pyx_L10_except_error)
+        }
+        goto __pyx_L10_except_error;
+        __pyx_L10_except_error:;
+
+        /* "asyncpg/protocol/codecs/base.pyx":144
+ * 
+ *             for field in obj:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     i = self.element_names[field]
+ *                 except KeyError:
+ */
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_XGIVEREF(__pyx_t_11);
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+        goto __pyx_L1_error;
+        __pyx_L15_try_end:;
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":151
+ *                         'type {}'.format(field, self.name)) from None
+ * 
+ *                 item = obj[field]             # <<<<<<<<<<<<<<
+ *                 cpython.Py_INCREF(item)
+ *                 cpython.PyTuple_SET_ITEM(rec, i, item)
+ */
+      __pyx_t_14 = __Pyx_PyObject_GetItem(__pyx_v_obj, __pyx_v_field); if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 151, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_14);
+      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_14);
+      __pyx_t_14 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":152
+ * 
+ *                 item = obj[field]
+ *                 cpython.Py_INCREF(item)             # <<<<<<<<<<<<<<
+ *                 cpython.PyTuple_SET_ITEM(rec, i, item)
+ * 
+ */
+      Py_INCREF(__pyx_v_item);
+
+      /* "asyncpg/protocol/codecs/base.pyx":153
+ *                 item = obj[field]
+ *                 cpython.Py_INCREF(item)
+ *                 cpython.PyTuple_SET_ITEM(rec, i, item)             # <<<<<<<<<<<<<<
+ * 
+ *             obj = rec
+ */
+      PyTuple_SET_ITEM(__pyx_v_rec, __pyx_v_i, __pyx_v_item);
+
+      /* "asyncpg/protocol/codecs/base.pyx":143
+ *                 cpython.PyTuple_SET_ITEM(rec, i, None)
+ * 
+ *             for field in obj:             # <<<<<<<<<<<<<<
+ *                 try:
+ *                     i = self.element_names[field]
+ */
+    }
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":155
+ *                 cpython.PyTuple_SET_ITEM(rec, i, item)
+ * 
+ *             obj = rec             # <<<<<<<<<<<<<<
+ * 
+ *         count = len(obj)
+ */
+    __Pyx_INCREF(__pyx_v_rec);
+    __Pyx_DECREF_SET(__pyx_v_obj, __pyx_v_rec);
+
+    /* "asyncpg/protocol/codecs/base.pyx":134
+ *             tuple rec
+ * 
+ *         if isinstance(obj, MappingABC):             # <<<<<<<<<<<<<<
+ *             # Input is dict-like, form a tuple
+ *             composite_size = len(self.element_type_oids)
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":157
+ *             obj = rec
+ * 
+ *         count = len(obj)             # <<<<<<<<<<<<<<
+ *         if count > _MAXINT32:
+ *             raise ValueError('too many elements in composite type record')
+ */
+  __pyx_t_4 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(3, 157, __pyx_L1_error)
+  __pyx_v_count = __pyx_t_4;
+
+  /* "asyncpg/protocol/codecs/base.pyx":158
+ * 
+ *         count = len(obj)
+ *         if count > _MAXINT32:             # <<<<<<<<<<<<<<
+ *             raise ValueError('too many elements in composite type record')
+ * 
+ */
+  __pyx_t_3 = ((__pyx_v_count > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":159
+ *         count = len(obj)
+ *         if count > _MAXINT32:
+ *             raise ValueError('too many elements in composite type record')             # <<<<<<<<<<<<<<
+ * 
+ *         elem_data = WriteBuffer.new()
+ */
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 159, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(3, 159, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":158
+ * 
+ *         count = len(obj)
+ *         if count > _MAXINT32:             # <<<<<<<<<<<<<<
+ *             raise ValueError('too many elements in composite type record')
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":161
+ *             raise ValueError('too many elements in composite type record')
+ * 
+ *         elem_data = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ *         i = 0
+ *         for item in obj:
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 161, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_elem_data = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":162
+ * 
+ *         elem_data = WriteBuffer.new()
+ *         i = 0             # <<<<<<<<<<<<<<
+ *         for item in obj:
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])
+ */
+  __pyx_v_i = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":163
+ *         elem_data = WriteBuffer.new()
+ *         i = 0
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])
+ *             if item is None:
+ */
+  if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+    __pyx_t_1 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
+    __pyx_t_8 = NULL;
+  } else {
+    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 163, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 163, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_8)) {
+      if (likely(PyList_CheckExact(__pyx_t_1))) {
+        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_14 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_14); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(3, 163, __pyx_L1_error)
+        #else
+        __pyx_t_14 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 163, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_14);
+        #endif
+      } else {
+        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_14); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(3, 163, __pyx_L1_error)
+        #else
+        __pyx_t_14 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 163, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_14);
+        #endif
+      }
+    } else {
+      __pyx_t_14 = __pyx_t_8(__pyx_t_1);
+      if (unlikely(!__pyx_t_14)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(3, 163, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_14);
+    }
+    __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_14);
+    __pyx_t_14 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":164
+ *         i = 0
+ *         for item in obj:
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])             # <<<<<<<<<<<<<<
+ *             if item is None:
+ *                 elem_data.write_int32(-1)
+ */
+    if (unlikely(__pyx_v_self->element_type_oids == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(3, 164, __pyx_L1_error)
+    }
+    __pyx_t_14 = __Pyx_GetItemInt_Tuple(__pyx_v_self->element_type_oids, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 164, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_14);
+    __pyx_t_19 = __Pyx_PyInt_As_int32_t(__pyx_t_14); if (unlikely((__pyx_t_19 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 164, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+    __pyx_t_14 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_elem_data->__pyx_vtab)->write_int32(__pyx_v_elem_data, ((int32_t)__pyx_t_19)); if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 164, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_14);
+    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":165
+ *         for item in obj:
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 elem_data.write_int32(-1)
+ *             else:
+ */
+    __pyx_t_3 = (__pyx_v_item == Py_None);
+    __pyx_t_2 = (__pyx_t_3 != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":166
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])
+ *             if item is None:
+ *                 elem_data.write_int32(-1)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 (<Codec>elem_codecs[i]).encode(settings, elem_data, item)
+ */
+      __pyx_t_14 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_elem_data->__pyx_vtab)->write_int32(__pyx_v_elem_data, -1); if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 166, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_14);
+      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":165
+ *         for item in obj:
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 elem_data.write_int32(-1)
+ *             else:
+ */
+      goto __pyx_L21;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":168
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 (<Codec>elem_codecs[i]).encode(settings, elem_data, item)             # <<<<<<<<<<<<<<
+ *             i += 1
+ * 
+ */
+    /*else*/ {
+      if (unlikely(__pyx_v_elem_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(3, 168, __pyx_L1_error)
+      }
+      __pyx_t_14 = __Pyx_GetItemInt_List(__pyx_v_elem_codecs, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(3, 168, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_14);
+      __pyx_t_13 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_14), __pyx_v_settings, __pyx_v_elem_data, __pyx_v_item); if (unlikely(!__pyx_t_13)) __PYX_ERR(3, 168, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_13);
+      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+    }
+    __pyx_L21:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":169
+ *             else:
+ *                 (<Codec>elem_codecs[i]).encode(settings, elem_data, item)
+ *             i += 1             # <<<<<<<<<<<<<<
+ * 
+ *         record_encode_frame(settings, buf, elem_data, <int32_t>count)
+ */
+    __pyx_v_i = (__pyx_v_i + 1);
+
+    /* "asyncpg/protocol/codecs/base.pyx":163
+ *         elem_data = WriteBuffer.new()
+ *         i = 0
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             elem_data.write_int32(<int32_t>self.element_type_oids[i])
+ *             if item is None:
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":171
+ *             i += 1
+ * 
+ *         record_encode_frame(settings, buf, elem_data, <int32_t>count)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_record_encode_frame(__pyx_v_settings, __pyx_v_buf, __pyx_v_elem_data, ((int32_t)__pyx_v_count)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 171, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":124
+ *                      <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef encode_composite(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                           object obj):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_XDECREF(__pyx_t_17);
+  __Pyx_XDECREF(__pyx_t_18);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_composite", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_data);
+  __Pyx_XDECREF(__pyx_v_elem_codecs);
+  __Pyx_XDECREF(__pyx_v_rec);
+  __Pyx_XDECREF(__pyx_v_field);
+  __Pyx_XDECREF(__pyx_v_item);
+  __Pyx_XDECREF(__pyx_v_obj);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":173
+ *         record_encode_frame(settings, buf, elem_data, <int32_t>count)
+ * 
+ *     cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                           object obj):
+ *         data = self.py_encoder(obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_in_python(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_v_data = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("encode_in_python", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":175
+ *     cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf,
+ *                           object obj):
+ *         data = self.py_encoder(obj)             # <<<<<<<<<<<<<<
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:
+ */
+  __Pyx_INCREF(__pyx_v_self->py_encoder);
+  __pyx_t_2 = __pyx_v_self->py_encoder; __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_obj);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 175, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_data = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":176
+ *                           object obj):
+ *         data = self.py_encoder(obj)
+ *         if self.xformat == PG_XFORMAT_OBJECT:             # <<<<<<<<<<<<<<
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 pgproto.bytea_encode(settings, buf, data)
+ */
+  switch (__pyx_v_self->xformat) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT:
+
+    /* "asyncpg/protocol/codecs/base.pyx":177
+ *         data = self.py_encoder(obj)
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 pgproto.bytea_encode(settings, buf, data)
+ *             elif self.format == PG_FORMAT_TEXT:
+ */
+    switch (__pyx_v_self->format) {
+      case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY:
+
+      /* "asyncpg/protocol/codecs/base.pyx":178
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 pgproto.bytea_encode(settings, buf, data)             # <<<<<<<<<<<<<<
+ *             elif self.format == PG_FORMAT_TEXT:
+ *                 pgproto.text_encode(settings, buf, data)
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf, __pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 178, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":177
+ *         data = self.py_encoder(obj)
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 pgproto.bytea_encode(settings, buf, data)
+ *             elif self.format == PG_FORMAT_TEXT:
+ */
+      break;
+      case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT:
+
+      /* "asyncpg/protocol/codecs/base.pyx":180
+ *                 pgproto.bytea_encode(settings, buf, data)
+ *             elif self.format == PG_FORMAT_TEXT:
+ *                 pgproto.text_encode(settings, buf, data)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 raise exceptions.InternalClientError(
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_encode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf, __pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 180, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":179
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 pgproto.bytea_encode(settings, buf, data)
+ *             elif self.format == PG_FORMAT_TEXT:             # <<<<<<<<<<<<<<
+ *                 pgproto.text_encode(settings, buf, data)
+ *             else:
+ */
+      break;
+      default:
+
+      /* "asyncpg/protocol/codecs/base.pyx":182
+ *                 pgproto.text_encode(settings, buf, data)
+ *             else:
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'unexpected data format: {}'.format(self.format))
+ *         elif self.xformat == PG_XFORMAT_TUPLE:
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 182, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 182, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":183
+ *             else:
+ *                 raise exceptions.InternalClientError(
+ *                     'unexpected data format: {}'.format(self.format))             # <<<<<<<<<<<<<<
+ *         elif self.xformat == PG_XFORMAT_TUPLE:
+ *             self.c_encoder(settings, buf, data)
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_data_format, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 183, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_self->format); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 183, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 183, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 182, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(3, 182, __pyx_L1_error)
+      break;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":176
+ *                           object obj):
+ *         data = self.py_encoder(obj)
+ *         if self.xformat == PG_XFORMAT_OBJECT:             # <<<<<<<<<<<<<<
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 pgproto.bytea_encode(settings, buf, data)
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE:
+
+    /* "asyncpg/protocol/codecs/base.pyx":185
+ *                     'unexpected data format: {}'.format(self.format))
+ *         elif self.xformat == PG_XFORMAT_TUPLE:
+ *             self.c_encoder(settings, buf, data)             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise exceptions.InternalClientError(
+ */
+    __pyx_t_1 = __pyx_v_self->c_encoder(__pyx_v_settings, __pyx_v_buf, __pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 185, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":184
+ *                 raise exceptions.InternalClientError(
+ *                     'unexpected data format: {}'.format(self.format))
+ *         elif self.xformat == PG_XFORMAT_TUPLE:             # <<<<<<<<<<<<<<
+ *             self.c_encoder(settings, buf, data)
+ *         else:
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/codecs/base.pyx":187
+ *             self.c_encoder(settings, buf, data)
+ *         else:
+ *             raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                 'unexpected exchange format: {}'.format(self.xformat))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 187, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 187, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":188
+ *         else:
+ *             raise exceptions.InternalClientError(
+ *                 'unexpected exchange format: {}'.format(self.xformat))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef encode(self, ConnectionSettings settings, WriteBuffer buf,
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_exchange_format, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 188, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(__pyx_v_self->xformat); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 188, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 188, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 187, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(3, 187, __pyx_L1_error)
+    break;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":173
+ *         record_encode_frame(settings, buf, elem_data, <int32_t>count)
+ * 
+ *     cdef encode_in_python(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                           object obj):
+ *         data = self.py_encoder(obj)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode_in_python", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_data);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":190
+ *                 'unexpected exchange format: {}'.format(self.xformat))
+ * 
+ *     cdef encode(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                 object obj):
+ *         return self.encoder(self, settings, buf, obj)
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("encode", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":192
+ *     cdef encode(self, ConnectionSettings settings, WriteBuffer buf,
+ *                 object obj):
+ *         return self.encoder(self, settings, buf, obj)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef decode_scalar(self, ConnectionSettings settings, FRBuffer *buf):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_v_self->encoder(__pyx_v_self, __pyx_v_settings, __pyx_v_buf, __pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 192, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":190
+ *                 'unexpected exchange format: {}'.format(self.xformat))
+ * 
+ *     cdef encode(self, ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                 object obj):
+ *         return self.encoder(self, settings, buf, obj)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":194
+ *         return self.encoder(self, settings, buf, obj)
+ * 
+ *     cdef decode_scalar(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return self.c_decoder(settings, buf)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_scalar(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("decode_scalar", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":195
+ * 
+ *     cdef decode_scalar(self, ConnectionSettings settings, FRBuffer *buf):
+ *         return self.c_decoder(settings, buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_v_self->c_decoder(__pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 195, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":194
+ *         return self.encoder(self, settings, buf, obj)
+ * 
+ *     cdef decode_scalar(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return self.c_decoder(settings, buf)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":197
+ *         return self.c_decoder(settings, buf)
+ * 
+ *     cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return array_decode(settings, buf, codec_decode_func_ex,
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("decode_array", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":198
+ * 
+ *     cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf):
+ *         return array_decode(settings, buf, codec_decode_func_ex,             # <<<<<<<<<<<<<<
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/protocol/codecs/base.pyx":199
+ *     cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf):
+ *         return array_decode(settings, buf, codec_decode_func_ex,
+ *                             <void*>(<cpython.PyObject>self.element_codec))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef decode_array_text(self, ConnectionSettings settings,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_array_decode(__pyx_v_settings, __pyx_v_buf, __pyx_f_7asyncpg_8protocol_8protocol_codec_decode_func_ex, ((void *)__pyx_v_self->element_codec)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 198, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":197
+ *         return self.c_decoder(settings, buf)
+ * 
+ *     cdef decode_array(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return array_decode(settings, buf, codec_decode_func_ex,
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode_array", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":201
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef decode_array_text(self, ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                            FRBuffer *buf):
+ *         return textarray_decode(settings, buf, codec_decode_func_ex,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array_text(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("decode_array_text", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":203
+ *     cdef decode_array_text(self, ConnectionSettings settings,
+ *                            FRBuffer *buf):
+ *         return textarray_decode(settings, buf, codec_decode_func_ex,             # <<<<<<<<<<<<<<
+ *                                 <void*>(<cpython.PyObject>self.element_codec),
+ *                                 self.element_delimiter)
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/protocol/codecs/base.pyx":205
+ *         return textarray_decode(settings, buf, codec_decode_func_ex,
+ *                                 <void*>(<cpython.PyObject>self.element_codec),
+ *                                 self.element_delimiter)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf):
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_textarray_decode(__pyx_v_settings, __pyx_v_buf, __pyx_f_7asyncpg_8protocol_8protocol_codec_decode_func_ex, ((void *)__pyx_v_self->element_codec), __pyx_v_self->element_delimiter); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 203, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":201
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef decode_array_text(self, ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                            FRBuffer *buf):
+ *         return textarray_decode(settings, buf, codec_decode_func_ex,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode_array_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":207
+ *                                 self.element_delimiter)
+ * 
+ *     cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return range_decode(settings, buf, codec_decode_func_ex,
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_range(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("decode_range", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":208
+ * 
+ *     cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf):
+ *         return range_decode(settings, buf, codec_decode_func_ex,             # <<<<<<<<<<<<<<
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/protocol/codecs/base.pyx":209
+ *     cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf):
+ *         return range_decode(settings, buf, codec_decode_func_ex,
+ *                             <void*>(<cpython.PyObject>self.element_codec))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef decode_composite(self, ConnectionSettings settings,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_range_decode(__pyx_v_settings, __pyx_v_buf, __pyx_f_7asyncpg_8protocol_8protocol_codec_decode_func_ex, ((void *)__pyx_v_self->element_codec)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 208, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":207
+ *                                 self.element_delimiter)
+ * 
+ *     cdef decode_range(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return range_decode(settings, buf, codec_decode_func_ex,
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":211
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef decode_composite(self, ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                           FRBuffer *buf):
+ *         cdef:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_composite(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_v_result = 0;
+  Py_ssize_t __pyx_v_elem_count;
+  Py_ssize_t __pyx_v_i;
+  int32_t __pyx_v_elem_len;
+  uint32_t __pyx_v_elem_typ;
+  uint32_t __pyx_v_received_elem_typ;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_elem_codec = 0;
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer __pyx_v_elem_buf;
+  PyObject *__pyx_v_elem = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  Py_ssize_t __pyx_t_12;
+  Py_ssize_t __pyx_t_13;
+  Py_ssize_t __pyx_t_14;
+  uint32_t __pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  __Pyx_RefNannySetupContext("decode_composite", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":223
+ *             FRBuffer elem_buf
+ * 
+ *         elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         if elem_count != len(self.element_type_oids):
+ *             raise exceptions.OutdatedSchemaCacheError(
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(3, 223, __pyx_L1_error)
+  __pyx_v_elem_count = ((Py_ssize_t)((uint32_t)unpack_int32(__pyx_t_1)));
+
+  /* "asyncpg/protocol/codecs/base.pyx":224
+ * 
+ *         elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_count != len(self.element_type_oids):             # <<<<<<<<<<<<<<
+ *             raise exceptions.OutdatedSchemaCacheError(
+ *                 'unexpected number of attributes of composite type: '
+ */
+  __pyx_t_2 = __pyx_v_self->element_type_oids;
+  __Pyx_INCREF(__pyx_t_2);
+  if (unlikely(__pyx_t_2 == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(3, 224, __pyx_L1_error)
+  }
+  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(3, 224, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_4 = ((__pyx_v_elem_count != __pyx_t_3) != 0);
+  if (unlikely(__pyx_t_4)) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":225
+ *         elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_count != len(self.element_type_oids):
+ *             raise exceptions.OutdatedSchemaCacheError(             # <<<<<<<<<<<<<<
+ *                 'unexpected number of attributes of composite type: '
+ *                 '{}, expected {}'
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 225, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OutdatedSchemaCacheError); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 225, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":228
+ *                 'unexpected number of attributes of composite type: '
+ *                 '{}, expected {}'
+ *                     .format(             # <<<<<<<<<<<<<<
+ *                         elem_count,
+ *                         len(self.element_type_oids),
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_number_of_attributes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 228, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+
+    /* "asyncpg/protocol/codecs/base.pyx":229
+ *                 '{}, expected {}'
+ *                     .format(
+ *                         elem_count,             # <<<<<<<<<<<<<<
+ *                         len(self.element_type_oids),
+ *                     ),
+ */
+    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_elem_count); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 229, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+
+    /* "asyncpg/protocol/codecs/base.pyx":230
+ *                     .format(
+ *                         elem_count,
+ *                         len(self.element_type_oids),             # <<<<<<<<<<<<<<
+ *                     ),
+ *                 schema=self.schema,
+ */
+    __pyx_t_8 = __pyx_v_self->element_type_oids;
+    __Pyx_INCREF(__pyx_t_8);
+    if (unlikely(__pyx_t_8 == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+      __PYX_ERR(3, 230, __pyx_L1_error)
+    }
+    __pyx_t_3 = PyTuple_GET_SIZE(__pyx_t_8); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(3, 230, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 230, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_9 = NULL;
+    __pyx_t_10 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_9)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_9);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+        __pyx_t_10 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
+      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 228, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
+      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 228, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 228, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      if (__pyx_t_9) {
+        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_7);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
+      __pyx_t_7 = 0;
+      __pyx_t_8 = 0;
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 228, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":225
+ *         elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_count != len(self.element_type_oids):
+ *             raise exceptions.OutdatedSchemaCacheError(             # <<<<<<<<<<<<<<
+ *                 'unexpected number of attributes of composite type: '
+ *                 '{}, expected {}'
+ */
+    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 225, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":232
+ *                         len(self.element_type_oids),
+ *                     ),
+ *                 schema=self.schema,             # <<<<<<<<<<<<<<
+ *                 data_type=self.name,
+ *             )
+ */
+    __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 232, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_schema, __pyx_v_self->schema) < 0) __PYX_ERR(3, 232, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":233
+ *                     ),
+ *                 schema=self.schema,
+ *                 data_type=self.name,             # <<<<<<<<<<<<<<
+ *             )
+ *         result = record.ApgRecord_New(self.record_desc, elem_count)
+ */
+    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_data_type, __pyx_v_self->name) < 0) __PYX_ERR(3, 232, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":225
+ *         elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_count != len(self.element_type_oids):
+ *             raise exceptions.OutdatedSchemaCacheError(             # <<<<<<<<<<<<<<
+ *                 'unexpected number of attributes of composite type: '
+ *                 '{}, expected {}'
+ */
+    __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 225, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_11);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_11, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+    __PYX_ERR(3, 225, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":224
+ * 
+ *         elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_count != len(self.element_type_oids):             # <<<<<<<<<<<<<<
+ *             raise exceptions.OutdatedSchemaCacheError(
+ *                 'unexpected number of attributes of composite type: '
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":235
+ *                 data_type=self.name,
+ *             )
+ *         result = record.ApgRecord_New(self.record_desc, elem_count)             # <<<<<<<<<<<<<<
+ *         for i in range(elem_count):
+ *             elem_typ = self.element_type_oids[i]
+ */
+  __pyx_t_11 = __pyx_v_self->record_desc;
+  __Pyx_INCREF(__pyx_t_11);
+  __pyx_t_2 = ApgRecord_New(__pyx_t_11, __pyx_v_elem_count); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 235, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+  __pyx_v_result = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":236
+ *             )
+ *         result = record.ApgRecord_New(self.record_desc, elem_count)
+ *         for i in range(elem_count):             # <<<<<<<<<<<<<<
+ *             elem_typ = self.element_type_oids[i]
+ *             received_elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ */
+  __pyx_t_12 = __pyx_v_elem_count;
+  __pyx_t_13 = __pyx_t_12;
+  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
+    __pyx_v_i = __pyx_t_14;
+
+    /* "asyncpg/protocol/codecs/base.pyx":237
+ *         result = record.ApgRecord_New(self.record_desc, elem_count)
+ *         for i in range(elem_count):
+ *             elem_typ = self.element_type_oids[i]             # <<<<<<<<<<<<<<
+ *             received_elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+    if (unlikely(__pyx_v_self->element_type_oids == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(3, 237, __pyx_L1_error)
+    }
+    __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_self->element_type_oids, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 237, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_15 = __Pyx_PyInt_As_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_15 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 237, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_v_elem_typ = __pyx_t_15;
+
+    /* "asyncpg/protocol/codecs/base.pyx":238
+ *         for i in range(elem_count):
+ *             elem_typ = self.element_type_oids[i]
+ *             received_elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *             if received_elem_typ != elem_typ:
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(3, 238, __pyx_L1_error)
+    __pyx_v_received_elem_typ = ((uint32_t)unpack_int32(__pyx_t_1));
+
+    /* "asyncpg/protocol/codecs/base.pyx":240
+ *             received_elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *             if received_elem_typ != elem_typ:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.OutdatedSchemaCacheError(
+ *                     'unexpected data type of composite type attribute {}: '
+ */
+    __pyx_t_4 = ((__pyx_v_received_elem_typ != __pyx_v_elem_typ) != 0);
+    if (unlikely(__pyx_t_4)) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":241
+ * 
+ *             if received_elem_typ != elem_typ:
+ *                 raise exceptions.OutdatedSchemaCacheError(             # <<<<<<<<<<<<<<
+ *                     'unexpected data type of composite type attribute {}: '
+ *                     '{!r}, expected {!r}'
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 241, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OutdatedSchemaCacheError); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 241, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":244
+ *                     'unexpected data type of composite type attribute {}: '
+ *                     '{!r}, expected {!r}'
+ *                         .format(             # <<<<<<<<<<<<<<
+ *                             i,
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ */
+      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_data_type_of_composit, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 244, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+
+      /* "asyncpg/protocol/codecs/base.pyx":245
+ *                     '{!r}, expected {!r}'
+ *                         .format(
+ *                             i,             # <<<<<<<<<<<<<<
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ *                                 received_elem_typ, received_elem_typ),
+ */
+      __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 245, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+
+      /* "asyncpg/protocol/codecs/base.pyx":246
+ *                         .format(
+ *                             i,
+ *                             BUILTIN_TYPE_OID_MAP.get(             # <<<<<<<<<<<<<<
+ *                                 received_elem_typ, received_elem_typ),
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_BUILTIN_TYPE_OID_MAP); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 246, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 246, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":247
+ *                             i,
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ *                                 received_elem_typ, received_elem_typ),             # <<<<<<<<<<<<<<
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ *                                 elem_typ, elem_typ)
+ */
+      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_received_elem_typ); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 247, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_16 = __Pyx_PyInt_From_uint32_t(__pyx_v_received_elem_typ); if (unlikely(!__pyx_t_16)) __PYX_ERR(3, 247, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_16);
+      __pyx_t_17 = NULL;
+      __pyx_t_10 = 0;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_17)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_17);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+          __pyx_t_10 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_9)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_7, __pyx_t_16};
+        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 246, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_7, __pyx_t_16};
+        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 246, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_18 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_18)) __PYX_ERR(3, 246, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_18);
+        if (__pyx_t_17) {
+          __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_17); __pyx_t_17 = NULL;
+        }
+        __Pyx_GIVEREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_10, __pyx_t_7);
+        __Pyx_GIVEREF(__pyx_t_16);
+        PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_10, __pyx_t_16);
+        __pyx_t_7 = 0;
+        __pyx_t_16 = 0;
+        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_18, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 246, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":248
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ *                                 received_elem_typ, received_elem_typ),
+ *                             BUILTIN_TYPE_OID_MAP.get(             # <<<<<<<<<<<<<<
+ *                                 elem_typ, elem_typ)
+ *                         ),
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_18, __pyx_n_s_BUILTIN_TYPE_OID_MAP); if (unlikely(!__pyx_t_18)) __PYX_ERR(3, 248, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_18);
+      __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_get); if (unlikely(!__pyx_t_16)) __PYX_ERR(3, 248, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_16);
+      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":249
+ *                                 received_elem_typ, received_elem_typ),
+ *                             BUILTIN_TYPE_OID_MAP.get(
+ *                                 elem_typ, elem_typ)             # <<<<<<<<<<<<<<
+ *                         ),
+ *                     schema=self.schema,
+ */
+      __pyx_t_18 = __Pyx_PyInt_From_uint32_t(__pyx_v_elem_typ); if (unlikely(!__pyx_t_18)) __PYX_ERR(3, 249, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_18);
+      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_elem_typ); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 249, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_17 = NULL;
+      __pyx_t_10 = 0;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
+        __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16);
+        if (likely(__pyx_t_17)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
+          __Pyx_INCREF(__pyx_t_17);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_16, function);
+          __pyx_t_10 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_16)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_18, __pyx_t_7};
+        __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 248, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_18, __pyx_t_7};
+        __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 248, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_19 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_19)) __PYX_ERR(3, 248, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_19);
+        if (__pyx_t_17) {
+          __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_17); __pyx_t_17 = NULL;
+        }
+        __Pyx_GIVEREF(__pyx_t_18);
+        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_10, __pyx_t_18);
+        __Pyx_GIVEREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_10, __pyx_t_7);
+        __pyx_t_18 = 0;
+        __pyx_t_7 = 0;
+        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_19, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 248, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+      __pyx_t_16 = NULL;
+      __pyx_t_10 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_6);
+        if (likely(__pyx_t_16)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+          __Pyx_INCREF(__pyx_t_16);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_6, function);
+          __pyx_t_10 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_6)) {
+        PyObject *__pyx_temp[4] = {__pyx_t_16, __pyx_t_5, __pyx_t_8, __pyx_t_9};
+        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 244, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+        PyObject *__pyx_temp[4] = {__pyx_t_16, __pyx_t_5, __pyx_t_8, __pyx_t_9};
+        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 244, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_19 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_19)) __PYX_ERR(3, 244, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_19);
+        if (__pyx_t_16) {
+          __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_16); __pyx_t_16 = NULL;
+        }
+        __Pyx_GIVEREF(__pyx_t_5);
+        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_10, __pyx_t_5);
+        __Pyx_GIVEREF(__pyx_t_8);
+        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_10, __pyx_t_8);
+        __Pyx_GIVEREF(__pyx_t_9);
+        PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_10, __pyx_t_9);
+        __pyx_t_5 = 0;
+        __pyx_t_8 = 0;
+        __pyx_t_9 = 0;
+        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 244, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":241
+ * 
+ *             if received_elem_typ != elem_typ:
+ *                 raise exceptions.OutdatedSchemaCacheError(             # <<<<<<<<<<<<<<
+ *                     'unexpected data type of composite type attribute {}: '
+ *                     '{!r}, expected {!r}'
+ */
+      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 241, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GIVEREF(__pyx_t_2);
+      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":251
+ *                                 elem_typ, elem_typ)
+ *                         ),
+ *                     schema=self.schema,             # <<<<<<<<<<<<<<
+ *                     data_type=self.name,
+ *                     position=i,
+ */
+      __pyx_t_2 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 251, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_schema, __pyx_v_self->schema) < 0) __PYX_ERR(3, 251, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":252
+ *                         ),
+ *                     schema=self.schema,
+ *                     data_type=self.name,             # <<<<<<<<<<<<<<
+ *                     position=i,
+ *                 )
+ */
+      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_data_type, __pyx_v_self->name) < 0) __PYX_ERR(3, 251, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":253
+ *                     schema=self.schema,
+ *                     data_type=self.name,
+ *                     position=i,             # <<<<<<<<<<<<<<
+ *                 )
+ * 
+ */
+      __pyx_t_19 = PyInt_FromSsize_t(__pyx_v_i); if (unlikely(!__pyx_t_19)) __PYX_ERR(3, 253, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_19);
+      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_position, __pyx_t_19) < 0) __PYX_ERR(3, 251, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":241
+ * 
+ *             if received_elem_typ != elem_typ:
+ *                 raise exceptions.OutdatedSchemaCacheError(             # <<<<<<<<<<<<<<
+ *                     'unexpected data type of composite type attribute {}: '
+ *                     '{!r}, expected {!r}'
+ */
+      __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_19)) __PYX_ERR(3, 241, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_19);
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_Raise(__pyx_t_19, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+      __PYX_ERR(3, 241, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":240
+ *             received_elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *             if received_elem_typ != elem_typ:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.OutdatedSchemaCacheError(
+ *                     'unexpected data type of composite type attribute {}: '
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":256
+ *                 )
+ * 
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *             if elem_len == -1:
+ *                 elem = None
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(3, 256, __pyx_L1_error)
+    __pyx_v_elem_len = unpack_int32(__pyx_t_1);
+
+    /* "asyncpg/protocol/codecs/base.pyx":257
+ * 
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:             # <<<<<<<<<<<<<<
+ *                 elem = None
+ *             else:
+ */
+    __pyx_t_4 = ((__pyx_v_elem_len == -1L) != 0);
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":258
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:
+ *                 elem = None             # <<<<<<<<<<<<<<
+ *             else:
+ *                 elem_codec = self.element_codecs[i]
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_elem, Py_None);
+
+      /* "asyncpg/protocol/codecs/base.pyx":257
+ * 
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:             # <<<<<<<<<<<<<<
+ *                 elem = None
+ *             else:
+ */
+      goto __pyx_L7;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":260
+ *                 elem = None
+ *             else:
+ *                 elem_codec = self.element_codecs[i]             # <<<<<<<<<<<<<<
+ *                 elem = elem_codec.decode(
+ *                     settings, frb_slice_from(&elem_buf, buf, elem_len))
+ */
+    /*else*/ {
+      if (unlikely(__pyx_v_self->element_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(3, 260, __pyx_L1_error)
+      }
+      __pyx_t_19 = __Pyx_GetItemInt_List(__pyx_v_self->element_codecs, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1); if (unlikely(!__pyx_t_19)) __PYX_ERR(3, 260, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_19);
+      if (!(likely(((__pyx_t_19) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_19, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 260, __pyx_L1_error)
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_19));
+      __pyx_t_19 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":261
+ *             else:
+ *                 elem_codec = self.element_codecs[i]
+ *                 elem = elem_codec.decode(             # <<<<<<<<<<<<<<
+ *                     settings, frb_slice_from(&elem_buf, buf, elem_len))
+ * 
+ */
+      __pyx_t_19 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(__pyx_v_elem_codec, __pyx_v_settings, __pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from((&__pyx_v_elem_buf), __pyx_v_buf, __pyx_v_elem_len)); if (unlikely(!__pyx_t_19)) __PYX_ERR(3, 261, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_19);
+      __Pyx_XDECREF_SET(__pyx_v_elem, __pyx_t_19);
+      __pyx_t_19 = 0;
+    }
+    __pyx_L7:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":264
+ *                     settings, frb_slice_from(&elem_buf, buf, elem_len))
+ * 
+ *             cpython.Py_INCREF(elem)             # <<<<<<<<<<<<<<
+ *             record.ApgRecord_SET_ITEM(result, i, elem)
+ * 
+ */
+    Py_INCREF(__pyx_v_elem);
+
+    /* "asyncpg/protocol/codecs/base.pyx":265
+ * 
+ *             cpython.Py_INCREF(elem)
+ *             record.ApgRecord_SET_ITEM(result, i, elem)             # <<<<<<<<<<<<<<
+ * 
+ *         return result
+ */
+    ApgRecord_SET_ITEM(__pyx_v_result, __pyx_v_i, __pyx_v_elem);
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":267
+ *             record.ApgRecord_SET_ITEM(result, i, elem)
+ * 
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     cdef decode_in_python(self, ConnectionSettings settings,
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":211
+ *                             <void*>(<cpython.PyObject>self.element_codec))
+ * 
+ *     cdef decode_composite(self, ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                           FRBuffer *buf):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_XDECREF(__pyx_t_17);
+  __Pyx_XDECREF(__pyx_t_18);
+  __Pyx_XDECREF(__pyx_t_19);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode_composite", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_codec);
+  __Pyx_XDECREF(__pyx_v_elem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":269
+ *         return result
+ * 
+ *     cdef decode_in_python(self, ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                           FRBuffer *buf):
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_in_python(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_v_data = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("decode_in_python", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":271
+ *     cdef decode_in_python(self, ConnectionSettings settings,
+ *                           FRBuffer *buf):
+ *         if self.xformat == PG_XFORMAT_OBJECT:             # <<<<<<<<<<<<<<
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 data = pgproto.bytea_decode(settings, buf)
+ */
+  switch (__pyx_v_self->xformat) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT:
+
+    /* "asyncpg/protocol/codecs/base.pyx":272
+ *                           FRBuffer *buf):
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 data = pgproto.bytea_decode(settings, buf)
+ *             elif self.format == PG_FORMAT_TEXT:
+ */
+    switch (__pyx_v_self->format) {
+      case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY:
+
+      /* "asyncpg/protocol/codecs/base.pyx":273
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 data = pgproto.bytea_decode(settings, buf)             # <<<<<<<<<<<<<<
+ *             elif self.format == PG_FORMAT_TEXT:
+ *                 data = pgproto.text_decode(settings, buf)
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 273, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_v_data = __pyx_t_1;
+      __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":272
+ *                           FRBuffer *buf):
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ *             if self.format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 data = pgproto.bytea_decode(settings, buf)
+ *             elif self.format == PG_FORMAT_TEXT:
+ */
+      break;
+      case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT:
+
+      /* "asyncpg/protocol/codecs/base.pyx":275
+ *                 data = pgproto.bytea_decode(settings, buf)
+ *             elif self.format == PG_FORMAT_TEXT:
+ *                 data = pgproto.text_decode(settings, buf)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 raise exceptions.InternalClientError(
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 275, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_v_data = __pyx_t_1;
+      __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":274
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 data = pgproto.bytea_decode(settings, buf)
+ *             elif self.format == PG_FORMAT_TEXT:             # <<<<<<<<<<<<<<
+ *                 data = pgproto.text_decode(settings, buf)
+ *             else:
+ */
+      break;
+      default:
+
+      /* "asyncpg/protocol/codecs/base.pyx":277
+ *                 data = pgproto.text_decode(settings, buf)
+ *             else:
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'unexpected data format: {}'.format(self.format))
+ *         elif self.xformat == PG_XFORMAT_TUPLE:
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 277, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 277, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":278
+ *             else:
+ *                 raise exceptions.InternalClientError(
+ *                     'unexpected data format: {}'.format(self.format))             # <<<<<<<<<<<<<<
+ *         elif self.xformat == PG_XFORMAT_TUPLE:
+ *             data = self.c_decoder(settings, buf)
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_data_format, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 278, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_self->format); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 278, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 278, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 277, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(3, 277, __pyx_L1_error)
+      break;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":271
+ *     cdef decode_in_python(self, ConnectionSettings settings,
+ *                           FRBuffer *buf):
+ *         if self.xformat == PG_XFORMAT_OBJECT:             # <<<<<<<<<<<<<<
+ *             if self.format == PG_FORMAT_BINARY:
+ *                 data = pgproto.bytea_decode(settings, buf)
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE:
+
+    /* "asyncpg/protocol/codecs/base.pyx":280
+ *                     'unexpected data format: {}'.format(self.format))
+ *         elif self.xformat == PG_XFORMAT_TUPLE:
+ *             data = self.c_decoder(settings, buf)             # <<<<<<<<<<<<<<
+ *         else:
+ *             raise exceptions.InternalClientError(
+ */
+    __pyx_t_1 = __pyx_v_self->c_decoder(__pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 280, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_v_data = __pyx_t_1;
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":279
+ *                 raise exceptions.InternalClientError(
+ *                     'unexpected data format: {}'.format(self.format))
+ *         elif self.xformat == PG_XFORMAT_TUPLE:             # <<<<<<<<<<<<<<
+ *             data = self.c_decoder(settings, buf)
+ *         else:
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/codecs/base.pyx":282
+ *             data = self.c_decoder(settings, buf)
+ *         else:
+ *             raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                 'unexpected exchange format: {}'.format(self.xformat))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 282, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 282, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":283
+ *         else:
+ *             raise exceptions.InternalClientError(
+ *                 'unexpected exchange format: {}'.format(self.xformat))             # <<<<<<<<<<<<<<
+ * 
+ *         return self.py_decoder(data)
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_exchange_format, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 283, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(__pyx_v_self->xformat); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 283, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 283, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 282, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(3, 282, __pyx_L1_error)
+    break;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":285
+ *                 'unexpected exchange format: {}'.format(self.xformat))
+ * 
+ *         return self.py_decoder(data)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline decode(self, ConnectionSettings settings, FRBuffer *buf):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->py_decoder);
+  __pyx_t_2 = __pyx_v_self->py_decoder; __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_data) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_data);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 285, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":269
+ *         return result
+ * 
+ *     cdef decode_in_python(self, ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                           FRBuffer *buf):
+ *         if self.xformat == PG_XFORMAT_OBJECT:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode_in_python", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_data);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":287
+ *         return self.py_decoder(data)
+ * 
+ *     cdef inline decode(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return self.decoder(self, settings, buf)
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("decode", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":288
+ * 
+ *     cdef inline decode(self, ConnectionSettings settings, FRBuffer *buf):
+ *         return self.decoder(self, settings, buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline has_encoder(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_v_self->decoder(__pyx_v_self, __pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 288, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":287
+ *         return self.py_decoder(data)
+ * 
+ *     cdef inline decode(self, ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *         return self.decoder(self, settings, buf)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":290
+ *         return self.decoder(self, settings, buf)
+ * 
+ *     cdef inline has_encoder(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec elem_codec
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_elem_codec = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  Py_ssize_t __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("has_encoder", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":293
+ *         cdef Codec elem_codec
+ * 
+ *         if self.c_encoder is not NULL or self.py_encoder is not None:             # <<<<<<<<<<<<<<
+ *             return True
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_self->c_encoder != NULL) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = (__pyx_v_self->py_encoder != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  __pyx_t_1 = __pyx_t_3;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":294
+ * 
+ *         if self.c_encoder is not NULL or self.py_encoder is not None:
+ *             return True             # <<<<<<<<<<<<<<
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(Py_True);
+    __pyx_r = Py_True;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":293
+ *         cdef Codec elem_codec
+ * 
+ *         if self.c_encoder is not NULL or self.py_encoder is not None:             # <<<<<<<<<<<<<<
+ *             return True
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":296
+ *             return True
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:             # <<<<<<<<<<<<<<
+ *             return self.element_codec.has_encoder()
+ * 
+ */
+  switch (__pyx_v_self->type) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_ARRAY:
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_RANGE:
+    __pyx_t_1 = 1;
+    break;
+    default:
+    __pyx_t_1 = 0;
+    break;
+  }
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":297
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:
+ *             return self.element_codec.has_encoder()             # <<<<<<<<<<<<<<
+ * 
+ *         elif self.type == CODEC_COMPOSITE:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(__pyx_v_self->element_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 297, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":296
+ *             return True
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:             # <<<<<<<<<<<<<<
+ *             return self.element_codec.has_encoder()
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":299
+ *             return self.element_codec.has_encoder()
+ * 
+ *         elif self.type == CODEC_COMPOSITE:             # <<<<<<<<<<<<<<
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_encoder():
+ */
+  __pyx_t_1 = ((__pyx_v_self->type == __pyx_e_7asyncpg_8protocol_8protocol_CODEC_COMPOSITE) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":300
+ * 
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:             # <<<<<<<<<<<<<<
+ *                 if not elem_codec.has_encoder():
+ *                     return False
+ */
+    if (unlikely(__pyx_v_self->element_codecs == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+      __PYX_ERR(3, 300, __pyx_L1_error)
+    }
+    __pyx_t_4 = __pyx_v_self->element_codecs; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
+    for (;;) {
+      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
+      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(3, 300, __pyx_L1_error)
+      #else
+      __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 300, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      #endif
+      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 300, __pyx_L1_error)
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_6));
+      __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":301
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_encoder():             # <<<<<<<<<<<<<<
+ *                     return False
+ *             return True
+ */
+      __pyx_t_6 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(__pyx_v_elem_codec); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 301, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(3, 301, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_3 = ((!__pyx_t_1) != 0);
+      if (__pyx_t_3) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":302
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_encoder():
+ *                     return False             # <<<<<<<<<<<<<<
+ *             return True
+ * 
+ */
+        __Pyx_XDECREF(__pyx_r);
+        __Pyx_INCREF(Py_False);
+        __pyx_r = Py_False;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        goto __pyx_L0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":301
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_encoder():             # <<<<<<<<<<<<<<
+ *                     return False
+ *             return True
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":300
+ * 
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:             # <<<<<<<<<<<<<<
+ *                 if not elem_codec.has_encoder():
+ *                     return False
+ */
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":303
+ *                 if not elem_codec.has_encoder():
+ *                     return False
+ *             return True             # <<<<<<<<<<<<<<
+ * 
+ *         else:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(Py_True);
+    __pyx_r = Py_True;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":299
+ *             return self.element_codec.has_encoder()
+ * 
+ *         elif self.type == CODEC_COMPOSITE:             # <<<<<<<<<<<<<<
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_encoder():
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":306
+ * 
+ *         else:
+ *             return False             # <<<<<<<<<<<<<<
+ * 
+ *     cdef has_decoder(self):
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(Py_False);
+    __pyx_r = Py_False;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":290
+ *         return self.decoder(self, settings, buf)
+ * 
+ *     cdef inline has_encoder(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec elem_codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.has_encoder", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_codec);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":308
+ *             return False
+ * 
+ *     cdef has_decoder(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec elem_codec
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_elem_codec = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  Py_ssize_t __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("has_decoder", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":311
+ *         cdef Codec elem_codec
+ * 
+ *         if self.c_decoder is not NULL or self.py_decoder is not None:             # <<<<<<<<<<<<<<
+ *             return True
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_self->c_decoder != NULL) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = (__pyx_v_self->py_decoder != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  __pyx_t_1 = __pyx_t_3;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":312
+ * 
+ *         if self.c_decoder is not NULL or self.py_decoder is not None:
+ *             return True             # <<<<<<<<<<<<<<
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(Py_True);
+    __pyx_r = Py_True;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":311
+ *         cdef Codec elem_codec
+ * 
+ *         if self.c_decoder is not NULL or self.py_decoder is not None:             # <<<<<<<<<<<<<<
+ *             return True
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":314
+ *             return True
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:             # <<<<<<<<<<<<<<
+ *             return self.element_codec.has_decoder()
+ * 
+ */
+  switch (__pyx_v_self->type) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_ARRAY:
+    case __pyx_e_7asyncpg_8protocol_8protocol_CODEC_RANGE:
+    __pyx_t_1 = 1;
+    break;
+    default:
+    __pyx_t_1 = 0;
+    break;
+  }
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":315
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:
+ *             return self.element_codec.has_decoder()             # <<<<<<<<<<<<<<
+ * 
+ *         elif self.type == CODEC_COMPOSITE:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(__pyx_v_self->element_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 315, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":314
+ *             return True
+ * 
+ *         elif self.type == CODEC_ARRAY or self.type == CODEC_RANGE:             # <<<<<<<<<<<<<<
+ *             return self.element_codec.has_decoder()
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":317
+ *             return self.element_codec.has_decoder()
+ * 
+ *         elif self.type == CODEC_COMPOSITE:             # <<<<<<<<<<<<<<
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_decoder():
+ */
+  __pyx_t_1 = ((__pyx_v_self->type == __pyx_e_7asyncpg_8protocol_8protocol_CODEC_COMPOSITE) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":318
+ * 
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:             # <<<<<<<<<<<<<<
+ *                 if not elem_codec.has_decoder():
+ *                     return False
+ */
+    if (unlikely(__pyx_v_self->element_codecs == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+      __PYX_ERR(3, 318, __pyx_L1_error)
+    }
+    __pyx_t_4 = __pyx_v_self->element_codecs; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
+    for (;;) {
+      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
+      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(3, 318, __pyx_L1_error)
+      #else
+      __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 318, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      #endif
+      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 318, __pyx_L1_error)
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_6));
+      __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":319
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                     return False
+ *             return True
+ */
+      __pyx_t_6 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(__pyx_v_elem_codec); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 319, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(3, 319, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_3 = ((!__pyx_t_1) != 0);
+      if (__pyx_t_3) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":320
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_decoder():
+ *                     return False             # <<<<<<<<<<<<<<
+ *             return True
+ * 
+ */
+        __Pyx_XDECREF(__pyx_r);
+        __Pyx_INCREF(Py_False);
+        __pyx_r = Py_False;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        goto __pyx_L0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":319
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                     return False
+ *             return True
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":318
+ * 
+ *         elif self.type == CODEC_COMPOSITE:
+ *             for elem_codec in self.element_codecs:             # <<<<<<<<<<<<<<
+ *                 if not elem_codec.has_decoder():
+ *                     return False
+ */
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":321
+ *                 if not elem_codec.has_decoder():
+ *                     return False
+ *             return True             # <<<<<<<<<<<<<<
+ * 
+ *         else:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(Py_True);
+    __pyx_r = Py_True;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":317
+ *             return self.element_codec.has_decoder()
+ * 
+ *         elif self.type == CODEC_COMPOSITE:             # <<<<<<<<<<<<<<
+ *             for elem_codec in self.element_codecs:
+ *                 if not elem_codec.has_decoder():
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":324
+ * 
+ *         else:
+ *             return False             # <<<<<<<<<<<<<<
+ * 
+ *     cdef is_binary(self):
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(Py_False);
+    __pyx_r = Py_False;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":308
+ *             return False
+ * 
+ *     cdef has_decoder(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec elem_codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.has_decoder", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_codec);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":326
+ *             return False
+ * 
+ *     cdef is_binary(self):             # <<<<<<<<<<<<<<
+ *         return self.format == PG_FORMAT_BINARY
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_is_binary(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("is_binary", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":327
+ * 
+ *     cdef is_binary(self):
+ *         return self.format == PG_FORMAT_BINARY             # <<<<<<<<<<<<<<
+ * 
+ *     def __repr__(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->format == __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 327, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":326
+ *             return False
+ * 
+ *     cdef is_binary(self):             # <<<<<<<<<<<<<<
+ *         return self.format == PG_FORMAT_BINARY
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.is_binary", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":329
+ *         return self.format == PG_FORMAT_BINARY
+ * 
+ *     def __repr__(self):             # <<<<<<<<<<<<<<
+ *         return '<Codec oid={} elem_oid={} core={}>'.format(
+ *             self.oid,
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_3__repr__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_3__repr__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Codec_2__repr__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Codec_2__repr__(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("__repr__", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":330
+ * 
+ *     def __repr__(self):
+ *         return '<Codec oid={} elem_oid={} core={}>'.format(             # <<<<<<<<<<<<<<
+ *             self.oid,
+ *             'NA' if self.element_codec is None else self.element_codec.oid,
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_Codec_oid_elem_oid_core, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 330, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+
+  /* "asyncpg/protocol/codecs/base.pyx":331
+ *     def __repr__(self):
+ *         return '<Codec oid={} elem_oid={} core={}>'.format(
+ *             self.oid,             # <<<<<<<<<<<<<<
+ *             'NA' if self.element_codec is None else self.element_codec.oid,
+ *             has_core_codec(self.oid))
+ */
+  __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->oid); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 331, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+
+  /* "asyncpg/protocol/codecs/base.pyx":332
+ *         return '<Codec oid={} elem_oid={} core={}>'.format(
+ *             self.oid,
+ *             'NA' if self.element_codec is None else self.element_codec.oid,             # <<<<<<<<<<<<<<
+ *             has_core_codec(self.oid))
+ * 
+ */
+  __pyx_t_5 = (((PyObject *)__pyx_v_self->element_codec) == Py_None);
+  if ((__pyx_t_5 != 0)) {
+    __Pyx_INCREF(__pyx_n_u_NA);
+    __pyx_t_4 = __pyx_n_u_NA;
+  } else {
+    __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->element_codec->oid); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 332, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_4 = __pyx_t_6;
+    __pyx_t_6 = 0;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":333
+ *             self.oid,
+ *             'NA' if self.element_codec is None else self.element_codec.oid,
+ *             has_core_codec(self.oid))             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_f_7asyncpg_8protocol_8protocol_has_core_codec(__pyx_v_self->oid)); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 333, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = NULL;
+  __pyx_t_8 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+      __pyx_t_8 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_t_3, __pyx_t_4, __pyx_t_6};
+    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 330, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_t_3, __pyx_t_4, __pyx_t_6};
+    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 330, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_9 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 330, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    if (__pyx_t_7) {
+      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_t_6);
+    __pyx_t_3 = 0;
+    __pyx_t_4 = 0;
+    __pyx_t_6 = 0;
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 330, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":329
+ *         return self.format == PG_FORMAT_BINARY
+ * 
+ *     def __repr__(self):             # <<<<<<<<<<<<<<
+ *         return '<Codec oid={} elem_oid={} core={}>'.format(
+ *             self.oid,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":336
+ * 
+ *     @staticmethod
+ *     cdef Codec new_array_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                str name,
+ *                                str schema,
+ */
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_array_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_element_codec, Py_UCS4 __pyx_v_element_delimiter) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("new_array_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":342
+ *                                Py_UCS4 element_delimiter):
+ *         cdef Codec codec
+ *         codec = Codec(oid)             # <<<<<<<<<<<<<<
+ *         codec.init(name, schema, 'array', CODEC_ARRAY, element_codec.format,
+ *                    PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 342, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 342, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":343
+ *         cdef Codec codec
+ *         codec = Codec(oid)
+ *         codec.init(name, schema, 'array', CODEC_ARRAY, element_codec.format,             # <<<<<<<<<<<<<<
+ *                    PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+ *                    None, None, None, element_delimiter)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, __pyx_v_name, __pyx_v_schema, __pyx_n_u_array, __pyx_e_7asyncpg_8protocol_8protocol_CODEC_ARRAY, __pyx_v_element_codec->format, __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT, NULL, NULL, Py_None, Py_None, __pyx_v_element_codec, ((PyObject*)Py_None), Py_None, ((PyObject*)Py_None), __pyx_v_element_delimiter); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 343, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":346
+ *                    PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+ *                    None, None, None, element_delimiter)
+ *         return codec             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = __pyx_v_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":336
+ * 
+ *     @staticmethod
+ *     cdef Codec new_array_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                str name,
+ *                                str schema,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.new_array_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":349
+ * 
+ *     @staticmethod
+ *     cdef Codec new_range_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                str name,
+ *                                str schema,
+ */
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_range_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_element_codec) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("new_range_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":354
+ *                                Codec element_codec):
+ *         cdef Codec codec
+ *         codec = Codec(oid)             # <<<<<<<<<<<<<<
+ *         codec.init(name, schema, 'range', CODEC_RANGE, element_codec.format,
+ *                    PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 354, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 354, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":355
+ *         cdef Codec codec
+ *         codec = Codec(oid)
+ *         codec.init(name, schema, 'range', CODEC_RANGE, element_codec.format,             # <<<<<<<<<<<<<<
+ *                    PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+ *                    None, None, None, 0)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, __pyx_v_name, __pyx_v_schema, __pyx_n_u_range, __pyx_e_7asyncpg_8protocol_8protocol_CODEC_RANGE, __pyx_v_element_codec->format, __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT, NULL, NULL, Py_None, Py_None, __pyx_v_element_codec, ((PyObject*)Py_None), Py_None, ((PyObject*)Py_None), 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 355, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":358
+ *                    PG_XFORMAT_OBJECT, NULL, NULL, None, None, element_codec,
+ *                    None, None, None, 0)
+ *         return codec             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = __pyx_v_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":349
+ * 
+ *     @staticmethod
+ *     cdef Codec new_range_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                str name,
+ *                                str schema,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.new_range_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":361
+ * 
+ *     @staticmethod
+ *     cdef Codec new_composite_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                    str name,
+ *                                    str schema,
+ */
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_composite_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, PyObject *__pyx_v_element_codecs, PyObject *__pyx_v_element_type_oids, PyObject *__pyx_v_element_names) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("new_composite_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":369
+ *                                    object element_names):
+ *         cdef Codec codec
+ *         codec = Codec(oid)             # <<<<<<<<<<<<<<
+ *         codec.init(name, schema, 'composite', CODEC_COMPOSITE,
+ *                    format, PG_XFORMAT_OBJECT, NULL, NULL, None, None, None,
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 369, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 369, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":370
+ *         cdef Codec codec
+ *         codec = Codec(oid)
+ *         codec.init(name, schema, 'composite', CODEC_COMPOSITE,             # <<<<<<<<<<<<<<
+ *                    format, PG_XFORMAT_OBJECT, NULL, NULL, None, None, None,
+ *                    element_type_oids, element_names, element_codecs, 0)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, __pyx_v_name, __pyx_v_schema, __pyx_n_u_composite, __pyx_e_7asyncpg_8protocol_8protocol_CODEC_COMPOSITE, __pyx_v_format, __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT, NULL, NULL, Py_None, Py_None, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None), __pyx_v_element_type_oids, __pyx_v_element_names, __pyx_v_element_codecs, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 370, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":373
+ *                    format, PG_XFORMAT_OBJECT, NULL, NULL, None, None, None,
+ *                    element_type_oids, element_names, element_codecs, 0)
+ *         return codec             # <<<<<<<<<<<<<<
+ * 
+ *     @staticmethod
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = __pyx_v_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":361
+ * 
+ *     @staticmethod
+ *     cdef Codec new_composite_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                    str name,
+ *                                    str schema,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.new_composite_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":376
+ * 
+ *     @staticmethod
+ *     cdef Codec new_python_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                 str name,
+ *                                 str schema,
+ */
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_python_codec(uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema, PyObject *__pyx_v_kind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_c_encoder, __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_c_decoder, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("new_python_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":387
+ *                                 ClientExchangeFormat xformat):
+ *         cdef Codec codec
+ *         codec = Codec(oid)             # <<<<<<<<<<<<<<
+ *         codec.init(name, schema, kind, CODEC_PY, format, xformat,
+ *                    c_encoder, c_decoder, encoder, decoder,
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 387, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 387, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":388
+ *         cdef Codec codec
+ *         codec = Codec(oid)
+ *         codec.init(name, schema, kind, CODEC_PY, format, xformat,             # <<<<<<<<<<<<<<
+ *                    c_encoder, c_decoder, encoder, decoder,
+ *                    None, None, None, None, 0)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, __pyx_v_name, __pyx_v_schema, __pyx_v_kind, __pyx_e_7asyncpg_8protocol_8protocol_CODEC_PY, __pyx_v_format, __pyx_v_xformat, __pyx_v_c_encoder, __pyx_v_c_decoder, __pyx_v_encoder, __pyx_v_decoder, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None), ((PyObject*)Py_None), Py_None, ((PyObject*)Py_None), 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 388, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":391
+ *                    c_encoder, c_decoder, encoder, decoder,
+ *                    None, None, None, None, 0)
+ *         return codec             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = __pyx_v_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":376
+ * 
+ *     @staticmethod
+ *     cdef Codec new_python_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                 str name,
+ *                                 str schema,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.new_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Codec_4__reduce_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Codec_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 2, __pyx_L1_error)
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Codec_6__setstate_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Codec_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 4, __pyx_L1_error)
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Codec.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":395
+ * 
+ * # Encode callback for arrays
+ * cdef codec_encode_func_ex(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                           object obj, const void *arg):
+ *     return (<Codec>arg).encode(settings, buf, obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_codec_encode_func_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj, void const *__pyx_v_arg) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("codec_encode_func_ex", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":397
+ * cdef codec_encode_func_ex(ConnectionSettings settings, WriteBuffer buf,
+ *                           object obj, const void *arg):
+ *     return (<Codec>arg).encode(settings, buf, obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_arg), __pyx_v_settings, __pyx_v_buf, __pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 397, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":395
+ * 
+ * # Encode callback for arrays
+ * cdef codec_encode_func_ex(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                           object obj, const void *arg):
+ *     return (<Codec>arg).encode(settings, buf, obj)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.codec_encode_func_ex", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":401
+ * 
+ * # Decode callback for arrays
+ * cdef codec_decode_func_ex(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                           const void *arg):
+ *     return (<Codec>arg).decode(settings, buf)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_codec_decode_func_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, void const *__pyx_v_arg) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("codec_decode_func_ex", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":403
+ * cdef codec_decode_func_ex(ConnectionSettings settings, FRBuffer *buf,
+ *                           const void *arg):
+ *     return (<Codec>arg).decode(settings, buf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_arg), __pyx_v_settings, __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 403, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":401
+ * 
+ * # Decode callback for arrays
+ * cdef codec_decode_func_ex(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                           const void *arg):
+ *     return (<Codec>arg).decode(settings, buf)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.codec_decode_func_ex", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":406
+ * 
+ * 
+ * cdef uint32_t pylong_as_oid(val) except? 0xFFFFFFFFl:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t oid = 0
+ */
+
+static uint32_t __pyx_f_7asyncpg_8protocol_8protocol_pylong_as_oid(PyObject *__pyx_v_val) {
+  int64_t __pyx_v_oid;
+  int __pyx_v_overflow;
+  uint32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PY_LONG_LONG __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  uint32_t __pyx_t_11;
+  __Pyx_RefNannySetupContext("pylong_as_oid", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":408
+ * cdef uint32_t pylong_as_oid(val) except? 0xFFFFFFFFl:
+ *     cdef:
+ *         int64_t oid = 0             # <<<<<<<<<<<<<<
+ *         bint overflow = False
+ * 
+ */
+  __pyx_v_oid = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":409
+ *     cdef:
+ *         int64_t oid = 0
+ *         bint overflow = False             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+  __pyx_v_overflow = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":411
+ *         bint overflow = False
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         oid = cpython.PyLong_AsLongLong(val)
+ *     except OverflowError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_1);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    /*try:*/ {
+
+      /* "asyncpg/protocol/codecs/base.pyx":412
+ * 
+ *     try:
+ *         oid = cpython.PyLong_AsLongLong(val)             # <<<<<<<<<<<<<<
+ *     except OverflowError:
+ *         overflow = True
+ */
+      __pyx_t_4 = PyLong_AsLongLong(__pyx_v_val); if (unlikely(__pyx_t_4 == ((PY_LONG_LONG)-1LL) && PyErr_Occurred())) __PYX_ERR(3, 412, __pyx_L3_error)
+      __pyx_v_oid = __pyx_t_4;
+
+      /* "asyncpg/protocol/codecs/base.pyx":411
+ *         bint overflow = False
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         oid = cpython.PyLong_AsLongLong(val)
+ *     except OverflowError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":413
+ *     try:
+ *         oid = cpython.PyLong_AsLongLong(val)
+ *     except OverflowError:             # <<<<<<<<<<<<<<
+ *         overflow = True
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
+    if (__pyx_t_5) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.pylong_as_oid", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(3, 413, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_8);
+
+      /* "asyncpg/protocol/codecs/base.pyx":414
+ *         oid = cpython.PyLong_AsLongLong(val)
+ *     except OverflowError:
+ *         overflow = True             # <<<<<<<<<<<<<<
+ * 
+ *     if overflow or (oid < 0 or oid > UINT32_MAX):
+ */
+      __pyx_v_overflow = 1;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":411
+ *         bint overflow = False
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         oid = cpython.PyLong_AsLongLong(val)
+ *     except OverflowError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":416
+ *         overflow = True
+ * 
+ *     if overflow or (oid < 0 or oid > UINT32_MAX):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('OID value too large: {!r}'.format(val))
+ * 
+ */
+  __pyx_t_10 = (__pyx_v_overflow != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_oid < 0) != 0);
+  if (!__pyx_t_10) {
+  } else {
+    __pyx_t_9 = __pyx_t_10;
+    goto __pyx_L12_bool_binop_done;
+  }
+  __pyx_t_10 = ((__pyx_v_oid > UINT32_MAX) != 0);
+  __pyx_t_9 = __pyx_t_10;
+  __pyx_L12_bool_binop_done:;
+  if (unlikely(__pyx_t_9)) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":417
+ * 
+ *     if overflow or (oid < 0 or oid > UINT32_MAX):
+ *         raise OverflowError('OID value too large: {!r}'.format(val))             # <<<<<<<<<<<<<<
+ * 
+ *     return <uint32_t>val
+ */
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_OID_value_too_large_r, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 417, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+      }
+    }
+    __pyx_t_8 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_v_val) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_val);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 417, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OverflowError, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 417, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_Raise(__pyx_t_7, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __PYX_ERR(3, 417, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":416
+ *         overflow = True
+ * 
+ *     if overflow or (oid < 0 or oid > UINT32_MAX):             # <<<<<<<<<<<<<<
+ *         raise OverflowError('OID value too large: {!r}'.format(val))
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":419
+ *         raise OverflowError('OID value too large: {!r}'.format(val))
+ * 
+ *     return <uint32_t>val             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_11 = __Pyx_PyInt_As_uint32_t(__pyx_v_val); if (unlikely((__pyx_t_11 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 419, __pyx_L1_error)
+  __pyx_r = ((uint32_t)__pyx_t_11);
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":406
+ * 
+ * 
+ * cdef uint32_t pylong_as_oid(val) except? 0xFFFFFFFFl:             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         int64_t oid = 0
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.pylong_as_oid", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0xFFFFFFFFL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":423
+ * 
+ * cdef class DataCodecConfig:
+ *     def __init__(self, cache_key):             # <<<<<<<<<<<<<<
+ *         # Codec instance cache for derived types:
+ *         # composites, arrays, ranges, domains and their combinations.
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  CYTHON_UNUSED PyObject *__pyx_v_cache_key = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_cache_key,0};
+    PyObject* values[1] = {0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cache_key)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(3, 423, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+    }
+    __pyx_v_cache_key = values[0];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 423, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig___init__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), __pyx_v_cache_key);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig___init__(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_cache_key) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__init__", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":426
+ *         # Codec instance cache for derived types:
+ *         # composites, arrays, ranges, domains and their combinations.
+ *         self._derived_type_codecs = {}             # <<<<<<<<<<<<<<
+ *         # Codec instances set up by the user for the connection.
+ *         self._custom_type_codecs = {}
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 426, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_derived_type_codecs);
+  __Pyx_DECREF(__pyx_v_self->_derived_type_codecs);
+  __pyx_v_self->_derived_type_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":428
+ *         self._derived_type_codecs = {}
+ *         # Codec instances set up by the user for the connection.
+ *         self._custom_type_codecs = {}             # <<<<<<<<<<<<<<
+ * 
+ *     def add_types(self, types):
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 428, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->_custom_type_codecs);
+  __Pyx_DECREF(__pyx_v_self->_custom_type_codecs);
+  __pyx_v_self->_custom_type_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":423
+ * 
+ * cdef class DataCodecConfig:
+ *     def __init__(self, cache_key):             # <<<<<<<<<<<<<<
+ *         # Codec instance cache for derived types:
+ *         # composites, arrays, ranges, domains and their combinations.
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":430
+ *         self._custom_type_codecs = {}
+ * 
+ *     def add_types(self, types):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec elem_codec
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_3add_types(PyObject *__pyx_v_self, PyObject *__pyx_v_types); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_3add_types(PyObject *__pyx_v_self, PyObject *__pyx_v_types) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("add_types (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_2add_types(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), ((PyObject *)__pyx_v_types));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_2add_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_types) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_elem_codec = 0;
+  PyObject *__pyx_v_comp_elem_codecs = 0;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_elem_format;
+  int __pyx_v_has_text_elements;
+  Py_UCS4 __pyx_v_elem_delim;
+  PyObject *__pyx_v_ti = NULL;
+  PyObject *__pyx_v_oid = NULL;
+  PyObject *__pyx_v_name = NULL;
+  PyObject *__pyx_v_schema = NULL;
+  PyObject *__pyx_v_array_element_oid = NULL;
+  PyObject *__pyx_v_range_subtype_oid = NULL;
+  PyObject *__pyx_v_comp_type_attrs = NULL;
+  PyObject *__pyx_v_base_type = NULL;
+  PyObject *__pyx_v_typoid = NULL;
+  PyObject *__pyx_v_element_names = NULL;
+  PyObject *__pyx_v_i = NULL;
+  PyObject *__pyx_v_attrname = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *(*__pyx_t_3)(PyObject *);
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  int __pyx_t_6;
+  uint32_t __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  Py_UCS4 __pyx_t_12;
+  PyObject *__pyx_t_13 = NULL;
+  Py_ssize_t __pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  int __pyx_t_16;
+  PyObject *(*__pyx_t_17)(PyObject *);
+  __Pyx_RefNannySetupContext("add_types", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":439
+ *             Py_UCS4 elem_delim
+ * 
+ *         for ti in types:             # <<<<<<<<<<<<<<
+ *             oid = ti['oid']
+ * 
+ */
+  if (likely(PyList_CheckExact(__pyx_v_types)) || PyTuple_CheckExact(__pyx_v_types)) {
+    __pyx_t_1 = __pyx_v_types; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+    __pyx_t_3 = NULL;
+  } else {
+    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 439, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 439, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_3)) {
+      if (likely(PyList_CheckExact(__pyx_t_1))) {
+        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(3, 439, __pyx_L1_error)
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 439, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      } else {
+        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(3, 439, __pyx_L1_error)
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 439, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      }
+    } else {
+      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
+      if (unlikely(!__pyx_t_4)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(3, 439, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_4);
+    }
+    __Pyx_XDECREF_SET(__pyx_v_ti, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":440
+ * 
+ *         for ti in types:
+ *             oid = ti['oid']             # <<<<<<<<<<<<<<
+ * 
+ *             if not ti['has_bin_io']:
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_oid); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 440, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_XDECREF_SET(__pyx_v_oid, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":442
+ *             oid = ti['oid']
+ * 
+ *             if not ti['has_bin_io']:             # <<<<<<<<<<<<<<
+ *                 format = PG_FORMAT_TEXT
+ *             else:
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_has_bin_io); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 442, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 442, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_6 = ((!__pyx_t_5) != 0);
+    if (__pyx_t_6) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":443
+ * 
+ *             if not ti['has_bin_io']:
+ *                 format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ *             else:
+ *                 format = PG_FORMAT_BINARY
+ */
+      __pyx_v_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+      /* "asyncpg/protocol/codecs/base.pyx":442
+ *             oid = ti['oid']
+ * 
+ *             if not ti['has_bin_io']:             # <<<<<<<<<<<<<<
+ *                 format = PG_FORMAT_TEXT
+ *             else:
+ */
+      goto __pyx_L5;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":445
+ *                 format = PG_FORMAT_TEXT
+ *             else:
+ *                 format = PG_FORMAT_BINARY             # <<<<<<<<<<<<<<
+ * 
+ *             has_text_elements = False
+ */
+    /*else*/ {
+      __pyx_v_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY;
+    }
+    __pyx_L5:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":447
+ *                 format = PG_FORMAT_BINARY
+ * 
+ *             has_text_elements = False             # <<<<<<<<<<<<<<
+ * 
+ *             if self.get_codec(oid, format) is not None:
+ */
+    __pyx_v_has_text_elements = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":449
+ *             has_text_elements = False
+ * 
+ *             if self.get_codec(oid, format) is not None:             # <<<<<<<<<<<<<<
+ *                 continue
+ * 
+ */
+    __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 449, __pyx_L1_error)
+    __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_t_7, __pyx_v_format)); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 449, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_6 = (__pyx_t_4 != Py_None);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_5 = (__pyx_t_6 != 0);
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":450
+ * 
+ *             if self.get_codec(oid, format) is not None:
+ *                 continue             # <<<<<<<<<<<<<<
+ * 
+ *             name = ti['name']
+ */
+      goto __pyx_L3_continue;
+
+      /* "asyncpg/protocol/codecs/base.pyx":449
+ *             has_text_elements = False
+ * 
+ *             if self.get_codec(oid, format) is not None:             # <<<<<<<<<<<<<<
+ *                 continue
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":452
+ *                 continue
+ * 
+ *             name = ti['name']             # <<<<<<<<<<<<<<
+ *             schema = ti['ns']
+ *             array_element_oid = ti['elemtype']
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 452, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":453
+ * 
+ *             name = ti['name']
+ *             schema = ti['ns']             # <<<<<<<<<<<<<<
+ *             array_element_oid = ti['elemtype']
+ *             range_subtype_oid = ti['range_subtype']
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_ns); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 453, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_XDECREF_SET(__pyx_v_schema, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":454
+ *             name = ti['name']
+ *             schema = ti['ns']
+ *             array_element_oid = ti['elemtype']             # <<<<<<<<<<<<<<
+ *             range_subtype_oid = ti['range_subtype']
+ *             if ti['attrtypoids']:
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_elemtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 454, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_XDECREF_SET(__pyx_v_array_element_oid, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":455
+ *             schema = ti['ns']
+ *             array_element_oid = ti['elemtype']
+ *             range_subtype_oid = ti['range_subtype']             # <<<<<<<<<<<<<<
+ *             if ti['attrtypoids']:
+ *                 comp_type_attrs = tuple(ti['attrtypoids'])
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_range_subtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 455, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_XDECREF_SET(__pyx_v_range_subtype_oid, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":456
+ *             array_element_oid = ti['elemtype']
+ *             range_subtype_oid = ti['range_subtype']
+ *             if ti['attrtypoids']:             # <<<<<<<<<<<<<<
+ *                 comp_type_attrs = tuple(ti['attrtypoids'])
+ *             else:
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_attrtypoids); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 456, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 456, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":457
+ *             range_subtype_oid = ti['range_subtype']
+ *             if ti['attrtypoids']:
+ *                 comp_type_attrs = tuple(ti['attrtypoids'])             # <<<<<<<<<<<<<<
+ *             else:
+ *                 comp_type_attrs = None
+ */
+      __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_attrtypoids); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 457, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_8 = __Pyx_PySequence_Tuple(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 457, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_comp_type_attrs, ((PyObject*)__pyx_t_8));
+      __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":456
+ *             array_element_oid = ti['elemtype']
+ *             range_subtype_oid = ti['range_subtype']
+ *             if ti['attrtypoids']:             # <<<<<<<<<<<<<<
+ *                 comp_type_attrs = tuple(ti['attrtypoids'])
+ *             else:
+ */
+      goto __pyx_L7;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":459
+ *                 comp_type_attrs = tuple(ti['attrtypoids'])
+ *             else:
+ *                 comp_type_attrs = None             # <<<<<<<<<<<<<<
+ *             base_type = ti['basetype']
+ * 
+ */
+    /*else*/ {
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_comp_type_attrs, ((PyObject*)Py_None));
+    }
+    __pyx_L7:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":460
+ *             else:
+ *                 comp_type_attrs = None
+ *             base_type = ti['basetype']             # <<<<<<<<<<<<<<
+ * 
+ *             if array_element_oid:
+ */
+    __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_basetype); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 460, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_XDECREF_SET(__pyx_v_base_type, __pyx_t_8);
+    __pyx_t_8 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":462
+ *             base_type = ti['basetype']
+ * 
+ *             if array_element_oid:             # <<<<<<<<<<<<<<
+ *                 # Array type (note, there is no separate 'kind' for arrays)
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_array_element_oid); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 462, __pyx_L1_error)
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":466
+ * 
+ *                 # Canonicalize type name to "elemtype[]"
+ *                 if name.startswith('_'):             # <<<<<<<<<<<<<<
+ *                     name = name[1:]
+ *                 name = '{}[]'.format(name)
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_name, __pyx_n_s_startswith); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 466, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_9 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_9)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_9);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_9, __pyx_n_u__2) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_u__2);
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 466, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 466, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":467
+ *                 # Canonicalize type name to "elemtype[]"
+ *                 if name.startswith('_'):
+ *                     name = name[1:]             # <<<<<<<<<<<<<<
+ *                 name = '{}[]'.format(name)
+ * 
+ */
+        __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_name, 1, 0, NULL, NULL, &__pyx_slice__8, 1, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 467, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF_SET(__pyx_v_name, __pyx_t_8);
+        __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":466
+ * 
+ *                 # Canonicalize type name to "elemtype[]"
+ *                 if name.startswith('_'):             # <<<<<<<<<<<<<<
+ *                     name = name[1:]
+ *                 name = '{}[]'.format(name)
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":468
+ *                 if name.startswith('_'):
+ *                     name = name[1:]
+ *                 name = '{}[]'.format(name)             # <<<<<<<<<<<<<<
+ * 
+ *                 if ti['elem_has_bin_io']:
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u__9, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 468, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_9 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_9)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_9);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_9, __pyx_v_name) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_name);
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 468, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF_SET(__pyx_v_name, __pyx_t_8);
+      __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":470
+ *                 name = '{}[]'.format(name)
+ * 
+ *                 if ti['elem_has_bin_io']:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_BINARY
+ *                 else:
+ */
+      __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_elem_has_bin_io); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 470, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 470, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":471
+ * 
+ *                 if ti['elem_has_bin_io']:
+ *                     elem_format = PG_FORMAT_BINARY             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     elem_format = PG_FORMAT_TEXT
+ */
+        __pyx_v_elem_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY;
+
+        /* "asyncpg/protocol/codecs/base.pyx":470
+ *                 name = '{}[]'.format(name)
+ * 
+ *                 if ti['elem_has_bin_io']:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_BINARY
+ *                 else:
+ */
+        goto __pyx_L10;
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":473
+ *                     elem_format = PG_FORMAT_BINARY
+ *                 else:
+ *                     elem_format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ * 
+ *                 elem_codec = self.get_codec(array_element_oid, elem_format)
+ */
+      /*else*/ {
+        __pyx_v_elem_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+      }
+      __pyx_L10:;
+
+      /* "asyncpg/protocol/codecs/base.pyx":475
+ *                     elem_format = PG_FORMAT_TEXT
+ * 
+ *                 elem_codec = self.get_codec(array_element_oid, elem_format)             # <<<<<<<<<<<<<<
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT
+ */
+      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_array_element_oid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 475, __pyx_L1_error)
+      __pyx_t_8 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_t_7, __pyx_v_elem_format)); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 475, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_8));
+      __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":476
+ * 
+ *                 elem_codec = self.get_codec(array_element_oid, elem_format)
+ *                 if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ */
+      __pyx_t_5 = (((PyObject *)__pyx_v_elem_codec) == Py_None);
+      __pyx_t_6 = (__pyx_t_5 != 0);
+      if (__pyx_t_6) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":477
+ *                 elem_codec = self.get_codec(array_element_oid, elem_format)
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ *                     elem_codec = self.declare_fallback_codec(
+ *                         array_element_oid, name, schema)
+ */
+        __pyx_v_elem_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+        /* "asyncpg/protocol/codecs/base.pyx":478
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(             # <<<<<<<<<<<<<<
+ *                         array_element_oid, name, schema)
+ * 
+ */
+        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_declare_fallback_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 478, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+
+        /* "asyncpg/protocol/codecs/base.pyx":479
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ *                         array_element_oid, name, schema)             # <<<<<<<<<<<<<<
+ * 
+ *                 elem_delim = <Py_UCS4>ti['elemdelim'][0]
+ */
+        __pyx_t_9 = NULL;
+        __pyx_t_10 = 0;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4);
+          if (likely(__pyx_t_9)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+            __Pyx_INCREF(__pyx_t_9);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_4, function);
+            __pyx_t_10 = 1;
+          }
+        }
+        #if CYTHON_FAST_PYCALL
+        if (PyFunction_Check(__pyx_t_4)) {
+          PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_array_element_oid, __pyx_v_name, __pyx_v_schema};
+          __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 478, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_GOTREF(__pyx_t_8);
+        } else
+        #endif
+        #if CYTHON_FAST_PYCCALL
+        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+          PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_array_element_oid, __pyx_v_name, __pyx_v_schema};
+          __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 478, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_GOTREF(__pyx_t_8);
+        } else
+        #endif
+        {
+          __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 478, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          if (__pyx_t_9) {
+            __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+          }
+          __Pyx_INCREF(__pyx_v_array_element_oid);
+          __Pyx_GIVEREF(__pyx_v_array_element_oid);
+          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_array_element_oid);
+          __Pyx_INCREF(__pyx_v_name);
+          __Pyx_GIVEREF(__pyx_v_name);
+          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_name);
+          __Pyx_INCREF(__pyx_v_schema);
+          __Pyx_GIVEREF(__pyx_v_schema);
+          PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_v_schema);
+          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 478, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_8);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        }
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":478
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(             # <<<<<<<<<<<<<<
+ *                         array_element_oid, name, schema)
+ * 
+ */
+        if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 478, __pyx_L1_error)
+        __Pyx_DECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_8));
+        __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":476
+ * 
+ *                 elem_codec = self.get_codec(array_element_oid, elem_format)
+ *                 if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":481
+ *                         array_element_oid, name, schema)
+ * 
+ *                 elem_delim = <Py_UCS4>ti['elemdelim'][0]             # <<<<<<<<<<<<<<
+ * 
+ *                 self._derived_type_codecs[oid, elem_format] = \
+ */
+      __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_elemdelim); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 481, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 481, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __pyx_t_12 = __Pyx_PyObject_AsPy_UCS4(__pyx_t_4); if (unlikely((__pyx_t_12 == (Py_UCS4)-1) && PyErr_Occurred())) __PYX_ERR(3, 481, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_v_elem_delim = ((Py_UCS4)__pyx_t_12);
+
+      /* "asyncpg/protocol/codecs/base.pyx":485
+ *                 self._derived_type_codecs[oid, elem_format] = \
+ *                     Codec.new_array_codec(
+ *                         oid, name, schema, elem_codec, elem_delim)             # <<<<<<<<<<<<<<
+ * 
+ *             elif ti['kind'] == b'c':
+ */
+      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 485, __pyx_L1_error)
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_name))||((__pyx_v_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_name)->tp_name), 0))) __PYX_ERR(3, 485, __pyx_L1_error)
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_schema))||((__pyx_v_schema) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_schema)->tp_name), 0))) __PYX_ERR(3, 485, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":484
+ * 
+ *                 self._derived_type_codecs[oid, elem_format] = \
+ *                     Codec.new_array_codec(             # <<<<<<<<<<<<<<
+ *                         oid, name, schema, elem_codec, elem_delim)
+ * 
+ */
+      __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_array_codec(__pyx_t_7, ((PyObject*)__pyx_v_name), ((PyObject*)__pyx_v_schema), __pyx_v_elem_codec, __pyx_v_elem_delim)); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 484, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+
+      /* "asyncpg/protocol/codecs/base.pyx":483
+ *                 elem_delim = <Py_UCS4>ti['elemdelim'][0]
+ * 
+ *                 self._derived_type_codecs[oid, elem_format] = \             # <<<<<<<<<<<<<<
+ *                     Codec.new_array_codec(
+ *                         oid, name, schema, elem_codec, elem_delim)
+ */
+      if (unlikely(__pyx_v_self->_derived_type_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(3, 483, __pyx_L1_error)
+      }
+      __pyx_t_8 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_elem_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 483, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 483, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __Pyx_INCREF(__pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_v_oid);
+      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_8);
+      __pyx_t_8 = 0;
+      if (unlikely(PyDict_SetItem(__pyx_v_self->_derived_type_codecs, __pyx_t_11, __pyx_t_4) < 0)) __PYX_ERR(3, 483, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":462
+ *             base_type = ti['basetype']
+ * 
+ *             if array_element_oid:             # <<<<<<<<<<<<<<
+ *                 # Array type (note, there is no separate 'kind' for arrays)
+ * 
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":487
+ *                         oid, name, schema, elem_codec, elem_delim)
+ * 
+ *             elif ti['kind'] == b'c':             # <<<<<<<<<<<<<<
+ *                 if not comp_type_attrs:
+ *                     raise exceptions.InternalClientError(
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_kind); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 487, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_c, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(3, 487, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (__pyx_t_6) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":488
+ * 
+ *             elif ti['kind'] == b'c':
+ *                 if not comp_type_attrs:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing field types for '
+ */
+      __pyx_t_6 = (__pyx_v_comp_type_attrs != Py_None)&&(PyTuple_GET_SIZE(__pyx_v_comp_type_attrs) != 0);
+      __pyx_t_5 = ((!__pyx_t_6) != 0);
+      if (unlikely(__pyx_t_5)) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":489
+ *             elif ti['kind'] == b'c':
+ *                 if not comp_type_attrs:
+ *                     raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                         'type record missing field types for '
+ *                         'composite {}'.format(oid))
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 489, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 489, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":491
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing field types for '
+ *                         'composite {}'.format(oid))             # <<<<<<<<<<<<<<
+ * 
+ *                 # Composite type
+ */
+        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_type_record_missing_field_types, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 491, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        __pyx_t_13 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_9);
+          if (likely(__pyx_t_13)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+            __Pyx_INCREF(__pyx_t_13);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_9, function);
+          }
+        }
+        __pyx_t_11 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_13, __pyx_v_oid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_oid);
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 491, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
+          if (likely(__pyx_t_9)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+            __Pyx_INCREF(__pyx_t_9);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_8, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_11);
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 489, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __PYX_ERR(3, 489, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/base.pyx":488
+ * 
+ *             elif ti['kind'] == b'c':
+ *                 if not comp_type_attrs:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing field types for '
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":495
+ *                 # Composite type
+ * 
+ *                 comp_elem_codecs = []             # <<<<<<<<<<<<<<
+ * 
+ *                 for typoid in comp_type_attrs:
+ */
+      __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 495, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_XDECREF_SET(__pyx_v_comp_elem_codecs, ((PyObject*)__pyx_t_4));
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":497
+ *                 comp_elem_codecs = []
+ * 
+ *                 for typoid in comp_type_attrs:             # <<<<<<<<<<<<<<
+ *                     elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)
+ *                     if elem_codec is None:
+ */
+      if (unlikely(__pyx_v_comp_type_attrs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+        __PYX_ERR(3, 497, __pyx_L1_error)
+      }
+      __pyx_t_4 = __pyx_v_comp_type_attrs; __Pyx_INCREF(__pyx_t_4); __pyx_t_14 = 0;
+      for (;;) {
+        if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_14); __Pyx_INCREF(__pyx_t_8); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(3, 497, __pyx_L1_error)
+        #else
+        __pyx_t_8 = PySequence_ITEM(__pyx_t_4, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 497, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        #endif
+        __Pyx_XDECREF_SET(__pyx_v_typoid, __pyx_t_8);
+        __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":498
+ * 
+ *                 for typoid in comp_type_attrs:
+ *                     elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)             # <<<<<<<<<<<<<<
+ *                     if elem_codec is None:
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+ */
+        __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_typoid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 498, __pyx_L1_error)
+        __pyx_t_8 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_t_7, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY)); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 498, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_8));
+        __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":499
+ *                 for typoid in comp_type_attrs:
+ *                     elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)
+ *                     if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+ *                         has_text_elements = True
+ */
+        __pyx_t_5 = (((PyObject *)__pyx_v_elem_codec) == Py_None);
+        __pyx_t_6 = (__pyx_t_5 != 0);
+        if (__pyx_t_6) {
+
+          /* "asyncpg/protocol/codecs/base.pyx":500
+ *                     elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)
+ *                     if elem_codec is None:
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ *                         has_text_elements = True
+ *                     if elem_codec is None:
+ */
+          __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_typoid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 500, __pyx_L1_error)
+          __pyx_t_8 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_t_7, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT)); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 500, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_8);
+          __Pyx_DECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_8));
+          __pyx_t_8 = 0;
+
+          /* "asyncpg/protocol/codecs/base.pyx":501
+ *                     if elem_codec is None:
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+ *                         has_text_elements = True             # <<<<<<<<<<<<<<
+ *                     if elem_codec is None:
+ *                         raise exceptions.InternalClientError(
+ */
+          __pyx_v_has_text_elements = 1;
+
+          /* "asyncpg/protocol/codecs/base.pyx":499
+ *                 for typoid in comp_type_attrs:
+ *                     elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)
+ *                     if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+ *                         has_text_elements = True
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/base.pyx":502
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+ *                         has_text_elements = True
+ *                     if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                         raise exceptions.InternalClientError(
+ *                             'no codec for composite attribute type {}'.format(
+ */
+        __pyx_t_6 = (((PyObject *)__pyx_v_elem_codec) == Py_None);
+        __pyx_t_5 = (__pyx_t_6 != 0);
+        if (unlikely(__pyx_t_5)) {
+
+          /* "asyncpg/protocol/codecs/base.pyx":503
+ *                         has_text_elements = True
+ *                     if elem_codec is None:
+ *                         raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                             'no codec for composite attribute type {}'.format(
+ *                                 typoid))
+ */
+          __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 503, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 503, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+          /* "asyncpg/protocol/codecs/base.pyx":504
+ *                     if elem_codec is None:
+ *                         raise exceptions.InternalClientError(
+ *                             'no codec for composite attribute type {}'.format(             # <<<<<<<<<<<<<<
+ *                                 typoid))
+ *                     comp_elem_codecs.append(elem_codec)
+ */
+          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_no_codec_for_composite_attribute, __pyx_n_s_format); if (unlikely(!__pyx_t_13)) __PYX_ERR(3, 504, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_13);
+
+          /* "asyncpg/protocol/codecs/base.pyx":505
+ *                         raise exceptions.InternalClientError(
+ *                             'no codec for composite attribute type {}'.format(
+ *                                 typoid))             # <<<<<<<<<<<<<<
+ *                     comp_elem_codecs.append(elem_codec)
+ * 
+ */
+          __pyx_t_15 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
+            __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_13);
+            if (likely(__pyx_t_15)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
+              __Pyx_INCREF(__pyx_t_15);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_13, function);
+            }
+          }
+          __pyx_t_11 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_15, __pyx_v_typoid) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_typoid);
+          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+          if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 504, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __pyx_t_13 = NULL;
+          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
+            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_9);
+            if (likely(__pyx_t_13)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+              __Pyx_INCREF(__pyx_t_13);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_9, function);
+            }
+          }
+          __pyx_t_8 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_13, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_11);
+          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 503, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_8);
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+          __PYX_ERR(3, 503, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/base.pyx":502
+ *                         elem_codec = self.get_codec(typoid, PG_FORMAT_TEXT)
+ *                         has_text_elements = True
+ *                     if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                         raise exceptions.InternalClientError(
+ *                             'no codec for composite attribute type {}'.format(
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/base.pyx":506
+ *                             'no codec for composite attribute type {}'.format(
+ *                                 typoid))
+ *                     comp_elem_codecs.append(elem_codec)             # <<<<<<<<<<<<<<
+ * 
+ *                 element_names = collections.OrderedDict()
+ */
+        __pyx_t_16 = __Pyx_PyList_Append(__pyx_v_comp_elem_codecs, ((PyObject *)__pyx_v_elem_codec)); if (unlikely(__pyx_t_16 == ((int)-1))) __PYX_ERR(3, 506, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/base.pyx":497
+ *                 comp_elem_codecs = []
+ * 
+ *                 for typoid in comp_type_attrs:             # <<<<<<<<<<<<<<
+ *                     elem_codec = self.get_codec(typoid, PG_FORMAT_BINARY)
+ *                     if elem_codec is None:
+ */
+      }
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":508
+ *                     comp_elem_codecs.append(elem_codec)
+ * 
+ *                 element_names = collections.OrderedDict()             # <<<<<<<<<<<<<<
+ *                 for i, attrname in enumerate(ti['attrnames']):
+ *                     element_names[attrname] = i
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_collections); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 508, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 508, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __pyx_t_8 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_8)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_8);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 508, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_element_names, __pyx_t_4);
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":509
+ * 
+ *                 element_names = collections.OrderedDict()
+ *                 for i, attrname in enumerate(ti['attrnames']):             # <<<<<<<<<<<<<<
+ *                     element_names[attrname] = i
+ * 
+ */
+      __Pyx_INCREF(__pyx_int_0);
+      __pyx_t_4 = __pyx_int_0;
+      __pyx_t_9 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_attrnames); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 509, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
+        __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_14 = 0;
+        __pyx_t_17 = NULL;
+      } else {
+        __pyx_t_14 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 509, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __pyx_t_17 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_17)) __PYX_ERR(3, 509, __pyx_L1_error)
+      }
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      for (;;) {
+        if (likely(!__pyx_t_17)) {
+          if (likely(PyList_CheckExact(__pyx_t_8))) {
+            if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_8)) break;
+            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+            __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_9); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(3, 509, __pyx_L1_error)
+            #else
+            __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 509, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_9);
+            #endif
+          } else {
+            if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
+            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+            __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_9); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(3, 509, __pyx_L1_error)
+            #else
+            __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 509, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_9);
+            #endif
+          }
+        } else {
+          __pyx_t_9 = __pyx_t_17(__pyx_t_8);
+          if (unlikely(!__pyx_t_9)) {
+            PyObject* exc_type = PyErr_Occurred();
+            if (exc_type) {
+              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+              else __PYX_ERR(3, 509, __pyx_L1_error)
+            }
+            break;
+          }
+          __Pyx_GOTREF(__pyx_t_9);
+        }
+        __Pyx_XDECREF_SET(__pyx_v_attrname, __pyx_t_9);
+        __pyx_t_9 = 0;
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
+        __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 509, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_4);
+        __pyx_t_4 = __pyx_t_9;
+        __pyx_t_9 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":510
+ *                 element_names = collections.OrderedDict()
+ *                 for i, attrname in enumerate(ti['attrnames']):
+ *                     element_names[attrname] = i             # <<<<<<<<<<<<<<
+ * 
+ *                 if has_text_elements:
+ */
+        if (unlikely(PyObject_SetItem(__pyx_v_element_names, __pyx_v_attrname, __pyx_v_i) < 0)) __PYX_ERR(3, 510, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/base.pyx":509
+ * 
+ *                 element_names = collections.OrderedDict()
+ *                 for i, attrname in enumerate(ti['attrnames']):             # <<<<<<<<<<<<<<
+ *                     element_names[attrname] = i
+ * 
+ */
+      }
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":512
+ *                     element_names[attrname] = i
+ * 
+ *                 if has_text_elements:             # <<<<<<<<<<<<<<
+ *                     format = PG_FORMAT_TEXT
+ * 
+ */
+      __pyx_t_5 = (__pyx_v_has_text_elements != 0);
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":513
+ * 
+ *                 if has_text_elements:
+ *                     format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ * 
+ *                 self._derived_type_codecs[oid, format] = \
+ */
+        __pyx_v_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+        /* "asyncpg/protocol/codecs/base.pyx":512
+ *                     element_names[attrname] = i
+ * 
+ *                 if has_text_elements:             # <<<<<<<<<<<<<<
+ *                     format = PG_FORMAT_TEXT
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":517
+ *                 self._derived_type_codecs[oid, format] = \
+ *                     Codec.new_composite_codec(
+ *                         oid, name, schema, format, comp_elem_codecs,             # <<<<<<<<<<<<<<
+ *                         comp_type_attrs, element_names)
+ * 
+ */
+      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 517, __pyx_L1_error)
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_name))||((__pyx_v_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_name)->tp_name), 0))) __PYX_ERR(3, 517, __pyx_L1_error)
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_schema))||((__pyx_v_schema) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_schema)->tp_name), 0))) __PYX_ERR(3, 517, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/base.pyx":516
+ * 
+ *                 self._derived_type_codecs[oid, format] = \
+ *                     Codec.new_composite_codec(             # <<<<<<<<<<<<<<
+ *                         oid, name, schema, format, comp_elem_codecs,
+ *                         comp_type_attrs, element_names)
+ */
+      __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_composite_codec(__pyx_t_7, ((PyObject*)__pyx_v_name), ((PyObject*)__pyx_v_schema), __pyx_v_format, __pyx_v_comp_elem_codecs, __pyx_v_comp_type_attrs, __pyx_v_element_names)); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 516, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+
+      /* "asyncpg/protocol/codecs/base.pyx":515
+ *                     format = PG_FORMAT_TEXT
+ * 
+ *                 self._derived_type_codecs[oid, format] = \             # <<<<<<<<<<<<<<
+ *                     Codec.new_composite_codec(
+ *                         oid, name, schema, format, comp_elem_codecs,
+ */
+      if (unlikely(__pyx_v_self->_derived_type_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(3, 515, __pyx_L1_error)
+      }
+      __pyx_t_8 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 515, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 515, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __Pyx_INCREF(__pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_v_oid);
+      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
+      __pyx_t_8 = 0;
+      if (unlikely(PyDict_SetItem(__pyx_v_self->_derived_type_codecs, __pyx_t_9, __pyx_t_4) < 0)) __PYX_ERR(3, 515, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":487
+ *                         oid, name, schema, elem_codec, elem_delim)
+ * 
+ *             elif ti['kind'] == b'c':             # <<<<<<<<<<<<<<
+ *                 if not comp_type_attrs:
+ *                     raise exceptions.InternalClientError(
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":520
+ *                         comp_type_attrs, element_names)
+ * 
+ *             elif ti['kind'] == b'd':             # <<<<<<<<<<<<<<
+ *                 # Domain type
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_kind); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 520, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_d, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 520, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":523
+ *                 # Domain type
+ * 
+ *                 if not base_type:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for domain {}'.format(
+ */
+      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_base_type); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 523, __pyx_L1_error)
+      __pyx_t_6 = ((!__pyx_t_5) != 0);
+      if (unlikely(__pyx_t_6)) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":524
+ * 
+ *                 if not base_type:
+ *                     raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                         'type record missing base type for domain {}'.format(
+ *                             oid))
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 524, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 524, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":525
+ *                 if not base_type:
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for domain {}'.format(             # <<<<<<<<<<<<<<
+ *                             oid))
+ * 
+ */
+        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_type_record_missing_base_type_fo, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 525, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+
+        /* "asyncpg/protocol/codecs/base.pyx":526
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for domain {}'.format(
+ *                             oid))             # <<<<<<<<<<<<<<
+ * 
+ *                 elem_codec = self.get_codec(base_type, format)
+ */
+        __pyx_t_13 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11);
+          if (likely(__pyx_t_13)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+            __Pyx_INCREF(__pyx_t_13);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_11, function);
+          }
+        }
+        __pyx_t_9 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_v_oid) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_oid);
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 525, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __pyx_t_11 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8);
+          if (likely(__pyx_t_11)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+            __Pyx_INCREF(__pyx_t_11);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_8, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_11, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9);
+        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 524, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __PYX_ERR(3, 524, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/base.pyx":523
+ *                 # Domain type
+ * 
+ *                 if not base_type:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for domain {}'.format(
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":528
+ *                             oid))
+ * 
+ *                 elem_codec = self.get_codec(base_type, format)             # <<<<<<<<<<<<<<
+ *                 if elem_codec is None:
+ *                     format = PG_FORMAT_TEXT
+ */
+      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_base_type); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 528, __pyx_L1_error)
+      __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_t_7, __pyx_v_format)); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 528, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_4));
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":529
+ * 
+ *                 elem_codec = self.get_codec(base_type, format)
+ *                 if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                     format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ */
+      __pyx_t_6 = (((PyObject *)__pyx_v_elem_codec) == Py_None);
+      __pyx_t_5 = (__pyx_t_6 != 0);
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":530
+ *                 elem_codec = self.get_codec(base_type, format)
+ *                 if elem_codec is None:
+ *                     format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ *                     elem_codec = self.declare_fallback_codec(
+ *                         base_type, name, schema)
+ */
+        __pyx_v_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+        /* "asyncpg/protocol/codecs/base.pyx":531
+ *                 if elem_codec is None:
+ *                     format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(             # <<<<<<<<<<<<<<
+ *                         base_type, name, schema)
+ * 
+ */
+        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_declare_fallback_codec); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 531, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+
+        /* "asyncpg/protocol/codecs/base.pyx":532
+ *                     format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ *                         base_type, name, schema)             # <<<<<<<<<<<<<<
+ * 
+ *                 self._derived_type_codecs[oid, format] = elem_codec
+ */
+        __pyx_t_9 = NULL;
+        __pyx_t_10 = 0;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
+          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
+          if (likely(__pyx_t_9)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+            __Pyx_INCREF(__pyx_t_9);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_8, function);
+            __pyx_t_10 = 1;
+          }
+        }
+        #if CYTHON_FAST_PYCALL
+        if (PyFunction_Check(__pyx_t_8)) {
+          PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_base_type, __pyx_v_name, __pyx_v_schema};
+          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 531, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_GOTREF(__pyx_t_4);
+        } else
+        #endif
+        #if CYTHON_FAST_PYCCALL
+        if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
+          PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_base_type, __pyx_v_name, __pyx_v_schema};
+          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 531, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_GOTREF(__pyx_t_4);
+        } else
+        #endif
+        {
+          __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 531, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          if (__pyx_t_9) {
+            __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+          }
+          __Pyx_INCREF(__pyx_v_base_type);
+          __Pyx_GIVEREF(__pyx_v_base_type);
+          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_base_type);
+          __Pyx_INCREF(__pyx_v_name);
+          __Pyx_GIVEREF(__pyx_v_name);
+          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_name);
+          __Pyx_INCREF(__pyx_v_schema);
+          __Pyx_GIVEREF(__pyx_v_schema);
+          PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_v_schema);
+          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 531, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_4);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        }
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":531
+ *                 if elem_codec is None:
+ *                     format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(             # <<<<<<<<<<<<<<
+ *                         base_type, name, schema)
+ * 
+ */
+        if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 531, __pyx_L1_error)
+        __Pyx_DECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_4));
+        __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":529
+ * 
+ *                 elem_codec = self.get_codec(base_type, format)
+ *                 if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                     format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":534
+ *                         base_type, name, schema)
+ * 
+ *                 self._derived_type_codecs[oid, format] = elem_codec             # <<<<<<<<<<<<<<
+ * 
+ *             elif ti['kind'] == b'r':
+ */
+      if (unlikely(__pyx_v_self->_derived_type_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(3, 534, __pyx_L1_error)
+      }
+      __pyx_t_4 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 534, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 534, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_INCREF(__pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_v_oid);
+      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_t_4);
+      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4);
+      __pyx_t_4 = 0;
+      if (unlikely(PyDict_SetItem(__pyx_v_self->_derived_type_codecs, __pyx_t_8, ((PyObject *)__pyx_v_elem_codec)) < 0)) __PYX_ERR(3, 534, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":520
+ *                         comp_type_attrs, element_names)
+ * 
+ *             elif ti['kind'] == b'd':             # <<<<<<<<<<<<<<
+ *                 # Domain type
+ * 
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":536
+ *                 self._derived_type_codecs[oid, format] = elem_codec
+ * 
+ *             elif ti['kind'] == b'r':             # <<<<<<<<<<<<<<
+ *                 # Range type
+ * 
+ */
+    __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_kind); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 536, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_5 = (__Pyx_PyBytes_Equals(__pyx_t_8, __pyx_n_b_r, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 536, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":539
+ *                 # Range type
+ * 
+ *                 if not range_subtype_oid:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for range {}'.format(
+ */
+      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_range_subtype_oid); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 539, __pyx_L1_error)
+      __pyx_t_6 = ((!__pyx_t_5) != 0);
+      if (unlikely(__pyx_t_6)) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":540
+ * 
+ *                 if not range_subtype_oid:
+ *                     raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                         'type record missing base type for range {}'.format(
+ *                             oid))
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 540, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 540, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":541
+ *                 if not range_subtype_oid:
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for range {}'.format(             # <<<<<<<<<<<<<<
+ *                             oid))
+ * 
+ */
+        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_type_record_missing_base_type_fo_2, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 541, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+
+        /* "asyncpg/protocol/codecs/base.pyx":542
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for range {}'.format(
+ *                             oid))             # <<<<<<<<<<<<<<
+ * 
+ *                 if ti['elem_has_bin_io']:
+ */
+        __pyx_t_13 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_9);
+          if (likely(__pyx_t_13)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+            __Pyx_INCREF(__pyx_t_13);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_9, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_13, __pyx_v_oid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_oid);
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 541, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
+          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11);
+          if (likely(__pyx_t_9)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+            __Pyx_INCREF(__pyx_t_9);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_11, function);
+          }
+        }
+        __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_9, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_4);
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 540, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __PYX_ERR(3, 540, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/base.pyx":539
+ *                 # Range type
+ * 
+ *                 if not range_subtype_oid:             # <<<<<<<<<<<<<<
+ *                     raise exceptions.InternalClientError(
+ *                         'type record missing base type for range {}'.format(
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":544
+ *                             oid))
+ * 
+ *                 if ti['elem_has_bin_io']:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_BINARY
+ *                 else:
+ */
+      __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_elem_has_bin_io); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 544, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(3, 544, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      if (__pyx_t_6) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":545
+ * 
+ *                 if ti['elem_has_bin_io']:
+ *                     elem_format = PG_FORMAT_BINARY             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     elem_format = PG_FORMAT_TEXT
+ */
+        __pyx_v_elem_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY;
+
+        /* "asyncpg/protocol/codecs/base.pyx":544
+ *                             oid))
+ * 
+ *                 if ti['elem_has_bin_io']:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_BINARY
+ *                 else:
+ */
+        goto __pyx_L23;
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":547
+ *                     elem_format = PG_FORMAT_BINARY
+ *                 else:
+ *                     elem_format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ * 
+ *                 elem_codec = self.get_codec(range_subtype_oid, elem_format)
+ */
+      /*else*/ {
+        __pyx_v_elem_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+      }
+      __pyx_L23:;
+
+      /* "asyncpg/protocol/codecs/base.pyx":549
+ *                     elem_format = PG_FORMAT_TEXT
+ * 
+ *                 elem_codec = self.get_codec(range_subtype_oid, elem_format)             # <<<<<<<<<<<<<<
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT
+ */
+      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_range_subtype_oid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 549, __pyx_L1_error)
+      __pyx_t_8 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_t_7, __pyx_v_elem_format)); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 549, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_8));
+      __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":550
+ * 
+ *                 elem_codec = self.get_codec(range_subtype_oid, elem_format)
+ *                 if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ */
+      __pyx_t_6 = (((PyObject *)__pyx_v_elem_codec) == Py_None);
+      __pyx_t_5 = (__pyx_t_6 != 0);
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":551
+ *                 elem_codec = self.get_codec(range_subtype_oid, elem_format)
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT             # <<<<<<<<<<<<<<
+ *                     elem_codec = self.declare_fallback_codec(
+ *                         range_subtype_oid, name, schema)
+ */
+        __pyx_v_elem_format = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT;
+
+        /* "asyncpg/protocol/codecs/base.pyx":552
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(             # <<<<<<<<<<<<<<
+ *                         range_subtype_oid, name, schema)
+ * 
+ */
+        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_declare_fallback_codec); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 552, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+
+        /* "asyncpg/protocol/codecs/base.pyx":553
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ *                         range_subtype_oid, name, schema)             # <<<<<<<<<<<<<<
+ * 
+ *                 self._derived_type_codecs[oid, elem_format] = \
+ */
+        __pyx_t_4 = NULL;
+        __pyx_t_10 = 0;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_11);
+          if (likely(__pyx_t_4)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+            __Pyx_INCREF(__pyx_t_4);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_11, function);
+            __pyx_t_10 = 1;
+          }
+        }
+        #if CYTHON_FAST_PYCALL
+        if (PyFunction_Check(__pyx_t_11)) {
+          PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_range_subtype_oid, __pyx_v_name, __pyx_v_schema};
+          __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 552, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+          __Pyx_GOTREF(__pyx_t_8);
+        } else
+        #endif
+        #if CYTHON_FAST_PYCCALL
+        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
+          PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_range_subtype_oid, __pyx_v_name, __pyx_v_schema};
+          __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 552, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+          __Pyx_GOTREF(__pyx_t_8);
+        } else
+        #endif
+        {
+          __pyx_t_9 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 552, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          if (__pyx_t_4) {
+            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); __pyx_t_4 = NULL;
+          }
+          __Pyx_INCREF(__pyx_v_range_subtype_oid);
+          __Pyx_GIVEREF(__pyx_v_range_subtype_oid);
+          PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_v_range_subtype_oid);
+          __Pyx_INCREF(__pyx_v_name);
+          __Pyx_GIVEREF(__pyx_v_name);
+          PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_v_name);
+          __Pyx_INCREF(__pyx_v_schema);
+          __Pyx_GIVEREF(__pyx_v_schema);
+          PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_10, __pyx_v_schema);
+          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 552, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_8);
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        }
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":552
+ *                 if elem_codec is None:
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(             # <<<<<<<<<<<<<<
+ *                         range_subtype_oid, name, schema)
+ * 
+ */
+        if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 552, __pyx_L1_error)
+        __Pyx_DECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_8));
+        __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/codecs/base.pyx":550
+ * 
+ *                 elem_codec = self.get_codec(range_subtype_oid, elem_format)
+ *                 if elem_codec is None:             # <<<<<<<<<<<<<<
+ *                     elem_format = PG_FORMAT_TEXT
+ *                     elem_codec = self.declare_fallback_codec(
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":556
+ * 
+ *                 self._derived_type_codecs[oid, elem_format] = \
+ *                     Codec.new_range_codec(oid, name, schema, elem_codec)             # <<<<<<<<<<<<<<
+ * 
+ *             elif ti['kind'] == b'e':
+ */
+      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 556, __pyx_L1_error)
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_name))||((__pyx_v_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_name)->tp_name), 0))) __PYX_ERR(3, 556, __pyx_L1_error)
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_schema))||((__pyx_v_schema) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_schema)->tp_name), 0))) __PYX_ERR(3, 556, __pyx_L1_error)
+      __pyx_t_8 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_range_codec(__pyx_t_7, ((PyObject*)__pyx_v_name), ((PyObject*)__pyx_v_schema), __pyx_v_elem_codec)); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 556, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+
+      /* "asyncpg/protocol/codecs/base.pyx":555
+ *                         range_subtype_oid, name, schema)
+ * 
+ *                 self._derived_type_codecs[oid, elem_format] = \             # <<<<<<<<<<<<<<
+ *                     Codec.new_range_codec(oid, name, schema, elem_codec)
+ * 
+ */
+      if (unlikely(__pyx_v_self->_derived_type_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(3, 555, __pyx_L1_error)
+      }
+      __pyx_t_11 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_elem_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 555, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 555, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __Pyx_INCREF(__pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_v_oid);
+      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_t_11);
+      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_11);
+      __pyx_t_11 = 0;
+      if (unlikely(PyDict_SetItem(__pyx_v_self->_derived_type_codecs, __pyx_t_9, __pyx_t_8) < 0)) __PYX_ERR(3, 555, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":536
+ *                 self._derived_type_codecs[oid, format] = elem_codec
+ * 
+ *             elif ti['kind'] == b'r':             # <<<<<<<<<<<<<<
+ *                 # Range type
+ * 
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":558
+ *                     Codec.new_range_codec(oid, name, schema, elem_codec)
+ * 
+ *             elif ti['kind'] == b'e':             # <<<<<<<<<<<<<<
+ *                 # Enum types are essentially text
+ *                 self._set_builtin_type_codec(oid, name, schema, 'scalar',
+ */
+    __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ti, __pyx_n_u_kind); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 558, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_5 = (__Pyx_PyBytes_Equals(__pyx_t_8, __pyx_n_b_e, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(3, 558, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":560
+ *             elif ti['kind'] == b'e':
+ *                 # Enum types are essentially text
+ *                 self._set_builtin_type_codec(oid, name, schema, 'scalar',             # <<<<<<<<<<<<<<
+ *                                              TEXTOID, PG_FORMAT_ANY)
+ *             else:
+ */
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_builtin_type_codec_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 560, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+
+      /* "asyncpg/protocol/codecs/base.pyx":561
+ *                 # Enum types are essentially text
+ *                 self._set_builtin_type_codec(oid, name, schema, 'scalar',
+ *                                              TEXTOID, PG_FORMAT_ANY)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 self.declare_fallback_codec(oid, name, schema)
+ */
+      __pyx_t_11 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 561, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __pyx_t_4 = NULL;
+      __pyx_t_10 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+          __pyx_t_10 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_9)) {
+        PyObject *__pyx_temp[7] = {__pyx_t_4, __pyx_v_oid, __pyx_v_name, __pyx_v_schema, __pyx_n_u_scalar, __pyx_int_25, __pyx_t_11};
+        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 6+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 560, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
+        PyObject *__pyx_temp[7] = {__pyx_t_4, __pyx_v_oid, __pyx_v_name, __pyx_v_schema, __pyx_n_u_scalar, __pyx_int_25, __pyx_t_11};
+        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 6+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 560, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_13 = PyTuple_New(6+__pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(3, 560, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_13);
+        if (__pyx_t_4) {
+          __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_4); __pyx_t_4 = NULL;
+        }
+        __Pyx_INCREF(__pyx_v_oid);
+        __Pyx_GIVEREF(__pyx_v_oid);
+        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_10, __pyx_v_oid);
+        __Pyx_INCREF(__pyx_v_name);
+        __Pyx_GIVEREF(__pyx_v_name);
+        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_10, __pyx_v_name);
+        __Pyx_INCREF(__pyx_v_schema);
+        __Pyx_GIVEREF(__pyx_v_schema);
+        PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_10, __pyx_v_schema);
+        __Pyx_INCREF(__pyx_n_u_scalar);
+        __Pyx_GIVEREF(__pyx_n_u_scalar);
+        PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_10, __pyx_n_u_scalar);
+        __Pyx_INCREF(__pyx_int_25);
+        __Pyx_GIVEREF(__pyx_int_25);
+        PyTuple_SET_ITEM(__pyx_t_13, 4+__pyx_t_10, __pyx_int_25);
+        __Pyx_GIVEREF(__pyx_t_11);
+        PyTuple_SET_ITEM(__pyx_t_13, 5+__pyx_t_10, __pyx_t_11);
+        __pyx_t_11 = 0;
+        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 560, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":558
+ *                     Codec.new_range_codec(oid, name, schema, elem_codec)
+ * 
+ *             elif ti['kind'] == b'e':             # <<<<<<<<<<<<<<
+ *                 # Enum types are essentially text
+ *                 self._set_builtin_type_codec(oid, name, schema, 'scalar',
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":563
+ *                                              TEXTOID, PG_FORMAT_ANY)
+ *             else:
+ *                 self.declare_fallback_codec(oid, name, schema)             # <<<<<<<<<<<<<<
+ * 
+ *     def add_python_codec(self, typeoid, typename, typeschema, typekind,
+ */
+    /*else*/ {
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_declare_fallback_codec); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 563, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_13 = NULL;
+      __pyx_t_10 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_13)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_13);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+          __pyx_t_10 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_9)) {
+        PyObject *__pyx_temp[4] = {__pyx_t_13, __pyx_v_oid, __pyx_v_name, __pyx_v_schema};
+        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 563, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_GOTREF(__pyx_t_8);
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
+        PyObject *__pyx_temp[4] = {__pyx_t_13, __pyx_v_oid, __pyx_v_name, __pyx_v_schema};
+        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 563, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_GOTREF(__pyx_t_8);
+      } else
+      #endif
+      {
+        __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(3, 563, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        if (__pyx_t_13) {
+          __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL;
+        }
+        __Pyx_INCREF(__pyx_v_oid);
+        __Pyx_GIVEREF(__pyx_v_oid);
+        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_oid);
+        __Pyx_INCREF(__pyx_v_name);
+        __Pyx_GIVEREF(__pyx_v_name);
+        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_name);
+        __Pyx_INCREF(__pyx_v_schema);
+        __Pyx_GIVEREF(__pyx_v_schema);
+        PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_v_schema);
+        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 563, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    }
+    __pyx_L8:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":439
+ *             Py_UCS4 elem_delim
+ * 
+ *         for ti in types:             # <<<<<<<<<<<<<<
+ *             oid = ti['oid']
+ * 
+ */
+    __pyx_L3_continue:;
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":430
+ *         self._custom_type_codecs = {}
+ * 
+ *     def add_types(self, types):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec elem_codec
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.add_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_codec);
+  __Pyx_XDECREF(__pyx_v_comp_elem_codecs);
+  __Pyx_XDECREF(__pyx_v_ti);
+  __Pyx_XDECREF(__pyx_v_oid);
+  __Pyx_XDECREF(__pyx_v_name);
+  __Pyx_XDECREF(__pyx_v_schema);
+  __Pyx_XDECREF(__pyx_v_array_element_oid);
+  __Pyx_XDECREF(__pyx_v_range_subtype_oid);
+  __Pyx_XDECREF(__pyx_v_comp_type_attrs);
+  __Pyx_XDECREF(__pyx_v_base_type);
+  __Pyx_XDECREF(__pyx_v_typoid);
+  __Pyx_XDECREF(__pyx_v_element_names);
+  __Pyx_XDECREF(__pyx_v_i);
+  __Pyx_XDECREF(__pyx_v_attrname);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":565
+ *                 self.declare_fallback_codec(oid, name, schema)
+ * 
+ *     def add_python_codec(self, typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                          encoder, decoder, format, xformat):
+ *         cdef:
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_5add_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_5add_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  PyObject *__pyx_v_typename = 0;
+  PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_v_typekind = 0;
+  PyObject *__pyx_v_encoder = 0;
+  PyObject *__pyx_v_decoder = 0;
+  PyObject *__pyx_v_format = 0;
+  PyObject *__pyx_v_xformat = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("add_python_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,&__pyx_n_s_typekind,&__pyx_n_s_encoder,&__pyx_n_s_decoder,&__pyx_n_s_format,&__pyx_n_s_xformat,0};
+    PyObject* values[8] = {0,0,0,0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
+        CYTHON_FALLTHROUGH;
+        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
+        CYTHON_FALLTHROUGH;
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 1); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 2); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typekind)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 3); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoder)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 4); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_decoder)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 5); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  6:
+        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 6); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  7:
+        if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_xformat)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, 7); __PYX_ERR(3, 565, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_python_codec") < 0)) __PYX_ERR(3, 565, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 8) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+      values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
+      values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+    __pyx_v_typekind = values[3];
+    __pyx_v_encoder = values[4];
+    __pyx_v_decoder = values[5];
+    __pyx_v_format = values[6];
+    __pyx_v_xformat = values[7];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("add_python_codec", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 565, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.add_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_4add_python_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_encoder, __pyx_v_decoder, __pyx_v_format, __pyx_v_xformat);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_4add_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_encoder, PyObject *__pyx_v_decoder, PyObject *__pyx_v_format, PyObject *__pyx_v_xformat) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_core_codec = 0;
+  __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_c_encoder;
+  __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_c_decoder;
+  uint32_t __pyx_v_oid;
+  int __pyx_v_codec_set;
+  PyObject *__pyx_v_formats = NULL;
+  PyObject *__pyx_v_fmt = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  uint32_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  Py_ssize_t __pyx_t_8;
+  PyObject *(*__pyx_t_9)(PyObject *);
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_t_10;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_t_11;
+  struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_core_codec __pyx_t_12;
+  int __pyx_t_13;
+  __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_t_14;
+  __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  __Pyx_RefNannySetupContext("add_python_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":569
+ *         cdef:
+ *             Codec core_codec
+ *             encode_func c_encoder = NULL             # <<<<<<<<<<<<<<
+ *             decode_func c_decoder = NULL
+ *             uint32_t oid = pylong_as_oid(typeoid)
+ */
+  __pyx_v_c_encoder = NULL;
+
+  /* "asyncpg/protocol/codecs/base.pyx":570
+ *             Codec core_codec
+ *             encode_func c_encoder = NULL
+ *             decode_func c_decoder = NULL             # <<<<<<<<<<<<<<
+ *             uint32_t oid = pylong_as_oid(typeoid)
+ *             bint codec_set = False
+ */
+  __pyx_v_c_decoder = NULL;
+
+  /* "asyncpg/protocol/codecs/base.pyx":571
+ *             encode_func c_encoder = NULL
+ *             decode_func c_decoder = NULL
+ *             uint32_t oid = pylong_as_oid(typeoid)             # <<<<<<<<<<<<<<
+ *             bint codec_set = False
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_pylong_as_oid(__pyx_v_typeoid); if (unlikely(__pyx_t_1 == ((uint32_t)0xFFFFFFFFL) && PyErr_Occurred())) __PYX_ERR(3, 571, __pyx_L1_error)
+  __pyx_v_oid = __pyx_t_1;
+
+  /* "asyncpg/protocol/codecs/base.pyx":572
+ *             decode_func c_decoder = NULL
+ *             uint32_t oid = pylong_as_oid(typeoid)
+ *             bint codec_set = False             # <<<<<<<<<<<<<<
+ * 
+ *         # Clear all previous overrides (this also clears type cache).
+ */
+  __pyx_v_codec_set = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":575
+ * 
+ *         # Clear all previous overrides (this also clears type cache).
+ *         self.remove_python_codec(typeoid, typename, typeschema)             # <<<<<<<<<<<<<<
+ * 
+ *         if format == PG_FORMAT_ANY:
+ */
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_remove_python_codec); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 575, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = NULL;
+  __pyx_t_5 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+      __pyx_t_5 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_3)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema};
+    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 575, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+    PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema};
+    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 575, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_GOTREF(__pyx_t_2);
+  } else
+  #endif
+  {
+    __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 575, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    if (__pyx_t_4) {
+      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_typename);
+    __Pyx_GIVEREF(__pyx_v_typename);
+    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_typename);
+    __Pyx_INCREF(__pyx_v_typeschema);
+    __Pyx_GIVEREF(__pyx_v_typeschema);
+    PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_typeschema);
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 575, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":577
+ *         self.remove_python_codec(typeoid, typename, typeschema)
+ * 
+ *         if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *             formats = (PG_FORMAT_TEXT, PG_FORMAT_BINARY)
+ *         else:
+ */
+  __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 577, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyObject_RichCompare(__pyx_v_format, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 577, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(3, 577, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (__pyx_t_7) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":578
+ * 
+ *         if format == PG_FORMAT_ANY:
+ *             formats = (PG_FORMAT_TEXT, PG_FORMAT_BINARY)             # <<<<<<<<<<<<<<
+ *         else:
+ *             formats = (format,)
+ */
+    __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 578, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 578, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 578, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
+    __pyx_t_3 = 0;
+    __pyx_t_2 = 0;
+    __pyx_v_formats = __pyx_t_6;
+    __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":577
+ *         self.remove_python_codec(typeoid, typename, typeschema)
+ * 
+ *         if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *             formats = (PG_FORMAT_TEXT, PG_FORMAT_BINARY)
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":580
+ *             formats = (PG_FORMAT_TEXT, PG_FORMAT_BINARY)
+ *         else:
+ *             formats = (format,)             # <<<<<<<<<<<<<<
+ * 
+ *         for fmt in formats:
+ */
+  /*else*/ {
+    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 580, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_INCREF(__pyx_v_format);
+    __Pyx_GIVEREF(__pyx_v_format);
+    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_format);
+    __pyx_v_formats = __pyx_t_6;
+    __pyx_t_6 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/codecs/base.pyx":582
+ *             formats = (format,)
+ * 
+ *         for fmt in formats:             # <<<<<<<<<<<<<<
+ *             if xformat == PG_XFORMAT_TUPLE:
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ */
+  if (likely(PyList_CheckExact(__pyx_v_formats)) || PyTuple_CheckExact(__pyx_v_formats)) {
+    __pyx_t_6 = __pyx_v_formats; __Pyx_INCREF(__pyx_t_6); __pyx_t_8 = 0;
+    __pyx_t_9 = NULL;
+  } else {
+    __pyx_t_8 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_formats); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 582, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_9 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 582, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_9)) {
+      if (likely(PyList_CheckExact(__pyx_t_6))) {
+        if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_6)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(3, 582, __pyx_L1_error)
+        #else
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 582, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        #endif
+      } else {
+        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(3, 582, __pyx_L1_error)
+        #else
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 582, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        #endif
+      }
+    } else {
+      __pyx_t_2 = __pyx_t_9(__pyx_t_6);
+      if (unlikely(!__pyx_t_2)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(3, 582, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_2);
+    }
+    __Pyx_XDECREF_SET(__pyx_v_fmt, __pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":583
+ * 
+ *         for fmt in formats:
+ *             if xformat == PG_XFORMAT_TUPLE:             # <<<<<<<<<<<<<<
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ *                 if core_codec is None:
+ */
+    __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 583, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_3 = PyObject_RichCompare(__pyx_v_xformat, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 583, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(3, 583, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (__pyx_t_7) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":584
+ *         for fmt in formats:
+ *             if xformat == PG_XFORMAT_TUPLE:
+ *                 core_codec = get_core_codec(oid, fmt, xformat)             # <<<<<<<<<<<<<<
+ *                 if core_codec is None:
+ *                     continue
+ */
+      __pyx_t_10 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_fmt)); if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 584, __pyx_L1_error)
+      __pyx_t_11 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(__pyx_v_xformat)); if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 584, __pyx_L1_error)
+      __pyx_t_12.__pyx_n = 1;
+      __pyx_t_12.xformat = __pyx_t_11;
+      __pyx_t_3 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(__pyx_v_oid, __pyx_t_10, &__pyx_t_12)); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 584, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_XDECREF_SET(__pyx_v_core_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+      __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":585
+ *             if xformat == PG_XFORMAT_TUPLE:
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ *                 if core_codec is None:             # <<<<<<<<<<<<<<
+ *                     continue
+ *                 c_encoder = core_codec.c_encoder
+ */
+      __pyx_t_7 = (((PyObject *)__pyx_v_core_codec) == Py_None);
+      __pyx_t_13 = (__pyx_t_7 != 0);
+      if (__pyx_t_13) {
+
+        /* "asyncpg/protocol/codecs/base.pyx":586
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ *                 if core_codec is None:
+ *                     continue             # <<<<<<<<<<<<<<
+ *                 c_encoder = core_codec.c_encoder
+ *                 c_decoder = core_codec.c_decoder
+ */
+        goto __pyx_L4_continue;
+
+        /* "asyncpg/protocol/codecs/base.pyx":585
+ *             if xformat == PG_XFORMAT_TUPLE:
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ *                 if core_codec is None:             # <<<<<<<<<<<<<<
+ *                     continue
+ *                 c_encoder = core_codec.c_encoder
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/base.pyx":587
+ *                 if core_codec is None:
+ *                     continue
+ *                 c_encoder = core_codec.c_encoder             # <<<<<<<<<<<<<<
+ *                 c_decoder = core_codec.c_decoder
+ * 
+ */
+      __pyx_t_14 = __pyx_v_core_codec->c_encoder;
+      __pyx_v_c_encoder = __pyx_t_14;
+
+      /* "asyncpg/protocol/codecs/base.pyx":588
+ *                     continue
+ *                 c_encoder = core_codec.c_encoder
+ *                 c_decoder = core_codec.c_decoder             # <<<<<<<<<<<<<<
+ * 
+ *             self._custom_type_codecs[typeoid, fmt] = \
+ */
+      __pyx_t_15 = __pyx_v_core_codec->c_decoder;
+      __pyx_v_c_decoder = __pyx_t_15;
+
+      /* "asyncpg/protocol/codecs/base.pyx":583
+ * 
+ *         for fmt in formats:
+ *             if xformat == PG_XFORMAT_TUPLE:             # <<<<<<<<<<<<<<
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ *                 if core_codec is None:
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":591
+ * 
+ *             self._custom_type_codecs[typeoid, fmt] = \
+ *                 Codec.new_python_codec(oid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                        encoder, decoder, c_encoder, c_decoder,
+ *                                        fmt, xformat)
+ */
+    if (!(likely(PyUnicode_CheckExact(__pyx_v_typename))||((__pyx_v_typename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_typename)->tp_name), 0))) __PYX_ERR(3, 591, __pyx_L1_error)
+    if (!(likely(PyUnicode_CheckExact(__pyx_v_typeschema))||((__pyx_v_typeschema) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_typeschema)->tp_name), 0))) __PYX_ERR(3, 591, __pyx_L1_error)
+    if (!(likely(PyUnicode_CheckExact(__pyx_v_typekind))||((__pyx_v_typekind) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_typekind)->tp_name), 0))) __PYX_ERR(3, 591, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":593
+ *                 Codec.new_python_codec(oid, typename, typeschema, typekind,
+ *                                        encoder, decoder, c_encoder, c_decoder,
+ *                                        fmt, xformat)             # <<<<<<<<<<<<<<
+ *             codec_set = True
+ * 
+ */
+    __pyx_t_10 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_fmt)); if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 593, __pyx_L1_error)
+    __pyx_t_11 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(__pyx_v_xformat)); if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 593, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":591
+ * 
+ *             self._custom_type_codecs[typeoid, fmt] = \
+ *                 Codec.new_python_codec(oid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                        encoder, decoder, c_encoder, c_decoder,
+ *                                        fmt, xformat)
+ */
+    __pyx_t_3 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_python_codec(__pyx_v_oid, ((PyObject*)__pyx_v_typename), ((PyObject*)__pyx_v_typeschema), ((PyObject*)__pyx_v_typekind), __pyx_v_encoder, __pyx_v_decoder, __pyx_v_c_encoder, __pyx_v_c_decoder, __pyx_t_10, __pyx_t_11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 591, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/protocol/codecs/base.pyx":590
+ *                 c_decoder = core_codec.c_decoder
+ * 
+ *             self._custom_type_codecs[typeoid, fmt] = \             # <<<<<<<<<<<<<<
+ *                 Codec.new_python_codec(oid, typename, typeschema, typekind,
+ *                                        encoder, decoder, c_encoder, c_decoder,
+ */
+    if (unlikely(__pyx_v_self->_custom_type_codecs == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(3, 590, __pyx_L1_error)
+    }
+    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 590, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_fmt);
+    __Pyx_GIVEREF(__pyx_v_fmt);
+    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_fmt);
+    if (unlikely(PyDict_SetItem(__pyx_v_self->_custom_type_codecs, __pyx_t_2, __pyx_t_3) < 0)) __PYX_ERR(3, 590, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":594
+ *                                        encoder, decoder, c_encoder, c_decoder,
+ *                                        fmt, xformat)
+ *             codec_set = True             # <<<<<<<<<<<<<<
+ * 
+ *         if not codec_set:
+ */
+    __pyx_v_codec_set = 1;
+
+    /* "asyncpg/protocol/codecs/base.pyx":582
+ *             formats = (format,)
+ * 
+ *         for fmt in formats:             # <<<<<<<<<<<<<<
+ *             if xformat == PG_XFORMAT_TUPLE:
+ *                 core_codec = get_core_codec(oid, fmt, xformat)
+ */
+    __pyx_L4_continue:;
+  }
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":596
+ *             codec_set = True
+ * 
+ *         if not codec_set:             # <<<<<<<<<<<<<<
+ *             raise exceptions.InterfaceError(
+ *                 "{} type does not support the 'tuple' exchange format".format(
+ */
+  __pyx_t_13 = ((!(__pyx_v_codec_set != 0)) != 0);
+  if (unlikely(__pyx_t_13)) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":597
+ * 
+ *         if not codec_set:
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 "{} type does not support the 'tuple' exchange format".format(
+ *                     typename))
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 597, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 597, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":598
+ *         if not codec_set:
+ *             raise exceptions.InterfaceError(
+ *                 "{} type does not support the 'tuple' exchange format".format(             # <<<<<<<<<<<<<<
+ *                     typename))
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_type_does_not_support_the_tuple, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 598, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/protocol/codecs/base.pyx":599
+ *             raise exceptions.InterfaceError(
+ *                 "{} type does not support the 'tuple' exchange format".format(
+ *                     typename))             # <<<<<<<<<<<<<<
+ * 
+ *     def remove_python_codec(self, typeoid, typename, typeschema):
+ */
+    __pyx_t_16 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_16)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_16);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_16, __pyx_v_typename) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_typename);
+    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 598, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 597, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __PYX_ERR(3, 597, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":596
+ *             codec_set = True
+ * 
+ *         if not codec_set:             # <<<<<<<<<<<<<<
+ *             raise exceptions.InterfaceError(
+ *                 "{} type does not support the 'tuple' exchange format".format(
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":565
+ *                 self.declare_fallback_codec(oid, name, schema)
+ * 
+ *     def add_python_codec(self, typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                          encoder, decoder, format, xformat):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.add_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_core_codec);
+  __Pyx_XDECREF(__pyx_v_formats);
+  __Pyx_XDECREF(__pyx_v_fmt);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":601
+ *                     typename))
+ * 
+ *     def remove_python_codec(self, typeoid, typename, typeschema):             # <<<<<<<<<<<<<<
+ *         for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):
+ *             self._custom_type_codecs.pop((typeoid, fmt), None)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_7remove_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_7remove_python_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  CYTHON_UNUSED PyObject *__pyx_v_typename = 0;
+  CYTHON_UNUSED PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("remove_python_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("remove_python_codec", 1, 3, 3, 1); __PYX_ERR(3, 601, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("remove_python_codec", 1, 3, 3, 2); __PYX_ERR(3, 601, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "remove_python_codec") < 0)) __PYX_ERR(3, 601, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("remove_python_codec", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 601, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.remove_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_6remove_python_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_6remove_python_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, CYTHON_UNUSED PyObject *__pyx_v_typename, CYTHON_UNUSED PyObject *__pyx_v_typeschema) {
+  PyObject *__pyx_v_fmt = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  Py_ssize_t __pyx_t_4;
+  __Pyx_RefNannySetupContext("remove_python_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":602
+ * 
+ *     def remove_python_codec(self, typeoid, typename, typeschema):
+ *         for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):             # <<<<<<<<<<<<<<
+ *             self._custom_type_codecs.pop((typeoid, fmt), None)
+ *         self.clear_type_cache()
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 602, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 602, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 602, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  for (;;) {
+    if (__pyx_t_4 >= 2) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(3, 602, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 602, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_fmt, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":603
+ *     def remove_python_codec(self, typeoid, typename, typeschema):
+ *         for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):
+ *             self._custom_type_codecs.pop((typeoid, fmt), None)             # <<<<<<<<<<<<<<
+ *         self.clear_type_cache()
+ * 
+ */
+    if (unlikely(__pyx_v_self->_custom_type_codecs == Py_None)) {
+      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "pop");
+      __PYX_ERR(3, 603, __pyx_L1_error)
+    }
+    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 603, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_fmt);
+    __Pyx_GIVEREF(__pyx_v_fmt);
+    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_fmt);
+    __pyx_t_1 = __Pyx_PyDict_Pop(__pyx_v_self->_custom_type_codecs, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 603, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":602
+ * 
+ *     def remove_python_codec(self, typeoid, typename, typeschema):
+ *         for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):             # <<<<<<<<<<<<<<
+ *             self._custom_type_codecs.pop((typeoid, fmt), None)
+ *         self.clear_type_cache()
+ */
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":604
+ *         for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):
+ *             self._custom_type_codecs.pop((typeoid, fmt), None)
+ *         self.clear_type_cache()             # <<<<<<<<<<<<<<
+ * 
+ *     def _set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_clear_type_cache); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 604, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_1, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 604, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":601
+ *                     typename))
+ * 
+ *     def remove_python_codec(self, typeoid, typename, typeschema):             # <<<<<<<<<<<<<<
+ *         for fmt in (PG_FORMAT_BINARY, PG_FORMAT_TEXT):
+ *             self._custom_type_codecs.pop((typeoid, fmt), None)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.remove_python_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_fmt);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":606
+ *         self.clear_type_cache()
+ * 
+ *     def _set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                 alias_to, format=PG_FORMAT_ANY):
+ *         cdef:
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_9_set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_9_set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  PyObject *__pyx_v_typename = 0;
+  PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_v_typekind = 0;
+  PyObject *__pyx_v_alias_to = 0;
+  PyObject *__pyx_v_format = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_set_builtin_type_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,&__pyx_n_s_typekind,&__pyx_n_s_alias_to,&__pyx_n_s_format,0};
+    PyObject* values[6] = {0,0,0,0,0,0};
+    values[5] = __pyx_k__10;
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("_set_builtin_type_codec", 0, 5, 6, 1); __PYX_ERR(3, 606, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("_set_builtin_type_codec", 0, 5, 6, 2); __PYX_ERR(3, 606, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typekind)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("_set_builtin_type_codec", 0, 5, 6, 3); __PYX_ERR(3, 606, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alias_to)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("_set_builtin_type_codec", 0, 5, 6, 4); __PYX_ERR(3, 606, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (kw_args > 0) {
+          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format);
+          if (value) { values[5] = value; kw_args--; }
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_set_builtin_type_codec") < 0)) __PYX_ERR(3, 606, __pyx_L3_error)
+      }
+    } else {
+      switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+    __pyx_v_typekind = values[3];
+    __pyx_v_alias_to = values[4];
+    __pyx_v_format = values[5];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("_set_builtin_type_codec", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 606, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig._set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_8_set_builtin_type_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_v_format);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_8_set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_target_codec = 0;
+  CYTHON_UNUSED uint32_t __pyx_v_oid;
+  uint32_t __pyx_v_alias_oid;
+  int __pyx_v_codec_set;
+  PyObject *__pyx_v_formats = NULL;
+  PyObject *__pyx_v_codec_str = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  uint32_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  Py_ssize_t __pyx_t_9;
+  PyObject *(*__pyx_t_10)(PyObject *);
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_t_11;
+  Py_UCS4 __pyx_t_12;
+  __Pyx_RefNannySetupContext("_set_builtin_type_codec", 0);
+  __Pyx_INCREF(__pyx_v_format);
+
+  /* "asyncpg/protocol/codecs/base.pyx":611
+ *             Codec codec
+ *             Codec target_codec
+ *             uint32_t oid = pylong_as_oid(typeoid)             # <<<<<<<<<<<<<<
+ *             uint32_t alias_oid = 0
+ *             bint codec_set = False
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_pylong_as_oid(__pyx_v_typeoid); if (unlikely(__pyx_t_1 == ((uint32_t)0xFFFFFFFFL) && PyErr_Occurred())) __PYX_ERR(3, 611, __pyx_L1_error)
+  __pyx_v_oid = __pyx_t_1;
+
+  /* "asyncpg/protocol/codecs/base.pyx":612
+ *             Codec target_codec
+ *             uint32_t oid = pylong_as_oid(typeoid)
+ *             uint32_t alias_oid = 0             # <<<<<<<<<<<<<<
+ *             bint codec_set = False
+ * 
+ */
+  __pyx_v_alias_oid = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":613
+ *             uint32_t oid = pylong_as_oid(typeoid)
+ *             uint32_t alias_oid = 0
+ *             bint codec_set = False             # <<<<<<<<<<<<<<
+ * 
+ *         if format == PG_FORMAT_ANY:
+ */
+  __pyx_v_codec_set = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":615
+ *             bint codec_set = False
+ * 
+ *         if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *             formats = (PG_FORMAT_BINARY, PG_FORMAT_TEXT)
+ *         else:
+ */
+  __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 615, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyObject_RichCompare(__pyx_v_format, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 615, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(3, 615, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (__pyx_t_4) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":616
+ * 
+ *         if format == PG_FORMAT_ANY:
+ *             formats = (PG_FORMAT_BINARY, PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ *         else:
+ *             formats = (format,)
+ */
+    __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 616, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 616, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 616, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+    __pyx_t_3 = 0;
+    __pyx_t_2 = 0;
+    __pyx_v_formats = __pyx_t_5;
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":615
+ *             bint codec_set = False
+ * 
+ *         if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *             formats = (PG_FORMAT_BINARY, PG_FORMAT_TEXT)
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":618
+ *             formats = (PG_FORMAT_BINARY, PG_FORMAT_TEXT)
+ *         else:
+ *             formats = (format,)             # <<<<<<<<<<<<<<
+ * 
+ *         if isinstance(alias_to, int):
+ */
+  /*else*/ {
+    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 618, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_INCREF(__pyx_v_format);
+    __Pyx_GIVEREF(__pyx_v_format);
+    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_format);
+    __pyx_v_formats = __pyx_t_5;
+    __pyx_t_5 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/codecs/base.pyx":620
+ *             formats = (format,)
+ * 
+ *         if isinstance(alias_to, int):             # <<<<<<<<<<<<<<
+ *             alias_oid = pylong_as_oid(alias_to)
+ *         else:
+ */
+  __pyx_t_4 = PyInt_Check(__pyx_v_alias_to); 
+  __pyx_t_6 = (__pyx_t_4 != 0);
+  if (__pyx_t_6) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":621
+ * 
+ *         if isinstance(alias_to, int):
+ *             alias_oid = pylong_as_oid(alias_to)             # <<<<<<<<<<<<<<
+ *         else:
+ *             alias_oid = BUILTIN_TYPE_NAME_MAP.get(alias_to, 0)
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_pylong_as_oid(__pyx_v_alias_to); if (unlikely(__pyx_t_1 == ((uint32_t)0xFFFFFFFFL) && PyErr_Occurred())) __PYX_ERR(3, 621, __pyx_L1_error)
+    __pyx_v_alias_oid = __pyx_t_1;
+
+    /* "asyncpg/protocol/codecs/base.pyx":620
+ *             formats = (format,)
+ * 
+ *         if isinstance(alias_to, int):             # <<<<<<<<<<<<<<
+ *             alias_oid = pylong_as_oid(alias_to)
+ *         else:
+ */
+    goto __pyx_L4;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":623
+ *             alias_oid = pylong_as_oid(alias_to)
+ *         else:
+ *             alias_oid = BUILTIN_TYPE_NAME_MAP.get(alias_to, 0)             # <<<<<<<<<<<<<<
+ * 
+ *         for format in formats:
+ */
+  /*else*/ {
+    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 623, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 623, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = NULL;
+    __pyx_t_7 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_2)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_2);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+        __pyx_t_7 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_3)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_alias_to, __pyx_int_0};
+      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 623, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_GOTREF(__pyx_t_5);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_alias_to, __pyx_int_0};
+      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 623, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_GOTREF(__pyx_t_5);
+    } else
+    #endif
+    {
+      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 623, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      if (__pyx_t_2) {
+        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); __pyx_t_2 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_alias_to);
+      __Pyx_GIVEREF(__pyx_v_alias_to);
+      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_alias_to);
+      __Pyx_INCREF(__pyx_int_0);
+      __Pyx_GIVEREF(__pyx_int_0);
+      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_int_0);
+      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 623, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_1 = __Pyx_PyInt_As_uint32_t(__pyx_t_5); if (unlikely((__pyx_t_1 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 623, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_v_alias_oid = __pyx_t_1;
+  }
+  __pyx_L4:;
+
+  /* "asyncpg/protocol/codecs/base.pyx":625
+ *             alias_oid = BUILTIN_TYPE_NAME_MAP.get(alias_to, 0)
+ * 
+ *         for format in formats:             # <<<<<<<<<<<<<<
+ *             if alias_oid != 0:
+ *                 target_codec = self.get_codec(alias_oid, format)
+ */
+  if (likely(PyList_CheckExact(__pyx_v_formats)) || PyTuple_CheckExact(__pyx_v_formats)) {
+    __pyx_t_5 = __pyx_v_formats; __Pyx_INCREF(__pyx_t_5); __pyx_t_9 = 0;
+    __pyx_t_10 = NULL;
+  } else {
+    __pyx_t_9 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_formats); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 625, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(3, 625, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_10)) {
+      if (likely(PyList_CheckExact(__pyx_t_5))) {
+        if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_5)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(3, 625, __pyx_L1_error)
+        #else
+        __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 625, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        #endif
+      } else {
+        if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(3, 625, __pyx_L1_error)
+        #else
+        __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 625, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        #endif
+      }
+    } else {
+      __pyx_t_3 = __pyx_t_10(__pyx_t_5);
+      if (unlikely(!__pyx_t_3)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(3, 625, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_3);
+    }
+    __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":626
+ * 
+ *         for format in formats:
+ *             if alias_oid != 0:             # <<<<<<<<<<<<<<
+ *                 target_codec = self.get_codec(alias_oid, format)
+ *             else:
+ */
+    __pyx_t_6 = ((__pyx_v_alias_oid != 0) != 0);
+    if (__pyx_t_6) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":627
+ *         for format in formats:
+ *             if alias_oid != 0:
+ *                 target_codec = self.get_codec(alias_oid, format)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 target_codec = get_extra_codec(alias_to, format)
+ */
+      __pyx_t_11 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format)); if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 627, __pyx_L1_error)
+      __pyx_t_3 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_v_alias_oid, __pyx_t_11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 627, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_XDECREF_SET(__pyx_v_target_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+      __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":626
+ * 
+ *         for format in formats:
+ *             if alias_oid != 0:             # <<<<<<<<<<<<<<
+ *                 target_codec = self.get_codec(alias_oid, format)
+ *             else:
+ */
+      goto __pyx_L7;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":629
+ *                 target_codec = self.get_codec(alias_oid, format)
+ *             else:
+ *                 target_codec = get_extra_codec(alias_to, format)             # <<<<<<<<<<<<<<
+ * 
+ *             if target_codec is None:
+ */
+    /*else*/ {
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_alias_to))||((__pyx_v_alias_to) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_alias_to)->tp_name), 0))) __PYX_ERR(3, 629, __pyx_L1_error)
+      __pyx_t_11 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format)); if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 629, __pyx_L1_error)
+      __pyx_t_3 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_get_extra_codec(((PyObject*)__pyx_v_alias_to), __pyx_t_11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 629, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_XDECREF_SET(__pyx_v_target_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+      __pyx_t_3 = 0;
+    }
+    __pyx_L7:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":631
+ *                 target_codec = get_extra_codec(alias_to, format)
+ * 
+ *             if target_codec is None:             # <<<<<<<<<<<<<<
+ *                 continue
+ * 
+ */
+    __pyx_t_6 = (((PyObject *)__pyx_v_target_codec) == Py_None);
+    __pyx_t_4 = (__pyx_t_6 != 0);
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":632
+ * 
+ *             if target_codec is None:
+ *                 continue             # <<<<<<<<<<<<<<
+ * 
+ *             codec = target_codec.copy()
+ */
+      goto __pyx_L5_continue;
+
+      /* "asyncpg/protocol/codecs/base.pyx":631
+ *                 target_codec = get_extra_codec(alias_to, format)
+ * 
+ *             if target_codec is None:             # <<<<<<<<<<<<<<
+ *                 continue
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":634
+ *                 continue
+ * 
+ *             codec = target_codec.copy()             # <<<<<<<<<<<<<<
+ *             codec.oid = typeoid
+ *             codec.name = typename
+ */
+    __pyx_t_3 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_5Codec_copy(__pyx_v_target_codec)); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 634, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":635
+ * 
+ *             codec = target_codec.copy()
+ *             codec.oid = typeoid             # <<<<<<<<<<<<<<
+ *             codec.name = typename
+ *             codec.schema = typeschema
+ */
+    __pyx_t_1 = __Pyx_PyInt_As_uint32_t(__pyx_v_typeoid); if (unlikely((__pyx_t_1 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 635, __pyx_L1_error)
+    __pyx_v_codec->oid = __pyx_t_1;
+
+    /* "asyncpg/protocol/codecs/base.pyx":636
+ *             codec = target_codec.copy()
+ *             codec.oid = typeoid
+ *             codec.name = typename             # <<<<<<<<<<<<<<
+ *             codec.schema = typeschema
+ *             codec.kind = typekind
+ */
+    if (!(likely(PyUnicode_CheckExact(__pyx_v_typename))||((__pyx_v_typename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_typename)->tp_name), 0))) __PYX_ERR(3, 636, __pyx_L1_error)
+    __pyx_t_3 = __pyx_v_typename;
+    __Pyx_INCREF(__pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_codec->name);
+    __Pyx_DECREF(__pyx_v_codec->name);
+    __pyx_v_codec->name = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":637
+ *             codec.oid = typeoid
+ *             codec.name = typename
+ *             codec.schema = typeschema             # <<<<<<<<<<<<<<
+ *             codec.kind = typekind
+ * 
+ */
+    if (!(likely(PyUnicode_CheckExact(__pyx_v_typeschema))||((__pyx_v_typeschema) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_typeschema)->tp_name), 0))) __PYX_ERR(3, 637, __pyx_L1_error)
+    __pyx_t_3 = __pyx_v_typeschema;
+    __Pyx_INCREF(__pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_codec->schema);
+    __Pyx_DECREF(__pyx_v_codec->schema);
+    __pyx_v_codec->schema = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":638
+ *             codec.name = typename
+ *             codec.schema = typeschema
+ *             codec.kind = typekind             # <<<<<<<<<<<<<<
+ * 
+ *             self._custom_type_codecs[typeoid, format] = codec
+ */
+    if (!(likely(PyUnicode_CheckExact(__pyx_v_typekind))||((__pyx_v_typekind) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_typekind)->tp_name), 0))) __PYX_ERR(3, 638, __pyx_L1_error)
+    __pyx_t_3 = __pyx_v_typekind;
+    __Pyx_INCREF(__pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_codec->kind);
+    __Pyx_DECREF(__pyx_v_codec->kind);
+    __pyx_v_codec->kind = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":640
+ *             codec.kind = typekind
+ * 
+ *             self._custom_type_codecs[typeoid, format] = codec             # <<<<<<<<<<<<<<
+ *             codec_set = True
+ * 
+ */
+    if (unlikely(__pyx_v_self->_custom_type_codecs == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(3, 640, __pyx_L1_error)
+    }
+    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 640, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_format);
+    __Pyx_GIVEREF(__pyx_v_format);
+    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_format);
+    if (unlikely(PyDict_SetItem(__pyx_v_self->_custom_type_codecs, __pyx_t_3, ((PyObject *)__pyx_v_codec)) < 0)) __PYX_ERR(3, 640, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":641
+ * 
+ *             self._custom_type_codecs[typeoid, format] = codec
+ *             codec_set = True             # <<<<<<<<<<<<<<
+ * 
+ *         if not codec_set:
+ */
+    __pyx_v_codec_set = 1;
+
+    /* "asyncpg/protocol/codecs/base.pyx":625
+ *             alias_oid = BUILTIN_TYPE_NAME_MAP.get(alias_to, 0)
+ * 
+ *         for format in formats:             # <<<<<<<<<<<<<<
+ *             if alias_oid != 0:
+ *                 target_codec = self.get_codec(alias_oid, format)
+ */
+    __pyx_L5_continue:;
+  }
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":643
+ *             codec_set = True
+ * 
+ *         if not codec_set:             # <<<<<<<<<<<<<<
+ *             if format == PG_FORMAT_BINARY:
+ *                 codec_str = 'binary'
+ */
+  __pyx_t_4 = ((!(__pyx_v_codec_set != 0)) != 0);
+  if (__pyx_t_4) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":644
+ * 
+ *         if not codec_set:
+ *             if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 codec_str = 'binary'
+ *             elif format == PG_FORMAT_TEXT:
+ */
+    __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 644, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_3 = PyObject_RichCompare(__pyx_v_format, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 644, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(3, 644, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":645
+ *         if not codec_set:
+ *             if format == PG_FORMAT_BINARY:
+ *                 codec_str = 'binary'             # <<<<<<<<<<<<<<
+ *             elif format == PG_FORMAT_TEXT:
+ *                 codec_str = 'text'
+ */
+      __Pyx_INCREF(__pyx_n_u_binary);
+      __pyx_v_codec_str = __pyx_n_u_binary;
+
+      /* "asyncpg/protocol/codecs/base.pyx":644
+ * 
+ *         if not codec_set:
+ *             if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *                 codec_str = 'binary'
+ *             elif format == PG_FORMAT_TEXT:
+ */
+      goto __pyx_L10;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":646
+ *             if format == PG_FORMAT_BINARY:
+ *                 codec_str = 'binary'
+ *             elif format == PG_FORMAT_TEXT:             # <<<<<<<<<<<<<<
+ *                 codec_str = 'text'
+ *             else:
+ */
+    __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 646, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = PyObject_RichCompare(__pyx_v_format, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 646, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(3, 646, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":647
+ *                 codec_str = 'binary'
+ *             elif format == PG_FORMAT_TEXT:
+ *                 codec_str = 'text'             # <<<<<<<<<<<<<<
+ *             else:
+ *                 codec_str = 'text or binary'
+ */
+      __Pyx_INCREF(__pyx_n_u_text);
+      __pyx_v_codec_str = __pyx_n_u_text;
+
+      /* "asyncpg/protocol/codecs/base.pyx":646
+ *             if format == PG_FORMAT_BINARY:
+ *                 codec_str = 'binary'
+ *             elif format == PG_FORMAT_TEXT:             # <<<<<<<<<<<<<<
+ *                 codec_str = 'text'
+ *             else:
+ */
+      goto __pyx_L10;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":649
+ *                 codec_str = 'text'
+ *             else:
+ *                 codec_str = 'text or binary'             # <<<<<<<<<<<<<<
+ * 
+ *             raise exceptions.InterfaceError(
+ */
+    /*else*/ {
+      __Pyx_INCREF(__pyx_kp_u_text_or_binary_2);
+      __pyx_v_codec_str = __pyx_kp_u_text_or_binary_2;
+    }
+    __pyx_L10:;
+
+    /* "asyncpg/protocol/codecs/base.pyx":651
+ *                 codec_str = 'text or binary'
+ * 
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 f'cannot alias {typename} to {alias_to}: '
+ *                 f'there is no {codec_str} codec for {alias_to}')
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 651, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 651, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":652
+ * 
+ *             raise exceptions.InterfaceError(
+ *                 f'cannot alias {typename} to {alias_to}: '             # <<<<<<<<<<<<<<
+ *                 f'there is no {codec_str} codec for {alias_to}')
+ * 
+ */
+    __pyx_t_3 = PyTuple_New(8); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 652, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_9 = 0;
+    __pyx_t_12 = 127;
+    __Pyx_INCREF(__pyx_kp_u_cannot_alias);
+    __pyx_t_9 += 13;
+    __Pyx_GIVEREF(__pyx_kp_u_cannot_alias);
+    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_cannot_alias);
+    __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_typename, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 652, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_12;
+    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+    __pyx_t_2 = 0;
+    __Pyx_INCREF(__pyx_kp_u_to);
+    __pyx_t_9 += 4;
+    __Pyx_GIVEREF(__pyx_kp_u_to);
+    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_kp_u_to);
+    __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_alias_to, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 652, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_12;
+    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2);
+    __pyx_t_2 = 0;
+    __Pyx_INCREF(__pyx_kp_u_there_is_no);
+    __pyx_t_9 += 14;
+    __Pyx_GIVEREF(__pyx_kp_u_there_is_no);
+    PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_kp_u_there_is_no);
+
+    /* "asyncpg/protocol/codecs/base.pyx":653
+ *             raise exceptions.InterfaceError(
+ *                 f'cannot alias {typename} to {alias_to}: '
+ *                 f'there is no {codec_str} codec for {alias_to}')             # <<<<<<<<<<<<<<
+ * 
+ *     def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+ */
+    __Pyx_INCREF(__pyx_v_codec_str);
+    __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_v_codec_str) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_v_codec_str) : __pyx_t_12;
+    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_v_codec_str);
+    __Pyx_GIVEREF(__pyx_v_codec_str);
+    PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_v_codec_str);
+    __Pyx_INCREF(__pyx_kp_u_codec_for);
+    __pyx_t_9 += 11;
+    __Pyx_GIVEREF(__pyx_kp_u_codec_for);
+    PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_kp_u_codec_for);
+    __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_alias_to, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 653, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_12;
+    __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_3, 7, __pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":652
+ * 
+ *             raise exceptions.InterfaceError(
+ *                 f'cannot alias {typename} to {alias_to}: '             # <<<<<<<<<<<<<<
+ *                 f'there is no {codec_str} codec for {alias_to}')
+ * 
+ */
+    __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_3, 8, __pyx_t_9, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 652, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_8, function);
+      }
+    }
+    __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_2);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 651, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __PYX_ERR(3, 651, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":643
+ *             codec_set = True
+ * 
+ *         if not codec_set:             # <<<<<<<<<<<<<<
+ *             if format == PG_FORMAT_BINARY:
+ *                 codec_str = 'binary'
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":606
+ *         self.clear_type_cache()
+ * 
+ *     def _set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                 alias_to, format=PG_FORMAT_ANY):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig._set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF((PyObject *)__pyx_v_target_codec);
+  __Pyx_XDECREF(__pyx_v_formats);
+  __Pyx_XDECREF(__pyx_v_codec_str);
+  __Pyx_XDECREF(__pyx_v_format);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":655
+ *                 f'there is no {codec_str} codec for {alias_to}')
+ * 
+ *     def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                alias_to, format=PG_FORMAT_ANY):
+ *         self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_11set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_11set_builtin_type_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_typeoid = 0;
+  PyObject *__pyx_v_typename = 0;
+  PyObject *__pyx_v_typeschema = 0;
+  PyObject *__pyx_v_typekind = 0;
+  PyObject *__pyx_v_alias_to = 0;
+  PyObject *__pyx_v_format = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("set_builtin_type_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_typeoid,&__pyx_n_s_typename,&__pyx_n_s_typeschema,&__pyx_n_s_typekind,&__pyx_n_s_alias_to,&__pyx_n_s_format,0};
+    PyObject* values[6] = {0,0,0,0,0,0};
+    values[5] = __pyx_k__11;
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeoid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typename)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 0, 5, 6, 1); __PYX_ERR(3, 655, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typeschema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 0, 5, 6, 2); __PYX_ERR(3, 655, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typekind)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 0, 5, 6, 3); __PYX_ERR(3, 655, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alias_to)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 0, 5, 6, 4); __PYX_ERR(3, 655, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (kw_args > 0) {
+          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format);
+          if (value) { values[5] = value; kw_args--; }
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_builtin_type_codec") < 0)) __PYX_ERR(3, 655, __pyx_L3_error)
+      }
+    } else {
+      switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+    }
+    __pyx_v_typeoid = values[0];
+    __pyx_v_typename = values[1];
+    __pyx_v_typeschema = values[2];
+    __pyx_v_typekind = values[3];
+    __pyx_v_alias_to = values[4];
+    __pyx_v_format = values[5];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("set_builtin_type_codec", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 655, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_10set_builtin_type_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_v_format);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_10set_builtin_type_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v_typeoid, PyObject *__pyx_v_typename, PyObject *__pyx_v_typeschema, PyObject *__pyx_v_typekind, PyObject *__pyx_v_alias_to, PyObject *__pyx_v_format) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("set_builtin_type_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":657
+ *     def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+ *                                alias_to, format=PG_FORMAT_ANY):
+ *         self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                      alias_to, format)
+ *         self.clear_type_cache()
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_builtin_type_codec_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 657, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+
+  /* "asyncpg/protocol/codecs/base.pyx":658
+ *                                alias_to, format=PG_FORMAT_ANY):
+ *         self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,
+ *                                      alias_to, format)             # <<<<<<<<<<<<<<
+ *         self.clear_type_cache()
+ * 
+ */
+  __pyx_t_3 = NULL;
+  __pyx_t_4 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+      __pyx_t_4 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[7] = {__pyx_t_3, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_v_format};
+    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 6+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 657, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[7] = {__pyx_t_3, __pyx_v_typeoid, __pyx_v_typename, __pyx_v_typeschema, __pyx_v_typekind, __pyx_v_alias_to, __pyx_v_format};
+    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 6+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 657, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+  } else
+  #endif
+  {
+    __pyx_t_5 = PyTuple_New(6+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 657, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    if (__pyx_t_3) {
+      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_typeoid);
+    __Pyx_GIVEREF(__pyx_v_typeoid);
+    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_typeoid);
+    __Pyx_INCREF(__pyx_v_typename);
+    __Pyx_GIVEREF(__pyx_v_typename);
+    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_typename);
+    __Pyx_INCREF(__pyx_v_typeschema);
+    __Pyx_GIVEREF(__pyx_v_typeschema);
+    PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_typeschema);
+    __Pyx_INCREF(__pyx_v_typekind);
+    __Pyx_GIVEREF(__pyx_v_typekind);
+    PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, __pyx_v_typekind);
+    __Pyx_INCREF(__pyx_v_alias_to);
+    __Pyx_GIVEREF(__pyx_v_alias_to);
+    PyTuple_SET_ITEM(__pyx_t_5, 4+__pyx_t_4, __pyx_v_alias_to);
+    __Pyx_INCREF(__pyx_v_format);
+    __Pyx_GIVEREF(__pyx_v_format);
+    PyTuple_SET_ITEM(__pyx_t_5, 5+__pyx_t_4, __pyx_v_format);
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 657, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":659
+ *         self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,
+ *                                      alias_to, format)
+ *         self.clear_type_cache()             # <<<<<<<<<<<<<<
+ * 
+ *     def clear_type_cache(self):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_clear_type_cache); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 659, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 659, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":655
+ *                 f'there is no {codec_str} codec for {alias_to}')
+ * 
+ *     def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,             # <<<<<<<<<<<<<<
+ *                                alias_to, format=PG_FORMAT_ANY):
+ *         self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.set_builtin_type_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":661
+ *         self.clear_type_cache()
+ * 
+ *     def clear_type_cache(self):             # <<<<<<<<<<<<<<
+ *         self._derived_type_codecs.clear()
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_13clear_type_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_13clear_type_cache(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("clear_type_cache (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_12clear_type_cache(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_12clear_type_cache(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("clear_type_cache", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":662
+ * 
+ *     def clear_type_cache(self):
+ *         self._derived_type_codecs.clear()             # <<<<<<<<<<<<<<
+ * 
+ *     def declare_fallback_codec(self, uint32_t oid, str name, str schema):
+ */
+  if (unlikely(__pyx_v_self->_derived_type_codecs == Py_None)) {
+    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "clear");
+    __PYX_ERR(3, 662, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_PyDict_Clear(__pyx_v_self->_derived_type_codecs); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(3, 662, __pyx_L1_error)
+
+  /* "asyncpg/protocol/codecs/base.pyx":661
+ *         self.clear_type_cache()
+ * 
+ *     def clear_type_cache(self):             # <<<<<<<<<<<<<<
+ *         self._derived_type_codecs.clear()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.clear_type_cache", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":664
+ *         self._derived_type_codecs.clear()
+ * 
+ *     def declare_fallback_codec(self, uint32_t oid, str name, str schema):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_15declare_fallback_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_15declare_fallback_codec(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  uint32_t __pyx_v_oid;
+  PyObject *__pyx_v_name = 0;
+  PyObject *__pyx_v_schema = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("declare_fallback_codec (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_oid,&__pyx_n_s_name,&__pyx_n_s_schema,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_oid)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("declare_fallback_codec", 1, 3, 3, 1); __PYX_ERR(3, 664, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_schema)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("declare_fallback_codec", 1, 3, 3, 2); __PYX_ERR(3, 664, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "declare_fallback_codec") < 0)) __PYX_ERR(3, 664, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v_oid = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_oid == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(3, 664, __pyx_L3_error)
+    __pyx_v_name = ((PyObject*)values[1]);
+    __pyx_v_schema = ((PyObject*)values[2]);
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("declare_fallback_codec", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(3, 664, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.declare_fallback_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_name), (&PyUnicode_Type), 1, "name", 1))) __PYX_ERR(3, 664, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_schema), (&PyUnicode_Type), 1, "schema", 1))) __PYX_ERR(3, 664, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_14declare_fallback_codec(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), __pyx_v_oid, __pyx_v_name, __pyx_v_schema);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_14declare_fallback_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, uint32_t __pyx_v_oid, PyObject *__pyx_v_name, PyObject *__pyx_v_schema) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("declare_fallback_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":667
+ *         cdef Codec codec
+ * 
+ *         codec = self.get_codec(oid, PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ *         if codec is not None:
+ *             return codec
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_v_oid, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 667, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":668
+ * 
+ *         codec = self.get_codec(oid, PG_FORMAT_TEXT)
+ *         if codec is not None:             # <<<<<<<<<<<<<<
+ *             return codec
+ * 
+ */
+  __pyx_t_2 = (((PyObject *)__pyx_v_codec) != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":669
+ *         codec = self.get_codec(oid, PG_FORMAT_TEXT)
+ *         if codec is not None:
+ *             return codec             # <<<<<<<<<<<<<<
+ * 
+ *         if oid <= MAXBUILTINOID:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+    __pyx_r = ((PyObject *)__pyx_v_codec);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":668
+ * 
+ *         codec = self.get_codec(oid, PG_FORMAT_TEXT)
+ *         if codec is not None:             # <<<<<<<<<<<<<<
+ *             return codec
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":671
+ *             return codec
+ * 
+ *         if oid <= MAXBUILTINOID:             # <<<<<<<<<<<<<<
+ *             # This is a BKI type, for which asyncpg has no
+ *             # defined codec.  This should only happen for newly
+ */
+  __pyx_t_3 = ((__pyx_v_oid <= 0x270F) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":678
+ *             #
+ *             raise NotImplementedError(
+ *                 'unhandled standard data type {!r} (OID {})'.format(             # <<<<<<<<<<<<<<
+ *                     name, oid))
+ *         else:
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unhandled_standard_data_type_r_O, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 678, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/protocol/codecs/base.pyx":679
+ *             raise NotImplementedError(
+ *                 'unhandled standard data type {!r} (OID {})'.format(
+ *                     name, oid))             # <<<<<<<<<<<<<<
+ *         else:
+ *             # This is a non-BKI type, and as such, has no
+ */
+    __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 679, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    __pyx_t_7 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+        __pyx_t_7 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_name, __pyx_t_5};
+      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 678, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_name, __pyx_t_5};
+      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 678, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 678, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      if (__pyx_t_6) {
+        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_name);
+      __Pyx_GIVEREF(__pyx_v_name);
+      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_name);
+      __Pyx_GIVEREF(__pyx_t_5);
+      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5);
+      __pyx_t_5 = 0;
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 678, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":677
+ *             # asyncpg is lacking support.
+ *             #
+ *             raise NotImplementedError(             # <<<<<<<<<<<<<<
+ *                 'unhandled standard data type {!r} (OID {})'.format(
+ *                     name, oid))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 677, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(3, 677, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":671
+ *             return codec
+ * 
+ *         if oid <= MAXBUILTINOID:             # <<<<<<<<<<<<<<
+ *             # This is a BKI type, for which asyncpg has no
+ *             # defined codec.  This should only happen for newly
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":687
+ *             # using Connection.set_type_codec().
+ *             #
+ *             self._set_builtin_type_codec(oid, name, schema, 'scalar',             # <<<<<<<<<<<<<<
+ *                                          TEXTOID, PG_FORMAT_TEXT)
+ * 
+ */
+  /*else*/ {
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_builtin_type_codec_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 687, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 687, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+
+    /* "asyncpg/protocol/codecs/base.pyx":688
+ *             #
+ *             self._set_builtin_type_codec(oid, name, schema, 'scalar',
+ *                                          TEXTOID, PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ * 
+ *             codec = self.get_codec(oid, PG_FORMAT_TEXT)
+ */
+    __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 688, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    __pyx_t_7 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_1, function);
+        __pyx_t_7 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_1)) {
+      PyObject *__pyx_temp[7] = {__pyx_t_6, __pyx_t_8, __pyx_v_name, __pyx_v_schema, __pyx_n_u_scalar, __pyx_int_25, __pyx_t_5};
+      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 6+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 687, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
+      PyObject *__pyx_temp[7] = {__pyx_t_6, __pyx_t_8, __pyx_v_name, __pyx_v_schema, __pyx_n_u_scalar, __pyx_int_25, __pyx_t_5};
+      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_7, 6+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 687, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_9 = PyTuple_New(6+__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 687, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      if (__pyx_t_6) {
+        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_7, __pyx_t_8);
+      __Pyx_INCREF(__pyx_v_name);
+      __Pyx_GIVEREF(__pyx_v_name);
+      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_7, __pyx_v_name);
+      __Pyx_INCREF(__pyx_v_schema);
+      __Pyx_GIVEREF(__pyx_v_schema);
+      PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_7, __pyx_v_schema);
+      __Pyx_INCREF(__pyx_n_u_scalar);
+      __Pyx_GIVEREF(__pyx_n_u_scalar);
+      PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_7, __pyx_n_u_scalar);
+      __Pyx_INCREF(__pyx_int_25);
+      __Pyx_GIVEREF(__pyx_int_25);
+      PyTuple_SET_ITEM(__pyx_t_9, 4+__pyx_t_7, __pyx_int_25);
+      __Pyx_GIVEREF(__pyx_t_5);
+      PyTuple_SET_ITEM(__pyx_t_9, 5+__pyx_t_7, __pyx_t_5);
+      __pyx_t_8 = 0;
+      __pyx_t_5 = 0;
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 687, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":690
+ *                                          TEXTOID, PG_FORMAT_TEXT)
+ * 
+ *             codec = self.get_codec(oid, PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ * 
+ *         return codec
+ */
+    __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(__pyx_v_self, __pyx_v_oid, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT)); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 690, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_4));
+    __pyx_t_4 = 0;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":692
+ *             codec = self.get_codec(oid, PG_FORMAT_TEXT)
+ * 
+ *         return codec             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline Codec get_codec(self, uint32_t oid, ServerDataFormat format):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = ((PyObject *)__pyx_v_codec);
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":664
+ *         self._derived_type_codecs.clear()
+ * 
+ *     def declare_fallback_codec(self, uint32_t oid, str name, str schema):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.declare_fallback_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":694
+ *         return codec
+ * 
+ *     cdef inline Codec get_codec(self, uint32_t oid, ServerDataFormat format):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, uint32_t __pyx_v_oid, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  __Pyx_RefNannySetupContext("get_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":697
+ *         cdef Codec codec
+ * 
+ *         codec = self.get_any_local_codec(oid)             # <<<<<<<<<<<<<<
+ *         if codec is not None:
+ *             if codec.format != format:
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_any_local_codec(__pyx_v_self, __pyx_v_oid)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 697, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":698
+ * 
+ *         codec = self.get_any_local_codec(oid)
+ *         if codec is not None:             # <<<<<<<<<<<<<<
+ *             if codec.format != format:
+ *                 # The codec for this OID has been overridden by
+ */
+  __pyx_t_2 = (((PyObject *)__pyx_v_codec) != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":699
+ *         codec = self.get_any_local_codec(oid)
+ *         if codec is not None:
+ *             if codec.format != format:             # <<<<<<<<<<<<<<
+ *                 # The codec for this OID has been overridden by
+ *                 # set_{builtin}_type_codec with a different format.
+ */
+    __pyx_t_3 = ((__pyx_v_codec->format != __pyx_v_format) != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":703
+ *                 # set_{builtin}_type_codec with a different format.
+ *                 # We must respect that and not return a core codec.
+ *                 return None             # <<<<<<<<<<<<<<
+ *             else:
+ *                 return codec
+ */
+      __Pyx_XDECREF(((PyObject *)__pyx_r));
+      __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None); __Pyx_INCREF(Py_None);
+      goto __pyx_L0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":699
+ *         codec = self.get_any_local_codec(oid)
+ *         if codec is not None:
+ *             if codec.format != format:             # <<<<<<<<<<<<<<
+ *                 # The codec for this OID has been overridden by
+ *                 # set_{builtin}_type_codec with a different format.
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":705
+ *                 return None
+ *             else:
+ *                 return codec             # <<<<<<<<<<<<<<
+ * 
+ *         codec = get_core_codec(oid, format)
+ */
+    /*else*/ {
+      __Pyx_XDECREF(((PyObject *)__pyx_r));
+      __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+      __pyx_r = __pyx_v_codec;
+      goto __pyx_L0;
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":698
+ * 
+ *         codec = self.get_any_local_codec(oid)
+ *         if codec is not None:             # <<<<<<<<<<<<<<
+ *             if codec.format != format:
+ *                 # The codec for this OID has been overridden by
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":707
+ *                 return codec
+ * 
+ *         codec = get_core_codec(oid, format)             # <<<<<<<<<<<<<<
+ *         if codec is not None:
+ *             return codec
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(__pyx_v_oid, __pyx_v_format, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 707, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_1));
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":708
+ * 
+ *         codec = get_core_codec(oid, format)
+ *         if codec is not None:             # <<<<<<<<<<<<<<
+ *             return codec
+ *         else:
+ */
+  __pyx_t_3 = (((PyObject *)__pyx_v_codec) != Py_None);
+  __pyx_t_2 = (__pyx_t_3 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":709
+ *         codec = get_core_codec(oid, format)
+ *         if codec is not None:
+ *             return codec             # <<<<<<<<<<<<<<
+ *         else:
+ *             try:
+ */
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+    __pyx_r = __pyx_v_codec;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":708
+ * 
+ *         codec = get_core_codec(oid, format)
+ *         if codec is not None:             # <<<<<<<<<<<<<<
+ *             return codec
+ *         else:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":711
+ *             return codec
+ *         else:
+ *             try:             # <<<<<<<<<<<<<<
+ *                 return self._derived_type_codecs[oid, format]
+ *             except KeyError:
+ */
+  /*else*/ {
+    {
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/codecs/base.pyx":712
+ *         else:
+ *             try:
+ *                 return self._derived_type_codecs[oid, format]             # <<<<<<<<<<<<<<
+ *             except KeyError:
+ *                 return None
+ */
+        __Pyx_XDECREF(((PyObject *)__pyx_r));
+        if (unlikely(__pyx_v_self->_derived_type_codecs == Py_None)) {
+          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+          __PYX_ERR(3, 712, __pyx_L6_error)
+        }
+        __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 712, __pyx_L6_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __pyx_t_7 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 712, __pyx_L6_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 712, __pyx_L6_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_GIVEREF(__pyx_t_1);
+        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
+        __Pyx_GIVEREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
+        __pyx_t_1 = 0;
+        __pyx_t_7 = 0;
+        __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_self->_derived_type_codecs, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 712, __pyx_L6_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 712, __pyx_L6_error)
+        __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_7);
+        __pyx_t_7 = 0;
+        goto __pyx_L10_try_return;
+
+        /* "asyncpg/protocol/codecs/base.pyx":711
+ *             return codec
+ *         else:
+ *             try:             # <<<<<<<<<<<<<<
+ *                 return self._derived_type_codecs[oid, format]
+ *             except KeyError:
+ */
+      }
+      __pyx_L6_error:;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":713
+ *             try:
+ *                 return self._derived_type_codecs[oid, format]
+ *             except KeyError:             # <<<<<<<<<<<<<<
+ *                 return None
+ * 
+ */
+      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
+      if (__pyx_t_9) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.get_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_1) < 0) __PYX_ERR(3, 713, __pyx_L8_except_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_GOTREF(__pyx_t_1);
+
+        /* "asyncpg/protocol/codecs/base.pyx":714
+ *                 return self._derived_type_codecs[oid, format]
+ *             except KeyError:
+ *                 return None             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline Codec get_any_local_codec(self, uint32_t oid):
+ */
+        __Pyx_XDECREF(((PyObject *)__pyx_r));
+        __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None); __Pyx_INCREF(Py_None);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+        goto __pyx_L9_except_return;
+      }
+      goto __pyx_L8_except_error;
+      __pyx_L8_except_error:;
+
+      /* "asyncpg/protocol/codecs/base.pyx":711
+ *             return codec
+ *         else:
+ *             try:             # <<<<<<<<<<<<<<
+ *                 return self._derived_type_codecs[oid, format]
+ *             except KeyError:
+ */
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L1_error;
+      __pyx_L10_try_return:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L0;
+      __pyx_L9_except_return:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L0;
+    }
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":694
+ *         return codec
+ * 
+ *     cdef inline Codec get_codec(self, uint32_t oid, ServerDataFormat format):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.get_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":716
+ *                 return None
+ * 
+ *     cdef inline Codec get_any_local_codec(self, uint32_t oid):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_any_local_codec(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, uint32_t __pyx_v_oid) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  __Pyx_RefNannySetupContext("get_any_local_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":719
+ *         cdef Codec codec
+ * 
+ *         codec = self._custom_type_codecs.get((oid, PG_FORMAT_BINARY))             # <<<<<<<<<<<<<<
+ *         if codec is None:
+ *             return self._custom_type_codecs.get((oid, PG_FORMAT_TEXT))
+ */
+  if (unlikely(__pyx_v_self->_custom_type_codecs == Py_None)) {
+    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
+    __PYX_ERR(3, 719, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 719, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 719, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 719, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->_custom_type_codecs, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 719, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 719, __pyx_L1_error)
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":720
+ * 
+ *         codec = self._custom_type_codecs.get((oid, PG_FORMAT_BINARY))
+ *         if codec is None:             # <<<<<<<<<<<<<<
+ *             return self._custom_type_codecs.get((oid, PG_FORMAT_TEXT))
+ *         else:
+ */
+  __pyx_t_4 = (((PyObject *)__pyx_v_codec) == Py_None);
+  __pyx_t_5 = (__pyx_t_4 != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":721
+ *         codec = self._custom_type_codecs.get((oid, PG_FORMAT_BINARY))
+ *         if codec is None:
+ *             return self._custom_type_codecs.get((oid, PG_FORMAT_TEXT))             # <<<<<<<<<<<<<<
+ *         else:
+ *             return codec
+ */
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    if (unlikely(__pyx_v_self->_custom_type_codecs == Py_None)) {
+      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
+      __PYX_ERR(3, 721, __pyx_L1_error)
+    }
+    __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 721, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 721, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 721, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_GIVEREF(__pyx_t_2);
+    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
+    __pyx_t_2 = 0;
+    __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->_custom_type_codecs, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 721, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 721, __pyx_L1_error)
+    __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3);
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":720
+ * 
+ *         codec = self._custom_type_codecs.get((oid, PG_FORMAT_BINARY))
+ *         if codec is None:             # <<<<<<<<<<<<<<
+ *             return self._custom_type_codecs.get((oid, PG_FORMAT_TEXT))
+ *         else:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":723
+ *             return self._custom_type_codecs.get((oid, PG_FORMAT_TEXT))
+ *         else:
+ *             return codec             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+    __pyx_r = __pyx_v_codec;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":716
+ *                 return None
+ * 
+ *     cdef inline Codec get_any_local_codec(self, uint32_t oid):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.get_any_local_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = (self._custom_type_codecs, self._derived_type_codecs)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_16__reduce_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_16__reduce_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self) {
+  int __pyx_v_use_setstate;
+  PyObject *__pyx_v_state = NULL;
+  PyObject *__pyx_v__dict = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     cdef bint use_setstate
+ *     state = (self._custom_type_codecs, self._derived_type_codecs)             # <<<<<<<<<<<<<<
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ */
+  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_v_self->_custom_type_codecs);
+  __Pyx_GIVEREF(__pyx_v_self->_custom_type_codecs);
+  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->_custom_type_codecs);
+  __Pyx_INCREF(__pyx_v_self->_derived_type_codecs);
+  __Pyx_GIVEREF(__pyx_v_self->_derived_type_codecs);
+  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->_derived_type_codecs);
+  __pyx_v_state = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "(tree fragment)":4
+ *     cdef bint use_setstate
+ *     state = (self._custom_type_codecs, self._derived_type_codecs)
+ *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
+ *     if _dict is not None:
+ *         state += (_dict,)
+ */
+  __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v__dict = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "(tree fragment)":5
+ *     state = (self._custom_type_codecs, self._derived_type_codecs)
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+  __pyx_t_2 = (__pyx_v__dict != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "(tree fragment)":6
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ *         state += (_dict,)             # <<<<<<<<<<<<<<
+ *         use_setstate = True
+ *     else:
+ */
+    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_INCREF(__pyx_v__dict);
+    __Pyx_GIVEREF(__pyx_v__dict);
+    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict);
+    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4));
+    __pyx_t_4 = 0;
+
+    /* "(tree fragment)":7
+ *     if _dict is not None:
+ *         state += (_dict,)
+ *         use_setstate = True             # <<<<<<<<<<<<<<
+ *     else:
+ *         use_setstate = self._custom_type_codecs is not None or self._derived_type_codecs is not None
+ */
+    __pyx_v_use_setstate = 1;
+
+    /* "(tree fragment)":5
+ *     state = (self._custom_type_codecs, self._derived_type_codecs)
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+    goto __pyx_L3;
+  }
+
+  /* "(tree fragment)":9
+ *         use_setstate = True
+ *     else:
+ *         use_setstate = self._custom_type_codecs is not None or self._derived_type_codecs is not None             # <<<<<<<<<<<<<<
+ *     if use_setstate:
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, None), state
+ */
+  /*else*/ {
+    __pyx_t_2 = (__pyx_v_self->_custom_type_codecs != ((PyObject*)Py_None));
+    __pyx_t_5 = (__pyx_t_2 != 0);
+    if (!__pyx_t_5) {
+    } else {
+      __pyx_t_3 = __pyx_t_5;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_5 = (__pyx_v_self->_derived_type_codecs != ((PyObject*)Py_None));
+    __pyx_t_2 = (__pyx_t_5 != 0);
+    __pyx_t_3 = __pyx_t_2;
+    __pyx_L4_bool_binop_done:;
+    __pyx_v_use_setstate = __pyx_t_3;
+  }
+  __pyx_L3:;
+
+  /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = self._custom_type_codecs is not None or self._derived_type_codecs is not None
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, None), state
+ *     else:
+ */
+  __pyx_t_3 = (__pyx_v_use_setstate != 0);
+  if (__pyx_t_3) {
+
+    /* "(tree fragment)":11
+ *         use_setstate = self._custom_type_codecs is not None or self._derived_type_codecs is not None
+ *     if use_setstate:
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, None), state             # <<<<<<<<<<<<<<
+ *     else:
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, state)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_DataCodecConfig); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_120810133);
+    __Pyx_GIVEREF(__pyx_int_120810133);
+    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_120810133);
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
+    __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_state);
+    __pyx_t_4 = 0;
+    __pyx_t_1 = 0;
+    __pyx_r = __pyx_t_6;
+    __pyx_t_6 = 0;
+    goto __pyx_L0;
+
+    /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = self._custom_type_codecs is not None or self._derived_type_codecs is not None
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, None), state
+ *     else:
+ */
+  }
+
+  /* "(tree fragment)":13
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, None), state
+ *     else:
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, state)             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_DataCodecConfig__set_state(self, __pyx_state)
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pyx_unpickle_DataCodecConfig); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_120810133);
+    __Pyx_GIVEREF(__pyx_int_120810133);
+    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_120810133);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state);
+    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
+    __pyx_t_6 = 0;
+    __pyx_t_1 = 0;
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = (self._custom_type_codecs, self._derived_type_codecs)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_state);
+  __Pyx_XDECREF(__pyx_v__dict);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_DataCodecConfig__set_state(self, __pyx_state)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_18__setstate_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_15DataCodecConfig_18__setstate_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":15
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, state)
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_DataCodecConfig__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
+ */
+  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error)
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_DataCodecConfig__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_DataCodecConfig, (type(self), 0x7336a95, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_DataCodecConfig__set_state(self, __pyx_state)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.DataCodecConfig.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":726
+ * 
+ * 
+ * cdef inline Codec get_core_codec(             # <<<<<<<<<<<<<<
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ */
+
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(uint32_t __pyx_v_oid, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_core_codec *__pyx_optional_args) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat = __pyx_k__12;
+  void *__pyx_v_ptr;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("get_core_codec", 0);
+  if (__pyx_optional_args) {
+    if (__pyx_optional_args->__pyx_n > 0) {
+      __pyx_v_xformat = __pyx_optional_args->xformat;
+    }
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":730
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ *     cdef:
+ *         void *ptr = NULL             # <<<<<<<<<<<<<<
+ * 
+ *     if oid > MAXSUPPORTEDOID:
+ */
+  __pyx_v_ptr = NULL;
+
+  /* "asyncpg/protocol/codecs/base.pyx":732
+ *         void *ptr = NULL
+ * 
+ *     if oid > MAXSUPPORTEDOID:             # <<<<<<<<<<<<<<
+ *         return None
+ *     if format == PG_FORMAT_BINARY:
+ */
+  __pyx_t_1 = ((__pyx_v_oid > 0x1000) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":733
+ * 
+ *     if oid > MAXSUPPORTEDOID:
+ *         return None             # <<<<<<<<<<<<<<
+ *     if format == PG_FORMAT_BINARY:
+ *         ptr = binary_codec_map[oid * xformat]
+ */
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None); __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":732
+ *         void *ptr = NULL
+ * 
+ *     if oid > MAXSUPPORTEDOID:             # <<<<<<<<<<<<<<
+ *         return None
+ *     if format == PG_FORMAT_BINARY:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":734
+ *     if oid > MAXSUPPORTEDOID:
+ *         return None
+ *     if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *         ptr = binary_codec_map[oid * xformat]
+ *     elif format == PG_FORMAT_TEXT:
+ */
+  switch (__pyx_v_format) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY:
+
+    /* "asyncpg/protocol/codecs/base.pyx":735
+ *         return None
+ *     if format == PG_FORMAT_BINARY:
+ *         ptr = binary_codec_map[oid * xformat]             # <<<<<<<<<<<<<<
+ *     elif format == PG_FORMAT_TEXT:
+ *         ptr = text_codec_map[oid * xformat]
+ */
+    __pyx_v_ptr = (__pyx_v_7asyncpg_8protocol_8protocol_binary_codec_map[(__pyx_v_oid * __pyx_v_xformat)]);
+
+    /* "asyncpg/protocol/codecs/base.pyx":734
+ *     if oid > MAXSUPPORTEDOID:
+ *         return None
+ *     if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *         ptr = binary_codec_map[oid * xformat]
+ *     elif format == PG_FORMAT_TEXT:
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT:
+
+    /* "asyncpg/protocol/codecs/base.pyx":737
+ *         ptr = binary_codec_map[oid * xformat]
+ *     elif format == PG_FORMAT_TEXT:
+ *         ptr = text_codec_map[oid * xformat]             # <<<<<<<<<<<<<<
+ * 
+ *     if ptr is NULL:
+ */
+    __pyx_v_ptr = (__pyx_v_7asyncpg_8protocol_8protocol_text_codec_map[(__pyx_v_oid * __pyx_v_xformat)]);
+
+    /* "asyncpg/protocol/codecs/base.pyx":736
+ *     if format == PG_FORMAT_BINARY:
+ *         ptr = binary_codec_map[oid * xformat]
+ *     elif format == PG_FORMAT_TEXT:             # <<<<<<<<<<<<<<
+ *         ptr = text_codec_map[oid * xformat]
+ * 
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":739
+ *         ptr = text_codec_map[oid * xformat]
+ * 
+ *     if ptr is NULL:             # <<<<<<<<<<<<<<
+ *         return None
+ *     else:
+ */
+  __pyx_t_1 = ((__pyx_v_ptr == NULL) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":740
+ * 
+ *     if ptr is NULL:
+ *         return None             # <<<<<<<<<<<<<<
+ *     else:
+ *         return <Codec>ptr
+ */
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None); __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":739
+ *         ptr = text_codec_map[oid * xformat]
+ * 
+ *     if ptr is NULL:             # <<<<<<<<<<<<<<
+ *         return None
+ *     else:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":742
+ *         return None
+ *     else:
+ *         return <Codec>ptr             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __Pyx_XDECREF(((PyObject *)__pyx_r));
+    __Pyx_INCREF(((PyObject *)((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_ptr)));
+    __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_v_ptr);
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":726
+ * 
+ * 
+ * cdef inline Codec get_core_codec(             # <<<<<<<<<<<<<<
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":745
+ * 
+ * 
+ * cdef inline Codec get_any_core_codec(             # <<<<<<<<<<<<<<
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ */
+
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_get_any_core_codec(uint32_t __pyx_v_oid, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_any_core_codec *__pyx_optional_args) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat = __pyx_k__13;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  struct __pyx_opt_args_7asyncpg_8protocol_8protocol_get_core_codec __pyx_t_3;
+  int __pyx_t_4;
+  __Pyx_RefNannySetupContext("get_any_core_codec", 0);
+  if (__pyx_optional_args) {
+    if (__pyx_optional_args->__pyx_n > 0) {
+      __pyx_v_xformat = __pyx_optional_args->xformat;
+    }
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":752
+ *         Codec codec
+ * 
+ *     if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *         codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)
+ *         if codec is None:
+ */
+  __pyx_t_1 = ((__pyx_v_format == __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":753
+ * 
+ *     if format == PG_FORMAT_ANY:
+ *         codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)             # <<<<<<<<<<<<<<
+ *         if codec is None:
+ *             codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat)
+ */
+    __pyx_t_3.__pyx_n = 1;
+    __pyx_t_3.xformat = __pyx_v_xformat;
+    __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(__pyx_v_oid, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 753, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":754
+ *     if format == PG_FORMAT_ANY:
+ *         codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)
+ *         if codec is None:             # <<<<<<<<<<<<<<
+ *             codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat)
+ *     else:
+ */
+    __pyx_t_1 = (((PyObject *)__pyx_v_codec) == Py_None);
+    __pyx_t_4 = (__pyx_t_1 != 0);
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/codecs/base.pyx":755
+ *         codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)
+ *         if codec is None:
+ *             codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat)             # <<<<<<<<<<<<<<
+ *     else:
+ *         codec = get_core_codec(oid, format, xformat)
+ */
+      __pyx_t_3.__pyx_n = 1;
+      __pyx_t_3.xformat = __pyx_v_xformat;
+      __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(__pyx_v_oid, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, &__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 755, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2));
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/base.pyx":754
+ *     if format == PG_FORMAT_ANY:
+ *         codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)
+ *         if codec is None:             # <<<<<<<<<<<<<<
+ *             codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat)
+ *     else:
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/base.pyx":752
+ *         Codec codec
+ * 
+ *     if format == PG_FORMAT_ANY:             # <<<<<<<<<<<<<<
+ *         codec = get_core_codec(oid, PG_FORMAT_BINARY, xformat)
+ *         if codec is None:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":757
+ *             codec = get_core_codec(oid, PG_FORMAT_TEXT, xformat)
+ *     else:
+ *         codec = get_core_codec(oid, format, xformat)             # <<<<<<<<<<<<<<
+ * 
+ *     return codec
+ */
+  /*else*/ {
+    __pyx_t_3.__pyx_n = 1;
+    __pyx_t_3.xformat = __pyx_v_xformat;
+    __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_get_core_codec(__pyx_v_oid, __pyx_v_format, &__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 757, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+    __pyx_t_2 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/codecs/base.pyx":759
+ *         codec = get_core_codec(oid, format, xformat)
+ * 
+ *     return codec             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_codec));
+  __pyx_r = __pyx_v_codec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":745
+ * 
+ * 
+ * cdef inline Codec get_any_core_codec(             # <<<<<<<<<<<<<<
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.get_any_core_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":762
+ * 
+ * 
+ * cdef inline int has_core_codec(uint32_t oid):             # <<<<<<<<<<<<<<
+ *     return binary_codec_map[oid] != NULL or text_codec_map[oid] != NULL
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol_has_core_codec(uint32_t __pyx_v_oid) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("has_core_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":763
+ * 
+ * cdef inline int has_core_codec(uint32_t oid):
+ *     return binary_codec_map[oid] != NULL or text_codec_map[oid] != NULL             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_7asyncpg_8protocol_8protocol_binary_codec_map[__pyx_v_oid]) != NULL);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __pyx_t_2 = ((__pyx_v_7asyncpg_8protocol_8protocol_text_codec_map[__pyx_v_oid]) != NULL);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L3_bool_binop_done:;
+  __pyx_r = __pyx_t_1;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":762
+ * 
+ * 
+ * cdef inline int has_core_codec(uint32_t oid):             # <<<<<<<<<<<<<<
+ *     return binary_codec_map[oid] != NULL or text_codec_map[oid] != NULL
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":766
+ * 
+ * 
+ * cdef register_core_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                          encode_func encode,
+ *                          decode_func decode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(uint32_t __pyx_v_oid, __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_encode, __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_decode, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_register_core_codec *__pyx_optional_args) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __pyx_v_xformat = __pyx_k__14;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_name = 0;
+  PyObject *__pyx_v_kind = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  __Pyx_RefNannySetupContext("register_core_codec", 0);
+  if (__pyx_optional_args) {
+    if (__pyx_optional_args->__pyx_n > 0) {
+      __pyx_v_xformat = __pyx_optional_args->xformat;
+    }
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":772
+ *                          ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ * 
+ *     if oid > MAXSUPPORTEDOID:             # <<<<<<<<<<<<<<
+ *         raise exceptions.InternalClientError(
+ *             'cannot register core codec for OID {}: it is greater '
+ */
+  __pyx_t_1 = ((__pyx_v_oid > 0x1000) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/protocol/codecs/base.pyx":773
+ * 
+ *     if oid > MAXSUPPORTEDOID:
+ *         raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *             'cannot register core codec for OID {}: it is greater '
+ *             'than MAXSUPPORTEDOID ({})'.format(oid, MAXSUPPORTEDOID))
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 773, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 773, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":775
+ *         raise exceptions.InternalClientError(
+ *             'cannot register core codec for OID {}: it is greater '
+ *             'than MAXSUPPORTEDOID ({})'.format(oid, MAXSUPPORTEDOID))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef:
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_cannot_register_core_codec_for_O, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 775, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 775, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = NULL;
+    __pyx_t_8 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_7)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+        __pyx_t_8 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_int_4096};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 775, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_int_4096};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 775, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 775, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      if (__pyx_t_7) {
+        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_6);
+      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
+      __Pyx_INCREF(__pyx_int_4096);
+      __Pyx_GIVEREF(__pyx_int_4096);
+      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_int_4096);
+      __pyx_t_6 = 0;
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 775, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 773, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(3, 773, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/base.pyx":772
+ *                          ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):
+ * 
+ *     if oid > MAXSUPPORTEDOID:             # <<<<<<<<<<<<<<
+ *         raise exceptions.InternalClientError(
+ *             'cannot register core codec for OID {}: it is greater '
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":782
+ *         str kind
+ * 
+ *     name = BUILTIN_TYPE_OID_MAP[oid]             # <<<<<<<<<<<<<<
+ *     kind = 'array' if oid in ARRAY_TYPES else 'scalar'
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_OID_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 782, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, __pyx_v_oid, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 782, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(3, 782, __pyx_L1_error)
+  __pyx_v_name = ((PyObject*)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":783
+ * 
+ *     name = BUILTIN_TYPE_OID_MAP[oid]
+ *     kind = 'array' if oid in ARRAY_TYPES else 'scalar'             # <<<<<<<<<<<<<<
+ * 
+ *     codec = Codec(oid)
+ */
+  __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 783, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_7asyncpg_8protocol_8protocol_ARRAY_TYPES, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(3, 783, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if ((__pyx_t_1 != 0)) {
+    __Pyx_INCREF(__pyx_n_u_array);
+    __pyx_t_4 = __pyx_n_u_array;
+  } else {
+    __Pyx_INCREF(__pyx_n_u_scalar);
+    __pyx_t_4 = __pyx_n_u_scalar;
+  }
+  __pyx_v_kind = ((PyObject*)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":785
+ *     kind = 'array' if oid in ARRAY_TYPES else 'scalar'
+ * 
+ *     codec = Codec(oid)             # <<<<<<<<<<<<<<
+ *     codec.init(name, 'pg_catalog', kind, CODEC_C, format, xformat,
+ *                encode, decode, None, None, None, None, None, None, 0)
+ */
+  __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 785, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 785, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":786
+ * 
+ *     codec = Codec(oid)
+ *     codec.init(name, 'pg_catalog', kind, CODEC_C, format, xformat,             # <<<<<<<<<<<<<<
+ *                encode, decode, None, None, None, None, None, None, 0)
+ *     cpython.Py_INCREF(codec)  # immortalize
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, __pyx_v_name, __pyx_n_u_pg_catalog, __pyx_v_kind, __pyx_e_7asyncpg_8protocol_8protocol_CODEC_C, __pyx_v_format, __pyx_v_xformat, __pyx_v_encode, __pyx_v_decode, Py_None, Py_None, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None), ((PyObject*)Py_None), Py_None, ((PyObject*)Py_None), 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 786, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":788
+ *     codec.init(name, 'pg_catalog', kind, CODEC_C, format, xformat,
+ *                encode, decode, None, None, None, None, None, None, 0)
+ *     cpython.Py_INCREF(codec)  # immortalize             # <<<<<<<<<<<<<<
+ * 
+ *     if format == PG_FORMAT_BINARY:
+ */
+  Py_INCREF(((PyObject *)__pyx_v_codec));
+
+  /* "asyncpg/protocol/codecs/base.pyx":790
+ *     cpython.Py_INCREF(codec)  # immortalize
+ * 
+ *     if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *         binary_codec_map[oid * xformat] = <void*>codec
+ *     elif format == PG_FORMAT_TEXT:
+ */
+  switch (__pyx_v_format) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY:
+
+    /* "asyncpg/protocol/codecs/base.pyx":791
+ * 
+ *     if format == PG_FORMAT_BINARY:
+ *         binary_codec_map[oid * xformat] = <void*>codec             # <<<<<<<<<<<<<<
+ *     elif format == PG_FORMAT_TEXT:
+ *         text_codec_map[oid * xformat] = <void*>codec
+ */
+    (__pyx_v_7asyncpg_8protocol_8protocol_binary_codec_map[(__pyx_v_oid * __pyx_v_xformat)]) = ((void *)__pyx_v_codec);
+
+    /* "asyncpg/protocol/codecs/base.pyx":790
+ *     cpython.Py_INCREF(codec)  # immortalize
+ * 
+ *     if format == PG_FORMAT_BINARY:             # <<<<<<<<<<<<<<
+ *         binary_codec_map[oid * xformat] = <void*>codec
+ *     elif format == PG_FORMAT_TEXT:
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT:
+
+    /* "asyncpg/protocol/codecs/base.pyx":793
+ *         binary_codec_map[oid * xformat] = <void*>codec
+ *     elif format == PG_FORMAT_TEXT:
+ *         text_codec_map[oid * xformat] = <void*>codec             # <<<<<<<<<<<<<<
+ *     else:
+ *         raise exceptions.InternalClientError(
+ */
+    (__pyx_v_7asyncpg_8protocol_8protocol_text_codec_map[(__pyx_v_oid * __pyx_v_xformat)]) = ((void *)__pyx_v_codec);
+
+    /* "asyncpg/protocol/codecs/base.pyx":792
+ *     if format == PG_FORMAT_BINARY:
+ *         binary_codec_map[oid * xformat] = <void*>codec
+ *     elif format == PG_FORMAT_TEXT:             # <<<<<<<<<<<<<<
+ *         text_codec_map[oid * xformat] = <void*>codec
+ *     else:
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/codecs/base.pyx":795
+ *         text_codec_map[oid * xformat] = <void*>codec
+ *     else:
+ *         raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *             'invalid data format: {}'.format(format))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 795, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 795, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/base.pyx":796
+ *     else:
+ *         raise exceptions.InternalClientError(
+ *             'invalid data format: {}'.format(format))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_data_format, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 796, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_9 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 796, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 796, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 795, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(3, 795, __pyx_L1_error)
+    break;
+  }
+
+  /* "asyncpg/protocol/codecs/base.pyx":766
+ * 
+ * 
+ * cdef register_core_codec(uint32_t oid,             # <<<<<<<<<<<<<<
+ *                          encode_func encode,
+ *                          decode_func decode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.register_core_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_name);
+  __Pyx_XDECREF(__pyx_v_kind);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":799
+ * 
+ * 
+ * cdef register_extra_codec(str name,             # <<<<<<<<<<<<<<
+ *                           encode_func encode,
+ *                           decode_func decode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_register_extra_codec(PyObject *__pyx_v_name, __pyx_t_7asyncpg_8protocol_8protocol_encode_func __pyx_v_encode, __pyx_t_7asyncpg_8protocol_8protocol_decode_func __pyx_v_decode, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_kind = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("register_extra_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":807
+ *         str kind
+ * 
+ *     kind = 'scalar'             # <<<<<<<<<<<<<<
+ * 
+ *     codec = Codec(INVALIDOID)
+ */
+  __Pyx_INCREF(__pyx_n_u_scalar);
+  __pyx_v_kind = __pyx_n_u_scalar;
+
+  /* "asyncpg/protocol/codecs/base.pyx":809
+ *     kind = 'scalar'
+ * 
+ *     codec = Codec(INVALIDOID)             # <<<<<<<<<<<<<<
+ *     codec.init(name, None, kind, CODEC_C, format, PG_XFORMAT_OBJECT,
+ *                encode, decode, None, None, None, None, None, None, 0)
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_Codec), __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 809, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":810
+ * 
+ *     codec = Codec(INVALIDOID)
+ *     codec.init(name, None, kind, CODEC_C, format, PG_XFORMAT_OBJECT,             # <<<<<<<<<<<<<<
+ *                encode, decode, None, None, None, None, None, None, 0)
+ *     EXTRA_CODECS[name, format] = codec
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_init(__pyx_v_codec, __pyx_v_name, ((PyObject*)Py_None), __pyx_v_kind, __pyx_e_7asyncpg_8protocol_8protocol_CODEC_C, __pyx_v_format, __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT, __pyx_v_encode, __pyx_v_decode, Py_None, Py_None, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None), ((PyObject*)Py_None), Py_None, ((PyObject*)Py_None), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 810, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":812
+ *     codec.init(name, None, kind, CODEC_C, format, PG_XFORMAT_OBJECT,
+ *                encode, decode, None, None, None, None, None, None, 0)
+ *     EXTRA_CODECS[name, format] = codec             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  if (unlikely(__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(3, 812, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 812, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 812, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_v_name);
+  __Pyx_GIVEREF(__pyx_v_name);
+  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_name);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(PyDict_SetItem(__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS, __pyx_t_2, ((PyObject *)__pyx_v_codec)) < 0)) __PYX_ERR(3, 812, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":799
+ * 
+ * 
+ * cdef register_extra_codec(str name,             # <<<<<<<<<<<<<<
+ *                           encode_func encode,
+ *                           decode_func decode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.register_extra_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_kind);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/base.pyx":815
+ * 
+ * 
+ * cdef inline Codec get_extra_codec(str name, ServerDataFormat format):             # <<<<<<<<<<<<<<
+ *     return EXTRA_CODECS.get((name, format))
+ */
+
+static CYTHON_INLINE struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_f_7asyncpg_8protocol_8protocol_get_extra_codec(PyObject *__pyx_v_name, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __pyx_v_format) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("get_extra_codec", 0);
+
+  /* "asyncpg/protocol/codecs/base.pyx":816
+ * 
+ * cdef inline Codec get_extra_codec(str name, ServerDataFormat format):
+ *     return EXTRA_CODECS.get((name, format))             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  if (unlikely(__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS == Py_None)) {
+    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get");
+    __PYX_ERR(3, 816, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_v_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 816, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 816, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_v_name);
+  __Pyx_GIVEREF(__pyx_v_name);
+  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_name);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
+  __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 816, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(3, 816, __pyx_L1_error)
+  __pyx_r = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_1);
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":815
+ * 
+ * 
+ * cdef inline Codec get_extra_codec(str name, ServerDataFormat format):             # <<<<<<<<<<<<<<
+ *     return EXTRA_CODECS.get((name, format))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.get_extra_codec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/textutils.pyx":8
+ * 
+ * 
+ * cdef inline uint32_t _apg_tolower(uint32_t c):             # <<<<<<<<<<<<<<
+ *     if c >= <uint32_t><Py_UCS4>'A' and c <= <uint32_t><Py_UCS4>'Z':
+ *         return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'
+ */
+
+static CYTHON_INLINE uint32_t __pyx_f_7asyncpg_8protocol_8protocol__apg_tolower(uint32_t __pyx_v_c) {
+  uint32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("_apg_tolower", 0);
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":9
+ * 
+ * cdef inline uint32_t _apg_tolower(uint32_t c):
+ *     if c >= <uint32_t><Py_UCS4>'A' and c <= <uint32_t><Py_UCS4>'Z':             # <<<<<<<<<<<<<<
+ *         return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'
+ *     else:
+ */
+  __pyx_t_2 = ((__pyx_v_c >= ((uint32_t)((Py_UCS4)65))) != 0);
+  if (__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = ((__pyx_v_c <= ((uint32_t)((Py_UCS4)90))) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":10
+ * cdef inline uint32_t _apg_tolower(uint32_t c):
+ *     if c >= <uint32_t><Py_UCS4>'A' and c <= <uint32_t><Py_UCS4>'Z':
+ *         return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'             # <<<<<<<<<<<<<<
+ *     else:
+ *         return c
+ */
+    __pyx_r = ((__pyx_v_c + ((uint32_t)((Py_UCS4)97))) - ((uint32_t)((Py_UCS4)65)));
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":9
+ * 
+ * cdef inline uint32_t _apg_tolower(uint32_t c):
+ *     if c >= <uint32_t><Py_UCS4>'A' and c <= <uint32_t><Py_UCS4>'Z':             # <<<<<<<<<<<<<<
+ *         return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'
+ *     else:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":12
+ *         return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'
+ *     else:
+ *         return c             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __pyx_r = __pyx_v_c;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":8
+ * 
+ * 
+ * cdef inline uint32_t _apg_tolower(uint32_t c):             # <<<<<<<<<<<<<<
+ *     if c >= <uint32_t><Py_UCS4>'A' and c <= <uint32_t><Py_UCS4>'Z':
+ *         return c + <uint32_t><Py_UCS4>'a' - <uint32_t><Py_UCS4>'A'
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/textutils.pyx":15
+ * 
+ * 
+ * cdef int apg_strcasecmp(const Py_UCS4 *s1, const Py_UCS4 *s2):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint32_t c1
+ */
+
+static int __pyx_f_7asyncpg_8protocol_8protocol_apg_strcasecmp(Py_UCS4 const *__pyx_v_s1, Py_UCS4 const *__pyx_v_s2) {
+  uint32_t __pyx_v_c1;
+  uint32_t __pyx_v_c2;
+  int __pyx_v_i;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("apg_strcasecmp", 0);
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":19
+ *         uint32_t c1
+ *         uint32_t c2
+ *         int i = 0             # <<<<<<<<<<<<<<
+ * 
+ *     while True:
+ */
+  __pyx_v_i = 0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":21
+ *         int i = 0
+ * 
+ *     while True:             # <<<<<<<<<<<<<<
+ *         c1 = s1[i]
+ *         c2 = s2[i]
+ */
+  while (1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":22
+ * 
+ *     while True:
+ *         c1 = s1[i]             # <<<<<<<<<<<<<<
+ *         c2 = s2[i]
+ * 
+ */
+    __pyx_v_c1 = (__pyx_v_s1[__pyx_v_i]);
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":23
+ *     while True:
+ *         c1 = s1[i]
+ *         c2 = s2[i]             # <<<<<<<<<<<<<<
+ * 
+ *         if c1 != c2:
+ */
+    __pyx_v_c2 = (__pyx_v_s2[__pyx_v_i]);
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":25
+ *         c2 = s2[i]
+ * 
+ *         if c1 != c2:             # <<<<<<<<<<<<<<
+ *             c1 = _apg_tolower(c1)
+ *             c2 = _apg_tolower(c2)
+ */
+    __pyx_t_1 = ((__pyx_v_c1 != __pyx_v_c2) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":26
+ * 
+ *         if c1 != c2:
+ *             c1 = _apg_tolower(c1)             # <<<<<<<<<<<<<<
+ *             c2 = _apg_tolower(c2)
+ *             if c1 != c2:
+ */
+      __pyx_v_c1 = __pyx_f_7asyncpg_8protocol_8protocol__apg_tolower(__pyx_v_c1);
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":27
+ *         if c1 != c2:
+ *             c1 = _apg_tolower(c1)
+ *             c2 = _apg_tolower(c2)             # <<<<<<<<<<<<<<
+ *             if c1 != c2:
+ *                 return <int32_t>c1 - <int32_t>c2
+ */
+      __pyx_v_c2 = __pyx_f_7asyncpg_8protocol_8protocol__apg_tolower(__pyx_v_c2);
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":28
+ *             c1 = _apg_tolower(c1)
+ *             c2 = _apg_tolower(c2)
+ *             if c1 != c2:             # <<<<<<<<<<<<<<
+ *                 return <int32_t>c1 - <int32_t>c2
+ * 
+ */
+      __pyx_t_1 = ((__pyx_v_c1 != __pyx_v_c2) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/textutils.pyx":29
+ *             c2 = _apg_tolower(c2)
+ *             if c1 != c2:
+ *                 return <int32_t>c1 - <int32_t>c2             # <<<<<<<<<<<<<<
+ * 
+ *         if c1 == 0 or c2 == 0:
+ */
+        __pyx_r = (((int32_t)__pyx_v_c1) - ((int32_t)__pyx_v_c2));
+        goto __pyx_L0;
+
+        /* "asyncpg/protocol/codecs/textutils.pyx":28
+ *             c1 = _apg_tolower(c1)
+ *             c2 = _apg_tolower(c2)
+ *             if c1 != c2:             # <<<<<<<<<<<<<<
+ *                 return <int32_t>c1 - <int32_t>c2
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":25
+ *         c2 = s2[i]
+ * 
+ *         if c1 != c2:             # <<<<<<<<<<<<<<
+ *             c1 = _apg_tolower(c1)
+ *             c2 = _apg_tolower(c2)
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":31
+ *                 return <int32_t>c1 - <int32_t>c2
+ * 
+ *         if c1 == 0 or c2 == 0:             # <<<<<<<<<<<<<<
+ *             break
+ * 
+ */
+    __pyx_t_2 = ((__pyx_v_c1 == 0) != 0);
+    if (!__pyx_t_2) {
+    } else {
+      __pyx_t_1 = __pyx_t_2;
+      goto __pyx_L8_bool_binop_done;
+    }
+    __pyx_t_2 = ((__pyx_v_c2 == 0) != 0);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_L8_bool_binop_done:;
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":32
+ * 
+ *         if c1 == 0 or c2 == 0:
+ *             break             # <<<<<<<<<<<<<<
+ * 
+ *         i += 1
+ */
+      goto __pyx_L4_break;
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":31
+ *                 return <int32_t>c1 - <int32_t>c2
+ * 
+ *         if c1 == 0 or c2 == 0:             # <<<<<<<<<<<<<<
+ *             break
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":34
+ *             break
+ * 
+ *         i += 1             # <<<<<<<<<<<<<<
+ * 
+ *     return 0
+ */
+    __pyx_v_i = (__pyx_v_i + 1);
+  }
+  __pyx_L4_break:;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":36
+ *         i += 1
+ * 
+ *     return 0             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":15
+ * 
+ * 
+ * cdef int apg_strcasecmp(const Py_UCS4 *s1, const Py_UCS4 *s2):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint32_t c1
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/textutils.pyx":39
+ * 
+ * 
+ * cdef int apg_strcasecmp_char(const char *s1, const char *s2):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint8_t c1
+ */
+
+static int __pyx_f_7asyncpg_8protocol_8protocol_apg_strcasecmp_char(char const *__pyx_v_s1, char const *__pyx_v_s2) {
+  uint8_t __pyx_v_c1;
+  uint8_t __pyx_v_c2;
+  int __pyx_v_i;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("apg_strcasecmp_char", 0);
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":43
+ *         uint8_t c1
+ *         uint8_t c2
+ *         int i = 0             # <<<<<<<<<<<<<<
+ * 
+ *     while True:
+ */
+  __pyx_v_i = 0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":45
+ *         int i = 0
+ * 
+ *     while True:             # <<<<<<<<<<<<<<
+ *         c1 = <uint8_t>s1[i]
+ *         c2 = <uint8_t>s2[i]
+ */
+  while (1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":46
+ * 
+ *     while True:
+ *         c1 = <uint8_t>s1[i]             # <<<<<<<<<<<<<<
+ *         c2 = <uint8_t>s2[i]
+ * 
+ */
+    __pyx_v_c1 = ((uint8_t)(__pyx_v_s1[__pyx_v_i]));
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":47
+ *     while True:
+ *         c1 = <uint8_t>s1[i]
+ *         c2 = <uint8_t>s2[i]             # <<<<<<<<<<<<<<
+ * 
+ *         if c1 != c2:
+ */
+    __pyx_v_c2 = ((uint8_t)(__pyx_v_s2[__pyx_v_i]));
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":49
+ *         c2 = <uint8_t>s2[i]
+ * 
+ *         if c1 != c2:             # <<<<<<<<<<<<<<
+ *             c1 = <uint8_t>_apg_tolower(c1)
+ *             c2 = <uint8_t>_apg_tolower(c2)
+ */
+    __pyx_t_1 = ((__pyx_v_c1 != __pyx_v_c2) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":50
+ * 
+ *         if c1 != c2:
+ *             c1 = <uint8_t>_apg_tolower(c1)             # <<<<<<<<<<<<<<
+ *             c2 = <uint8_t>_apg_tolower(c2)
+ *             if c1 != c2:
+ */
+      __pyx_v_c1 = ((uint8_t)__pyx_f_7asyncpg_8protocol_8protocol__apg_tolower(__pyx_v_c1));
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":51
+ *         if c1 != c2:
+ *             c1 = <uint8_t>_apg_tolower(c1)
+ *             c2 = <uint8_t>_apg_tolower(c2)             # <<<<<<<<<<<<<<
+ *             if c1 != c2:
+ *                 return <int8_t>c1 - <int8_t>c2
+ */
+      __pyx_v_c2 = ((uint8_t)__pyx_f_7asyncpg_8protocol_8protocol__apg_tolower(__pyx_v_c2));
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":52
+ *             c1 = <uint8_t>_apg_tolower(c1)
+ *             c2 = <uint8_t>_apg_tolower(c2)
+ *             if c1 != c2:             # <<<<<<<<<<<<<<
+ *                 return <int8_t>c1 - <int8_t>c2
+ * 
+ */
+      __pyx_t_1 = ((__pyx_v_c1 != __pyx_v_c2) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/textutils.pyx":53
+ *             c2 = <uint8_t>_apg_tolower(c2)
+ *             if c1 != c2:
+ *                 return <int8_t>c1 - <int8_t>c2             # <<<<<<<<<<<<<<
+ * 
+ *         if c1 == 0 or c2 == 0:
+ */
+        __pyx_r = (((int8_t)__pyx_v_c1) - ((int8_t)__pyx_v_c2));
+        goto __pyx_L0;
+
+        /* "asyncpg/protocol/codecs/textutils.pyx":52
+ *             c1 = <uint8_t>_apg_tolower(c1)
+ *             c2 = <uint8_t>_apg_tolower(c2)
+ *             if c1 != c2:             # <<<<<<<<<<<<<<
+ *                 return <int8_t>c1 - <int8_t>c2
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":49
+ *         c2 = <uint8_t>s2[i]
+ * 
+ *         if c1 != c2:             # <<<<<<<<<<<<<<
+ *             c1 = <uint8_t>_apg_tolower(c1)
+ *             c2 = <uint8_t>_apg_tolower(c2)
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":55
+ *                 return <int8_t>c1 - <int8_t>c2
+ * 
+ *         if c1 == 0 or c2 == 0:             # <<<<<<<<<<<<<<
+ *             break
+ * 
+ */
+    __pyx_t_2 = ((__pyx_v_c1 == 0) != 0);
+    if (!__pyx_t_2) {
+    } else {
+      __pyx_t_1 = __pyx_t_2;
+      goto __pyx_L8_bool_binop_done;
+    }
+    __pyx_t_2 = ((__pyx_v_c2 == 0) != 0);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_L8_bool_binop_done:;
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":56
+ * 
+ *         if c1 == 0 or c2 == 0:
+ *             break             # <<<<<<<<<<<<<<
+ * 
+ *         i += 1
+ */
+      goto __pyx_L4_break;
+
+      /* "asyncpg/protocol/codecs/textutils.pyx":55
+ *                 return <int8_t>c1 - <int8_t>c2
+ * 
+ *         if c1 == 0 or c2 == 0:             # <<<<<<<<<<<<<<
+ *             break
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":58
+ *             break
+ * 
+ *         i += 1             # <<<<<<<<<<<<<<
+ * 
+ *     return 0
+ */
+    __pyx_v_i = (__pyx_v_i + 1);
+  }
+  __pyx_L4_break:;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":60
+ *         i += 1
+ * 
+ *     return 0             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":39
+ * 
+ * 
+ * cdef int apg_strcasecmp_char(const char *s1, const char *s2):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         uint8_t c1
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/textutils.pyx":63
+ * 
+ * 
+ * cdef inline bint apg_ascii_isspace(Py_UCS4 ch):             # <<<<<<<<<<<<<<
+ *     return (
+ *         ch == ' ' or
+ */
+
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace(Py_UCS4 __pyx_v_ch) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  __Pyx_RefNannySetupContext("apg_ascii_isspace", 0);
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":65
+ * cdef inline bint apg_ascii_isspace(Py_UCS4 ch):
+ *     return (
+ *         ch == ' ' or             # <<<<<<<<<<<<<<
+ *         ch == '\n' or
+ *         ch == '\r' or
+ */
+  switch (__pyx_v_ch) {
+    case 32:
+    case 10:
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":66
+ *     return (
+ *         ch == ' ' or
+ *         ch == '\n' or             # <<<<<<<<<<<<<<
+ *         ch == '\r' or
+ *         ch == '\t' or
+ */
+    case 13:
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":67
+ *         ch == ' ' or
+ *         ch == '\n' or
+ *         ch == '\r' or             # <<<<<<<<<<<<<<
+ *         ch == '\t' or
+ *         ch == '\v' or
+ */
+    case 9:
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":68
+ *         ch == '\n' or
+ *         ch == '\r' or
+ *         ch == '\t' or             # <<<<<<<<<<<<<<
+ *         ch == '\v' or
+ *         ch == '\f'
+ */
+    case 11:
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":69
+ *         ch == '\r' or
+ *         ch == '\t' or
+ *         ch == '\v' or             # <<<<<<<<<<<<<<
+ *         ch == '\f'
+ *     )
+ */
+    case 12:
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":65
+ * cdef inline bint apg_ascii_isspace(Py_UCS4 ch):
+ *     return (
+ *         ch == ' ' or             # <<<<<<<<<<<<<<
+ *         ch == '\n' or
+ *         ch == '\r' or
+ */
+    __pyx_t_1 = 1;
+    break;
+    default:
+    __pyx_t_1 = 0;
+    break;
+  }
+  __pyx_r = __pyx_t_1;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":63
+ * 
+ * 
+ * cdef inline bint apg_ascii_isspace(Py_UCS4 ch):             # <<<<<<<<<<<<<<
+ *     return (
+ *         ch == ' ' or
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/textutils.pyx":74
+ * 
+ * 
+ * cdef Py_UCS4 *apg_parse_int32(Py_UCS4 *buf, int32_t *num):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         Py_UCS4 *p
+ */
+
+static Py_UCS4 *__pyx_f_7asyncpg_8protocol_8protocol_apg_parse_int32(Py_UCS4 *__pyx_v_buf, int32_t *__pyx_v_num) {
+  Py_UCS4 *__pyx_v_p;
+  int32_t __pyx_v_n;
+  int32_t __pyx_v_neg;
+  Py_UCS4 *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("apg_parse_int32", 0);
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":77
+ *     cdef:
+ *         Py_UCS4 *p
+ *         int32_t n = 0             # <<<<<<<<<<<<<<
+ *         int32_t neg = 0
+ * 
+ */
+  __pyx_v_n = 0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":78
+ *         Py_UCS4 *p
+ *         int32_t n = 0
+ *         int32_t neg = 0             # <<<<<<<<<<<<<<
+ * 
+ *     if buf[0] == '-':
+ */
+  __pyx_v_neg = 0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":80
+ *         int32_t neg = 0
+ * 
+ *     if buf[0] == '-':             # <<<<<<<<<<<<<<
+ *         neg = 1
+ *         buf += 1
+ */
+  __pyx_t_1 = (((__pyx_v_buf[0]) == 45) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":81
+ * 
+ *     if buf[0] == '-':
+ *         neg = 1             # <<<<<<<<<<<<<<
+ *         buf += 1
+ *     elif buf[0] == '+':
+ */
+    __pyx_v_neg = 1;
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":82
+ *     if buf[0] == '-':
+ *         neg = 1
+ *         buf += 1             # <<<<<<<<<<<<<<
+ *     elif buf[0] == '+':
+ *         buf += 1
+ */
+    __pyx_v_buf = (__pyx_v_buf + 1);
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":80
+ *         int32_t neg = 0
+ * 
+ *     if buf[0] == '-':             # <<<<<<<<<<<<<<
+ *         neg = 1
+ *         buf += 1
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":83
+ *         neg = 1
+ *         buf += 1
+ *     elif buf[0] == '+':             # <<<<<<<<<<<<<<
+ *         buf += 1
+ * 
+ */
+  __pyx_t_1 = (((__pyx_v_buf[0]) == 43) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":84
+ *         buf += 1
+ *     elif buf[0] == '+':
+ *         buf += 1             # <<<<<<<<<<<<<<
+ * 
+ *     p = buf
+ */
+    __pyx_v_buf = (__pyx_v_buf + 1);
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":83
+ *         neg = 1
+ *         buf += 1
+ *     elif buf[0] == '+':             # <<<<<<<<<<<<<<
+ *         buf += 1
+ * 
+ */
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":86
+ *         buf += 1
+ * 
+ *     p = buf             # <<<<<<<<<<<<<<
+ *     while <int>p[0] >= <int><Py_UCS4>'0' and <int>p[0] <= <int><Py_UCS4>'9':
+ *         n = 10 * n - (<int>p[0] - <int32_t><Py_UCS4>'0')
+ */
+  __pyx_v_p = __pyx_v_buf;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":87
+ * 
+ *     p = buf
+ *     while <int>p[0] >= <int><Py_UCS4>'0' and <int>p[0] <= <int><Py_UCS4>'9':             # <<<<<<<<<<<<<<
+ *         n = 10 * n - (<int>p[0] - <int32_t><Py_UCS4>'0')
+ *         p += 1
+ */
+  while (1) {
+    __pyx_t_2 = ((((int)(__pyx_v_p[0])) >= ((int)((Py_UCS4)48))) != 0);
+    if (__pyx_t_2) {
+    } else {
+      __pyx_t_1 = __pyx_t_2;
+      goto __pyx_L6_bool_binop_done;
+    }
+    __pyx_t_2 = ((((int)(__pyx_v_p[0])) <= ((int)((Py_UCS4)57))) != 0);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_L6_bool_binop_done:;
+    if (!__pyx_t_1) break;
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":88
+ *     p = buf
+ *     while <int>p[0] >= <int><Py_UCS4>'0' and <int>p[0] <= <int><Py_UCS4>'9':
+ *         n = 10 * n - (<int>p[0] - <int32_t><Py_UCS4>'0')             # <<<<<<<<<<<<<<
+ *         p += 1
+ * 
+ */
+    __pyx_v_n = ((10 * __pyx_v_n) - (((int)(__pyx_v_p[0])) - ((int32_t)((Py_UCS4)48))));
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":89
+ *     while <int>p[0] >= <int><Py_UCS4>'0' and <int>p[0] <= <int><Py_UCS4>'9':
+ *         n = 10 * n - (<int>p[0] - <int32_t><Py_UCS4>'0')
+ *         p += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if p == buf:
+ */
+    __pyx_v_p = (__pyx_v_p + 1);
+  }
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":91
+ *         p += 1
+ * 
+ *     if p == buf:             # <<<<<<<<<<<<<<
+ *         return NULL
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_p == __pyx_v_buf) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":92
+ * 
+ *     if p == buf:
+ *         return NULL             # <<<<<<<<<<<<<<
+ * 
+ *     if not neg:
+ */
+    __pyx_r = NULL;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":91
+ *         p += 1
+ * 
+ *     if p == buf:             # <<<<<<<<<<<<<<
+ *         return NULL
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":94
+ *         return NULL
+ * 
+ *     if not neg:             # <<<<<<<<<<<<<<
+ *         n = -n
+ * 
+ */
+  __pyx_t_1 = ((!(__pyx_v_neg != 0)) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":95
+ * 
+ *     if not neg:
+ *         n = -n             # <<<<<<<<<<<<<<
+ * 
+ *     num[0] = n
+ */
+    __pyx_v_n = (-__pyx_v_n);
+
+    /* "asyncpg/protocol/codecs/textutils.pyx":94
+ *         return NULL
+ * 
+ *     if not neg:             # <<<<<<<<<<<<<<
+ *         n = -n
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":97
+ *         n = -n
+ * 
+ *     num[0] = n             # <<<<<<<<<<<<<<
+ * 
+ *     return p
+ */
+  (__pyx_v_num[0]) = __pyx_v_n;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":99
+ *     num[0] = n
+ * 
+ *     return p             # <<<<<<<<<<<<<<
+ */
+  __pyx_r = __pyx_v_p;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/textutils.pyx":74
+ * 
+ * 
+ * cdef Py_UCS4 *apg_parse_int32(Py_UCS4 *buf, int32_t *num):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         Py_UCS4 *p
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":8
+ * 
+ * 
+ * cdef init_bits_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(BITOID,
+ *                         <encode_func>pgproto.bits_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_bits_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_bits_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":9
+ * 
+ * cdef init_bits_codecs():
+ *     register_core_codec(BITOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.bits_encode,
+ *                         <decode_func>pgproto.bits_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x618, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bits_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bits_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 9, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":14
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(VARBITOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.bits_encode,
+ *                         <decode_func>pgproto.bits_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x61A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bits_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bits_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":8
+ * 
+ * 
+ * cdef init_bits_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(BITOID,
+ *                         <encode_func>pgproto.bits_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_bits_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":20
+ * 
+ * 
+ * cdef init_bytea_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(BYTEAOID,
+ *                         <encode_func>pgproto.bytea_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_bytea_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_bytea_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":21
+ * 
+ * cdef init_bytea_codecs():
+ *     register_core_codec(BYTEAOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.bytea_encode,
+ *                         <decode_func>pgproto.bytea_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(17, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 21, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":26
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(CHAROID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.bytea_encode,
+ *                         <decode_func>pgproto.bytea_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(18, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 26, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":20
+ * 
+ * 
+ * cdef init_bytea_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(BYTEAOID,
+ *                         <encode_func>pgproto.bytea_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_bytea_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":32
+ * 
+ * 
+ * cdef init_datetime_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(DATEOID,
+ *                         <encode_func>pgproto.date_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_datetime_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  struct __pyx_opt_args_7asyncpg_8protocol_8protocol_register_core_codec __pyx_t_2;
+  __Pyx_RefNannySetupContext("init_datetime_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":33
+ * 
+ * cdef init_datetime_codecs():
+ *     register_core_codec(DATEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.date_encode,
+ *                         <decode_func>pgproto.date_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x43A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 33, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":38
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(DATEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.date_encode_tuple,
+ *                         <decode_func>pgproto.date_decode_tuple,
+ */
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x43A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode_tuple), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode_tuple), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 38, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":44
+ *                         PG_XFORMAT_TUPLE)
+ * 
+ *     register_core_codec(TIMEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.time_encode,
+ *                         <decode_func>pgproto.time_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x43B, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 44, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":49
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(TIMEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.time_encode_tuple,
+ *                         <decode_func>pgproto.time_decode_tuple,
+ */
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x43B, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode_tuple), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode_tuple), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":55
+ *                         PG_XFORMAT_TUPLE)
+ * 
+ *     register_core_codec(TIMETZOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.timetz_encode,
+ *                         <decode_func>pgproto.timetz_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x4F2, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":60
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(TIMETZOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.timetz_encode_tuple,
+ *                         <decode_func>pgproto.timetz_decode_tuple,
+ */
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x4F2, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode_tuple), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode_tuple), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 60, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":66
+ *                         PG_XFORMAT_TUPLE)
+ * 
+ *     register_core_codec(TIMESTAMPOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.timestamp_encode,
+ *                         <decode_func>pgproto.timestamp_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x45A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 66, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":71
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(TIMESTAMPOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.timestamp_encode_tuple,
+ *                         <decode_func>pgproto.timestamp_decode_tuple,
+ */
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x45A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode_tuple), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode_tuple), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 71, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":77
+ *                         PG_XFORMAT_TUPLE)
+ * 
+ *     register_core_codec(TIMESTAMPTZOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.timestamptz_encode,
+ *                         <decode_func>pgproto.timestamptz_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x4A0, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 77, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":82
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(TIMESTAMPTZOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.timestamp_encode_tuple,
+ *                         <decode_func>pgproto.timestamp_decode_tuple,
+ */
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x4A0, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode_tuple), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode_tuple), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 82, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":88
+ *                         PG_XFORMAT_TUPLE)
+ * 
+ *     register_core_codec(INTERVALOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.interval_encode,
+ *                         <decode_func>pgproto.interval_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x4A2, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 88, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":93
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(INTERVALOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.interval_encode_tuple,
+ *                         <decode_func>pgproto.interval_decode_tuple,
+ */
+  __pyx_t_2.__pyx_n = 1;
+  __pyx_t_2.xformat = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_TUPLE;
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x4A2, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode_tuple), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode_tuple), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 93, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":102
+ *     # interpret the value, and simply return and pass it as text.
+ *     #
+ *     register_core_codec(ABSTIMEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2BE, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 102, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":107
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     register_core_codec(RELTIMEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2BF, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 107, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":112
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     register_core_codec(TINTERVALOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2C0, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 112, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":32
+ * 
+ * 
+ * cdef init_datetime_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(DATEOID,
+ *                         <encode_func>pgproto.date_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_datetime_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":118
+ * 
+ * 
+ * cdef init_float_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(FLOAT4OID,
+ *                         <encode_func>pgproto.float4_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_float_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_float_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":119
+ * 
+ * cdef init_float_codecs():
+ *     register_core_codec(FLOAT4OID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.float4_encode,
+ *                         <decode_func>pgproto.float4_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2BC, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_float4_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_float4_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 119, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":124
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(FLOAT8OID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.float8_encode,
+ *                         <decode_func>pgproto.float8_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2BD, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_float8_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_float8_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 124, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":118
+ * 
+ * 
+ * cdef init_float_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(FLOAT4OID,
+ *                         <encode_func>pgproto.float4_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_float_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":130
+ * 
+ * 
+ * cdef init_geometry_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(BOXOID,
+ *                         <encode_func>pgproto.box_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_geometry_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_geometry_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":131
+ * 
+ * cdef init_geometry_codecs():
+ *     register_core_codec(BOXOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.box_encode,
+ *                         <decode_func>pgproto.box_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x25B, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_box_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_box_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 131, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":136
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(LINEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.line_encode,
+ *                         <decode_func>pgproto.line_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x274, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_line_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_line_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 136, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":141
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(LSEGOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.lseg_encode,
+ *                         <decode_func>pgproto.lseg_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x259, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 141, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":146
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(POINTOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.point_encode,
+ *                         <decode_func>pgproto.point_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x258, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_point_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_point_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 146, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":151
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(PATHOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.path_encode,
+ *                         <decode_func>pgproto.path_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x25A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_path_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_path_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 151, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":156
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(POLYGONOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.poly_encode,
+ *                         <decode_func>pgproto.poly_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x25C, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_poly_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_poly_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 156, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":161
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(CIRCLEOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.circle_encode,
+ *                         <decode_func>pgproto.circle_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2CE, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_circle_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_circle_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 161, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":130
+ * 
+ * 
+ * cdef init_geometry_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(BOXOID,
+ *                         <encode_func>pgproto.box_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_geometry_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":167
+ * 
+ * 
+ * cdef init_hstore_codecs():             # <<<<<<<<<<<<<<
+ *     register_extra_codec('pg_contrib.hstore',
+ *                          <encode_func>pgproto.hstore_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_hstore_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_hstore_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":168
+ * 
+ * cdef init_hstore_codecs():
+ *     register_extra_codec('pg_contrib.hstore',             # <<<<<<<<<<<<<<
+ *                          <encode_func>pgproto.hstore_encode,
+ *                          <decode_func>pgproto.hstore_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_extra_codec(__pyx_kp_u_pg_contrib_hstore, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 168, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":167
+ * 
+ * 
+ * cdef init_hstore_codecs():             # <<<<<<<<<<<<<<
+ *     register_extra_codec('pg_contrib.hstore',
+ *                          <encode_func>pgproto.hstore_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_hstore_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":174
+ * 
+ * 
+ * cdef init_json_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(JSONOID,
+ *                         <encode_func>pgproto.text_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_json_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_json_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":175
+ * 
+ * cdef init_json_codecs():
+ *     register_core_codec(JSONOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x72, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 175, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":179
+ *                         <decode_func>pgproto.text_decode,
+ *                         PG_FORMAT_BINARY)
+ *     register_core_codec(JSONBOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.jsonb_encode,
+ *                         <decode_func>pgproto.jsonb_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xEDA, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 179, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":174
+ * 
+ * 
+ * cdef init_json_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(JSONOID,
+ *                         <encode_func>pgproto.text_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_json_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":185
+ * 
+ * 
+ * cdef init_int_codecs():             # <<<<<<<<<<<<<<
+ * 
+ *     register_core_codec(BOOLOID,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_int_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_int_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":187
+ * cdef init_int_codecs():
+ * 
+ *     register_core_codec(BOOLOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.bool_encode,
+ *                         <decode_func>pgproto.bool_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(16, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bool_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_bool_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 187, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":192
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(INT2OID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.int2_encode,
+ *                         <decode_func>pgproto.int2_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(21, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int2_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int2_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 192, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":197
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(INT4OID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.int4_encode,
+ *                         <decode_func>pgproto.int4_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(23, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int4_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int4_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 197, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":202
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(INT8OID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.int8_encode,
+ *                         <decode_func>pgproto.int8_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(20, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int8_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int8_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 202, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":185
+ * 
+ * 
+ * cdef init_int_codecs():             # <<<<<<<<<<<<<<
+ * 
+ *     register_core_codec(BOOLOID,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_int_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":208
+ * 
+ * 
+ * cdef init_pseudo_codecs():             # <<<<<<<<<<<<<<
+ *     # Void type is returned by SELECT void_returning_function()
+ *     register_core_codec(VOIDOID,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_pseudo_codecs(void) {
+  PyObject *__pyx_v_oid_types = NULL;
+  PyObject *__pyx_v_oid_type = NULL;
+  PyObject *__pyx_v_reg_types = NULL;
+  PyObject *__pyx_v_reg_type = NULL;
+  PyObject *__pyx_v_no_io_types = NULL;
+  PyObject *__pyx_v_no_io_type = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  uint32_t __pyx_t_4;
+  __Pyx_RefNannySetupContext("init_pseudo_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":210
+ * cdef init_pseudo_codecs():
+ *     # Void type is returned by SELECT void_returning_function()
+ *     register_core_codec(VOIDOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.void_encode,
+ *                         <decode_func>pgproto.void_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x8E6, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_void_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_void_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 210, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":216
+ * 
+ *     # Unknown type, always decoded as text
+ *     register_core_codec(UNKNOWNOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x2C1, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 216, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":222
+ * 
+ *     # OID and friends
+ *     oid_types = [             # <<<<<<<<<<<<<<
+ *         OIDOID, XIDOID, CIDOID
+ *     ]
+ */
+  __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 222, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_int_26);
+  __Pyx_GIVEREF(__pyx_int_26);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_26);
+  __Pyx_INCREF(__pyx_int_28);
+  __Pyx_GIVEREF(__pyx_int_28);
+  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_28);
+  __Pyx_INCREF(__pyx_int_29);
+  __Pyx_GIVEREF(__pyx_int_29);
+  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_int_29);
+  __pyx_v_oid_types = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":226
+ *     ]
+ * 
+ *     for oid_type in oid_types:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid_type,
+ *                             <encode_func>pgproto.uint4_encode,
+ */
+  __pyx_t_1 = __pyx_v_oid_types; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(8, 226, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 226, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_oid_type, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":227
+ * 
+ *     for oid_type in oid_types:
+ *         register_core_codec(oid_type,             # <<<<<<<<<<<<<<
+ *                             <encode_func>pgproto.uint4_encode,
+ *                             <decode_func>pgproto.uint4_decode,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid_type); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 227, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":230
+ *                             <encode_func>pgproto.uint4_encode,
+ *                             <decode_func>pgproto.uint4_decode,
+ *                             PG_FORMAT_BINARY)             # <<<<<<<<<<<<<<
+ * 
+ *     # reg* types -- these are really system catalog OIDs, but
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 227, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":226
+ *     ]
+ * 
+ *     for oid_type in oid_types:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid_type,
+ *                             <encode_func>pgproto.uint4_encode,
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":237
+ *     # useful.
+ *     #
+ *     reg_types = [             # <<<<<<<<<<<<<<
+ *         REGPROCOID, REGPROCEDUREOID, REGOPEROID, REGOPERATOROID,
+ *         REGCLASSOID, REGTYPEOID, REGCONFIGOID, REGDICTIONARYOID,
+ */
+  __pyx_t_1 = PyList_New(11); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 237, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_int_24);
+  __Pyx_GIVEREF(__pyx_int_24);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_24);
+  __Pyx_INCREF(__pyx_int_2202);
+  __Pyx_GIVEREF(__pyx_int_2202);
+  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_2202);
+  __Pyx_INCREF(__pyx_int_2203);
+  __Pyx_GIVEREF(__pyx_int_2203);
+  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_int_2203);
+  __Pyx_INCREF(__pyx_int_2204);
+  __Pyx_GIVEREF(__pyx_int_2204);
+  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_int_2204);
+  __Pyx_INCREF(__pyx_int_2205);
+  __Pyx_GIVEREF(__pyx_int_2205);
+  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_int_2205);
+  __Pyx_INCREF(__pyx_int_2206);
+  __Pyx_GIVEREF(__pyx_int_2206);
+  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_int_2206);
+  __Pyx_INCREF(__pyx_int_3734);
+  __Pyx_GIVEREF(__pyx_int_3734);
+  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_int_3734);
+  __Pyx_INCREF(__pyx_int_3769);
+  __Pyx_GIVEREF(__pyx_int_3769);
+  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_int_3769);
+  __Pyx_INCREF(__pyx_int_4089);
+  __Pyx_GIVEREF(__pyx_int_4089);
+  PyList_SET_ITEM(__pyx_t_1, 8, __pyx_int_4089);
+  __Pyx_INCREF(__pyx_int_4096);
+  __Pyx_GIVEREF(__pyx_int_4096);
+  PyList_SET_ITEM(__pyx_t_1, 9, __pyx_int_4096);
+  __Pyx_INCREF(__pyx_int_1790);
+  __Pyx_GIVEREF(__pyx_int_1790);
+  PyList_SET_ITEM(__pyx_t_1, 10, __pyx_int_1790);
+  __pyx_v_reg_types = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":243
+ *     ]
+ * 
+ *     for reg_type in reg_types:             # <<<<<<<<<<<<<<
+ *         register_core_codec(reg_type,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  __pyx_t_1 = __pyx_v_reg_types; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(8, 243, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 243, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_reg_type, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":244
+ * 
+ *     for reg_type in reg_types:
+ *         register_core_codec(reg_type,             # <<<<<<<<<<<<<<
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_reg_type); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 244, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":247
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ *                             PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ * 
+ *     # cstring type is used by Postgres' I/O functions
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 244, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":243
+ *     ]
+ * 
+ *     for reg_type in reg_types:             # <<<<<<<<<<<<<<
+ *         register_core_codec(reg_type,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":250
+ * 
+ *     # cstring type is used by Postgres' I/O functions
+ *     register_core_codec(CSTRINGOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x8E3, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 250, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":256
+ * 
+ *     # various system pseudotypes with no I/O
+ *     no_io_types = [             # <<<<<<<<<<<<<<
+ *         ANYOID, TRIGGEROID, EVENT_TRIGGEROID, LANGUAGE_HANDLEROID,
+ *         FDW_HANDLEROID, TSM_HANDLEROID, INTERNALOID, OPAQUEOID,
+ */
+  __pyx_t_1 = PyList_New(12); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 256, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_int_2276);
+  __Pyx_GIVEREF(__pyx_int_2276);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_2276);
+  __Pyx_INCREF(__pyx_int_2279);
+  __Pyx_GIVEREF(__pyx_int_2279);
+  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_2279);
+  __Pyx_INCREF(__pyx_int_3838);
+  __Pyx_GIVEREF(__pyx_int_3838);
+  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_int_3838);
+  __Pyx_INCREF(__pyx_int_2280);
+  __Pyx_GIVEREF(__pyx_int_2280);
+  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_int_2280);
+  __Pyx_INCREF(__pyx_int_3115);
+  __Pyx_GIVEREF(__pyx_int_3115);
+  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_int_3115);
+  __Pyx_INCREF(__pyx_int_3310);
+  __Pyx_GIVEREF(__pyx_int_3310);
+  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_int_3310);
+  __Pyx_INCREF(__pyx_int_2281);
+  __Pyx_GIVEREF(__pyx_int_2281);
+  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_int_2281);
+  __Pyx_INCREF(__pyx_int_2282);
+  __Pyx_GIVEREF(__pyx_int_2282);
+  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_int_2282);
+  __Pyx_INCREF(__pyx_int_2283);
+  __Pyx_GIVEREF(__pyx_int_2283);
+  PyList_SET_ITEM(__pyx_t_1, 8, __pyx_int_2283);
+  __Pyx_INCREF(__pyx_int_2776);
+  __Pyx_GIVEREF(__pyx_int_2776);
+  PyList_SET_ITEM(__pyx_t_1, 9, __pyx_int_2776);
+  __Pyx_INCREF(__pyx_int_32);
+  __Pyx_GIVEREF(__pyx_int_32);
+  PyList_SET_ITEM(__pyx_t_1, 10, __pyx_int_32);
+  __Pyx_INCREF(__pyx_int_325);
+  __Pyx_GIVEREF(__pyx_int_325);
+  PyList_SET_ITEM(__pyx_t_1, 11, __pyx_int_325);
+  __pyx_v_no_io_types = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":263
+ *     ]
+ * 
+ *     register_core_codec(ANYENUMOID,             # <<<<<<<<<<<<<<
+ *                         NULL,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xDAC, NULL, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 263, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":268
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     for no_io_type in no_io_types:             # <<<<<<<<<<<<<<
+ *         register_core_codec(no_io_type,
+ *                             NULL,
+ */
+  __pyx_t_1 = __pyx_v_no_io_types; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(8, 268, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 268, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_no_io_type, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":269
+ * 
+ *     for no_io_type in no_io_types:
+ *         register_core_codec(no_io_type,             # <<<<<<<<<<<<<<
+ *                             NULL,
+ *                             NULL,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_no_io_type); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 269, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":272
+ *                             NULL,
+ *                             NULL,
+ *                             PG_FORMAT_BINARY)             # <<<<<<<<<<<<<<
+ * 
+ *     # ACL specification string
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, NULL, NULL, __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 269, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":268
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     for no_io_type in no_io_types:             # <<<<<<<<<<<<<<
+ *         register_core_codec(no_io_type,
+ *                             NULL,
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":275
+ * 
+ *     # ACL specification string
+ *     register_core_codec(ACLITEMOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x409, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 275, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":281
+ * 
+ *     # Postgres' serialized expression tree type
+ *     register_core_codec(PG_NODE_TREEOID,             # <<<<<<<<<<<<<<
+ *                         NULL,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xC2, NULL, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 281, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":287
+ * 
+ *     # pg_lsn type -- a pointer to a location in the XLOG.
+ *     register_core_codec(PG_LSNOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.int8_encode,
+ *                         <decode_func>pgproto.int8_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xC94, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int8_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_int8_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 287, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":292
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(SMGROID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xD2, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 292, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":299
+ *     # pg_dependencies and pg_ndistinct are special types
+ *     # used in pg_statistic_ext columns.
+ *     register_core_codec(PG_DEPENDENCIESOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xD4A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 299, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":304
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     register_core_codec(PG_NDISTINCTOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xD21, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 304, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":208
+ * 
+ * 
+ * cdef init_pseudo_codecs():             # <<<<<<<<<<<<<<
+ *     # Void type is returned by SELECT void_returning_function()
+ *     register_core_codec(VOIDOID,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_pseudo_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_oid_types);
+  __Pyx_XDECREF(__pyx_v_oid_type);
+  __Pyx_XDECREF(__pyx_v_reg_types);
+  __Pyx_XDECREF(__pyx_v_reg_type);
+  __Pyx_XDECREF(__pyx_v_no_io_types);
+  __Pyx_XDECREF(__pyx_v_no_io_type);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":310
+ * 
+ * 
+ * cdef init_text_codecs():             # <<<<<<<<<<<<<<
+ *     textoids = [
+ *         NAMEOID,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_text_codecs(void) {
+  PyObject *__pyx_v_textoids = NULL;
+  PyObject *__pyx_v_oid = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  uint32_t __pyx_t_4;
+  __Pyx_RefNannySetupContext("init_text_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":311
+ * 
+ * cdef init_text_codecs():
+ *     textoids = [             # <<<<<<<<<<<<<<
+ *         NAMEOID,
+ *         BPCHAROID,
+ */
+  __pyx_t_1 = PyList_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 311, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_int_19);
+  __Pyx_GIVEREF(__pyx_int_19);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_19);
+  __Pyx_INCREF(__pyx_int_1042);
+  __Pyx_GIVEREF(__pyx_int_1042);
+  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_1042);
+  __Pyx_INCREF(__pyx_int_1043);
+  __Pyx_GIVEREF(__pyx_int_1043);
+  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_int_1043);
+  __Pyx_INCREF(__pyx_int_25);
+  __Pyx_GIVEREF(__pyx_int_25);
+  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_int_25);
+  __Pyx_INCREF(__pyx_int_142);
+  __Pyx_GIVEREF(__pyx_int_142);
+  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_int_142);
+  __pyx_v_textoids = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":319
+ *     ]
+ * 
+ *     for oid in textoids:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  __pyx_t_1 = __pyx_v_textoids; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(8, 319, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 319, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_oid, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":320
+ * 
+ *     for oid in textoids:
+ *         register_core_codec(oid,             # <<<<<<<<<<<<<<
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 320, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":323
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ *                             PG_FORMAT_BINARY)             # <<<<<<<<<<<<<<
+ * 
+ *         register_core_codec(oid,
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 320, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":325
+ *                             PG_FORMAT_BINARY)
+ * 
+ *         register_core_codec(oid,             # <<<<<<<<<<<<<<
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 325, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":328
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ *                             PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 325, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":319
+ *     ]
+ * 
+ *     for oid in textoids:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":310
+ * 
+ * 
+ * cdef init_text_codecs():             # <<<<<<<<<<<<<<
+ *     textoids = [
+ *         NAMEOID,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_text_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_textoids);
+  __Pyx_XDECREF(__pyx_v_oid);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":331
+ * 
+ * 
+ * cdef init_tid_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(TIDOID,
+ *                         <encode_func>pgproto.tid_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_tid_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_tid_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":332
+ * 
+ * cdef init_tid_codecs():
+ *     register_core_codec(TIDOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.tid_encode,
+ *                         <decode_func>pgproto.tid_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(27, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_tid_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_tid_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 332, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":331
+ * 
+ * 
+ * cdef init_tid_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(TIDOID,
+ *                         <encode_func>pgproto.tid_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_tid_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":338
+ * 
+ * 
+ * cdef init_txid_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(TXID_SNAPSHOTOID,
+ *                         <encode_func>pgproto.txid_snapshot_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_txid_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_txid_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":339
+ * 
+ * cdef init_txid_codecs():
+ *     register_core_codec(TXID_SNAPSHOTOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.txid_snapshot_encode,
+ *                         <decode_func>pgproto.txid_snapshot_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xB9A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 339, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":338
+ * 
+ * 
+ * cdef init_txid_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(TXID_SNAPSHOTOID,
+ *                         <encode_func>pgproto.txid_snapshot_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_txid_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":345
+ * 
+ * 
+ * cdef init_tsearch_codecs():             # <<<<<<<<<<<<<<
+ *     ts_oids = [
+ *         TSQUERYOID,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_tsearch_codecs(void) {
+  PyObject *__pyx_v_ts_oids = NULL;
+  PyObject *__pyx_v_oid = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  uint32_t __pyx_t_4;
+  __Pyx_RefNannySetupContext("init_tsearch_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":346
+ * 
+ * cdef init_tsearch_codecs():
+ *     ts_oids = [             # <<<<<<<<<<<<<<
+ *         TSQUERYOID,
+ *         TSVECTOROID,
+ */
+  __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 346, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_int_3615);
+  __Pyx_GIVEREF(__pyx_int_3615);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_3615);
+  __Pyx_INCREF(__pyx_int_3614);
+  __Pyx_GIVEREF(__pyx_int_3614);
+  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_3614);
+  __pyx_v_ts_oids = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":351
+ *     ]
+ * 
+ *     for oid in ts_oids:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  __pyx_t_1 = __pyx_v_ts_oids; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(8, 351, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 351, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_oid, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":352
+ * 
+ *     for oid in ts_oids:
+ *         register_core_codec(oid,             # <<<<<<<<<<<<<<
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 352, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":355
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ *                             PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ * 
+ *     register_core_codec(GTSVECTOROID,
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 352, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":351
+ *     ]
+ * 
+ *     for oid in ts_oids:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":357
+ *                             PG_FORMAT_TEXT)
+ * 
+ *     register_core_codec(GTSVECTOROID,             # <<<<<<<<<<<<<<
+ *                         NULL,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xE3A, NULL, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 357, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":345
+ * 
+ * 
+ * cdef init_tsearch_codecs():             # <<<<<<<<<<<<<<
+ *     ts_oids = [
+ *         TSQUERYOID,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_tsearch_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_ts_oids);
+  __Pyx_XDECREF(__pyx_v_oid);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":363
+ * 
+ * 
+ * cdef init_uuid_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(UUIDOID,
+ *                         <encode_func>pgproto.uuid_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_uuid_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_uuid_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":364
+ * 
+ * cdef init_uuid_codecs():
+ *     register_core_codec(UUIDOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.uuid_encode,
+ *                         <decode_func>pgproto.uuid_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xB86, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 364, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":363
+ * 
+ * 
+ * cdef init_uuid_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(UUIDOID,
+ *                         <encode_func>pgproto.uuid_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_uuid_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":370
+ * 
+ * 
+ * cdef init_numeric_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(NUMERICOID,
+ *                         <encode_func>pgproto.numeric_encode_text,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_numeric_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_numeric_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":371
+ * 
+ * cdef init_numeric_codecs():
+ *     register_core_codec(NUMERICOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.numeric_encode_text,
+ *                         <decode_func>pgproto.numeric_decode_text,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x6A4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_text), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_text), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 371, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":376
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     register_core_codec(NUMERICOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.numeric_encode_binary,
+ *                         <decode_func>pgproto.numeric_decode_binary,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x6A4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_binary), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_binary), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 376, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":370
+ * 
+ * 
+ * cdef init_numeric_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(NUMERICOID,
+ *                         <encode_func>pgproto.numeric_encode_text,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_numeric_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":382
+ * 
+ * 
+ * cdef init_network_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(CIDROID,
+ *                         <encode_func>pgproto.cidr_encode,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_network_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_network_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":383
+ * 
+ * cdef init_network_codecs():
+ *     register_core_codec(CIDROID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.cidr_encode,
+ *                         <decode_func>pgproto.net_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x28A, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_net_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 383, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":388
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(INETOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.inet_encode,
+ *                         <decode_func>pgproto.net_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x365, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_inet_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_net_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 388, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":393
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(MACADDROID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x33D, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 393, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":398
+ *                         PG_FORMAT_TEXT)
+ * 
+ *     register_core_codec(MACADDR8OID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>pgproto.text_encode,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x306, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 398, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":382
+ * 
+ * 
+ * cdef init_network_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(CIDROID,
+ *                         <encode_func>pgproto.cidr_encode,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_network_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":404
+ * 
+ * 
+ * cdef init_monetary_codecs():             # <<<<<<<<<<<<<<
+ *     moneyoids = [
+ *         MONEYOID,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_monetary_codecs(void) {
+  PyObject *__pyx_v_moneyoids = NULL;
+  PyObject *__pyx_v_oid = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  uint32_t __pyx_t_4;
+  __Pyx_RefNannySetupContext("init_monetary_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":405
+ * 
+ * cdef init_monetary_codecs():
+ *     moneyoids = [             # <<<<<<<<<<<<<<
+ *         MONEYOID,
+ *     ]
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 405, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_int_790);
+  __Pyx_GIVEREF(__pyx_int_790);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_790);
+  __pyx_v_moneyoids = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":409
+ *     ]
+ * 
+ *     for oid in moneyoids:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  __pyx_t_1 = __pyx_v_moneyoids; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(8, 409, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 409, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_oid, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":410
+ * 
+ *     for oid in moneyoids:
+ *         register_core_codec(oid,             # <<<<<<<<<<<<<<
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(8, 410, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":413
+ *                             <encode_func>pgproto.text_encode,
+ *                             <decode_func>pgproto.text_decode,
+ *                             PG_FORMAT_TEXT)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(__pyx_t_4, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(8, 410, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/pgproto.pyx":409
+ *     ]
+ * 
+ *     for oid in moneyoids:             # <<<<<<<<<<<<<<
+ *         register_core_codec(oid,
+ *                             <encode_func>pgproto.text_encode,
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":404
+ * 
+ * 
+ * cdef init_monetary_codecs():             # <<<<<<<<<<<<<<
+ *     moneyoids = [
+ *         MONEYOID,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_monetary_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_moneyoids);
+  __Pyx_XDECREF(__pyx_v_oid);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/pgproto.pyx":416
+ * 
+ * 
+ * cdef init_all_pgproto_codecs():             # <<<<<<<<<<<<<<
+ *     # Builtin types, in lexicographical order.
+ *     init_bits_codecs()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_all_pgproto_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_all_pgproto_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":418
+ * cdef init_all_pgproto_codecs():
+ *     # Builtin types, in lexicographical order.
+ *     init_bits_codecs()             # <<<<<<<<<<<<<<
+ *     init_bytea_codecs()
+ *     init_datetime_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_bits_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 418, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":419
+ *     # Builtin types, in lexicographical order.
+ *     init_bits_codecs()
+ *     init_bytea_codecs()             # <<<<<<<<<<<<<<
+ *     init_datetime_codecs()
+ *     init_float_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_bytea_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 419, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":420
+ *     init_bits_codecs()
+ *     init_bytea_codecs()
+ *     init_datetime_codecs()             # <<<<<<<<<<<<<<
+ *     init_float_codecs()
+ *     init_geometry_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_datetime_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 420, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":421
+ *     init_bytea_codecs()
+ *     init_datetime_codecs()
+ *     init_float_codecs()             # <<<<<<<<<<<<<<
+ *     init_geometry_codecs()
+ *     init_int_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_float_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 421, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":422
+ *     init_datetime_codecs()
+ *     init_float_codecs()
+ *     init_geometry_codecs()             # <<<<<<<<<<<<<<
+ *     init_int_codecs()
+ *     init_json_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_geometry_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 422, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":423
+ *     init_float_codecs()
+ *     init_geometry_codecs()
+ *     init_int_codecs()             # <<<<<<<<<<<<<<
+ *     init_json_codecs()
+ *     init_monetary_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_int_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 423, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":424
+ *     init_geometry_codecs()
+ *     init_int_codecs()
+ *     init_json_codecs()             # <<<<<<<<<<<<<<
+ *     init_monetary_codecs()
+ *     init_network_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_json_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 424, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":425
+ *     init_int_codecs()
+ *     init_json_codecs()
+ *     init_monetary_codecs()             # <<<<<<<<<<<<<<
+ *     init_network_codecs()
+ *     init_numeric_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_monetary_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 425, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":426
+ *     init_json_codecs()
+ *     init_monetary_codecs()
+ *     init_network_codecs()             # <<<<<<<<<<<<<<
+ *     init_numeric_codecs()
+ *     init_text_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_network_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 426, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":427
+ *     init_monetary_codecs()
+ *     init_network_codecs()
+ *     init_numeric_codecs()             # <<<<<<<<<<<<<<
+ *     init_text_codecs()
+ *     init_tid_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_numeric_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 427, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":428
+ *     init_network_codecs()
+ *     init_numeric_codecs()
+ *     init_text_codecs()             # <<<<<<<<<<<<<<
+ *     init_tid_codecs()
+ *     init_tsearch_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_text_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 428, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":429
+ *     init_numeric_codecs()
+ *     init_text_codecs()
+ *     init_tid_codecs()             # <<<<<<<<<<<<<<
+ *     init_tsearch_codecs()
+ *     init_txid_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_tid_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 429, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":430
+ *     init_text_codecs()
+ *     init_tid_codecs()
+ *     init_tsearch_codecs()             # <<<<<<<<<<<<<<
+ *     init_txid_codecs()
+ *     init_uuid_codecs()
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_tsearch_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 430, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":431
+ *     init_tid_codecs()
+ *     init_tsearch_codecs()
+ *     init_txid_codecs()             # <<<<<<<<<<<<<<
+ *     init_uuid_codecs()
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_txid_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 431, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":432
+ *     init_tsearch_codecs()
+ *     init_txid_codecs()
+ *     init_uuid_codecs()             # <<<<<<<<<<<<<<
+ * 
+ *     # Various pseudotypes and system types
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_uuid_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 432, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":435
+ * 
+ *     # Various pseudotypes and system types
+ *     init_pseudo_codecs()             # <<<<<<<<<<<<<<
+ * 
+ *     # contrib
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_pseudo_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 435, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":438
+ * 
+ *     # contrib
+ *     init_hstore_codecs()             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_hstore_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 438, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":416
+ * 
+ * 
+ * cdef init_all_pgproto_codecs():             # <<<<<<<<<<<<<<
+ *     # Builtin types, in lexicographical order.
+ *     init_bits_codecs()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_all_pgproto_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":32
+ * 
+ * 
+ * cdef inline bint _is_trivial_container(object obj):             # <<<<<<<<<<<<<<
+ *     return cpython.PyUnicode_Check(obj) or cpython.PyBytes_Check(obj) or \
+ *             cpythonx.PyByteArray_Check(obj) or cpythonx.PyMemoryView_Check(obj)
+ */
+
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol__is_trivial_container(PyObject *__pyx_v_obj) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannySetupContext("_is_trivial_container", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":33
+ * 
+ * cdef inline bint _is_trivial_container(object obj):
+ *     return cpython.PyUnicode_Check(obj) or cpython.PyBytes_Check(obj) or \             # <<<<<<<<<<<<<<
+ *             cpythonx.PyByteArray_Check(obj) or cpythonx.PyMemoryView_Check(obj)
+ * 
+ */
+  __pyx_t_2 = (PyUnicode_Check(__pyx_v_obj) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __pyx_t_2 = (PyBytes_Check(__pyx_v_obj) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L3_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":34
+ * cdef inline bint _is_trivial_container(object obj):
+ *     return cpython.PyUnicode_Check(obj) or cpython.PyBytes_Check(obj) or \
+ *             cpythonx.PyByteArray_Check(obj) or cpythonx.PyMemoryView_Check(obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = (PyByteArray_Check(__pyx_v_obj) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __pyx_t_2 = (PyMemoryView_Check(__pyx_v_obj) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L3_bool_binop_done:;
+  __pyx_r = __pyx_t_1;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":32
+ * 
+ * 
+ * cdef inline bint _is_trivial_container(object obj):             # <<<<<<<<<<<<<<
+ *     return cpython.PyUnicode_Check(obj) or cpython.PyBytes_Check(obj) or \
+ *             cpythonx.PyByteArray_Check(obj) or cpythonx.PyMemoryView_Check(obj)
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":37
+ * 
+ * 
+ * cdef inline _is_array_iterable(object obj):             # <<<<<<<<<<<<<<
+ *     return (
+ *         isinstance(obj, IterableABC) and
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol__is_array_iterable(PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  int __pyx_t_3;
+  int __pyx_t_4;
+  __Pyx_RefNannySetupContext("_is_array_iterable", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":38
+ * 
+ * cdef inline _is_array_iterable(object obj):
+ *     return (             # <<<<<<<<<<<<<<
+ *         isinstance(obj, IterableABC) and
+ *         isinstance(obj, SizedABC) and
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/protocol/codecs/array.pyx":39
+ * cdef inline _is_array_iterable(object obj):
+ *     return (
+ *         isinstance(obj, IterableABC) and             # <<<<<<<<<<<<<<
+ *         isinstance(obj, SizedABC) and
+ *         not _is_trivial_container(obj) and
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_IterableABC); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 39, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 39, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (__pyx_t_3) {
+  } else {
+    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 39, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":40
+ *     return (
+ *         isinstance(obj, IterableABC) and
+ *         isinstance(obj, SizedABC) and             # <<<<<<<<<<<<<<
+ *         not _is_trivial_container(obj) and
+ *         not isinstance(obj, MappingABC)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_SizedABC); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 40, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 40, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (__pyx_t_3) {
+  } else {
+    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 40, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":41
+ *         isinstance(obj, IterableABC) and
+ *         isinstance(obj, SizedABC) and
+ *         not _is_trivial_container(obj) and             # <<<<<<<<<<<<<<
+ *         not isinstance(obj, MappingABC)
+ *     )
+ */
+  __pyx_t_3 = (!(__pyx_f_7asyncpg_8protocol_8protocol__is_trivial_container(__pyx_v_obj) != 0));
+  if (__pyx_t_3) {
+  } else {
+    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 41, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_t_2 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":42
+ *         isinstance(obj, SizedABC) and
+ *         not _is_trivial_container(obj) and
+ *         not isinstance(obj, MappingABC)             # <<<<<<<<<<<<<<
+ *     )
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_MappingABC); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 42, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(4, 42, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_4 = (!(__pyx_t_3 != 0));
+  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 42, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_t_2 = 0;
+  __pyx_L3_bool_binop_done:;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":37
+ * 
+ * 
+ * cdef inline _is_array_iterable(object obj):             # <<<<<<<<<<<<<<
+ *     return (
+ *         isinstance(obj, IterableABC) and
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._is_array_iterable", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":46
+ * 
+ * 
+ * cdef inline _is_sub_array_iterable(object obj):             # <<<<<<<<<<<<<<
+ *     # Sub-arrays have a specialized check, because we treat
+ *     # nested tuples as records.
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol__is_sub_array_iterable(PyObject *__pyx_v_obj) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  int __pyx_t_3;
+  __Pyx_RefNannySetupContext("_is_sub_array_iterable", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":49
+ *     # Sub-arrays have a specialized check, because we treat
+ *     # nested tuples as records.
+ *     return _is_array_iterable(obj) and not cpython.PyTuple_Check(obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol__is_array_iterable(__pyx_v_obj); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(4, 49, __pyx_L1_error)
+  if (__pyx_t_3) {
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  } else {
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_t_1 = __pyx_t_2;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __pyx_t_3 = (!(PyTuple_Check(__pyx_v_obj) != 0));
+  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_t_2 = 0;
+  __pyx_L3_bool_binop_done:;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":46
+ * 
+ * 
+ * cdef inline _is_sub_array_iterable(object obj):             # <<<<<<<<<<<<<<
+ *     # Sub-arrays have a specialized check, because we treat
+ *     # nested tuples as records.
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._is_sub_array_iterable", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":52
+ * 
+ * 
+ * cdef _get_array_shape(object obj, int32_t *dims, int32_t *ndims):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ssize_t mylen = len(obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__get_array_shape(PyObject *__pyx_v_obj, int32_t *__pyx_v_dims, int32_t *__pyx_v_ndims) {
+  Py_ssize_t __pyx_v_mylen;
+  Py_ssize_t __pyx_v_elemlen;
+  PyObject *__pyx_v_elem = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *(*__pyx_t_9)(PyObject *);
+  Py_ssize_t __pyx_t_10;
+  long __pyx_t_11;
+  __Pyx_RefNannySetupContext("_get_array_shape", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":54
+ * cdef _get_array_shape(object obj, int32_t *dims, int32_t *ndims):
+ *     cdef:
+ *         ssize_t mylen = len(obj)             # <<<<<<<<<<<<<<
+ *         ssize_t elemlen = -2
+ *         object it
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(4, 54, __pyx_L1_error)
+  __pyx_v_mylen = __pyx_t_1;
+
+  /* "asyncpg/protocol/codecs/array.pyx":55
+ *     cdef:
+ *         ssize_t mylen = len(obj)
+ *         ssize_t elemlen = -2             # <<<<<<<<<<<<<<
+ *         object it
+ * 
+ */
+  __pyx_v_elemlen = -2L;
+
+  /* "asyncpg/protocol/codecs/array.pyx":58
+ *         object it
+ * 
+ *     if mylen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('too many elements in array value')
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_mylen > 0x7FFFFFFF) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":59
+ * 
+ *     if mylen > _MAXINT32:
+ *         raise ValueError('too many elements in array value')             # <<<<<<<<<<<<<<
+ * 
+ *     if ndims[0] > ARRAY_MAXDIM:
+ */
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 59, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(4, 59, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/array.pyx":58
+ *         object it
+ * 
+ *     if mylen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *         raise ValueError('too many elements in array value')
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":61
+ *         raise ValueError('too many elements in array value')
+ * 
+ *     if ndims[0] > ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ */
+  __pyx_t_2 = (((__pyx_v_ndims[0]) > 6) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":63
+ *     if ndims[0] > ARRAY_MAXDIM:
+ *         raise ValueError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.             # <<<<<<<<<<<<<<
+ *                 format(ndims[0], ARRAY_MAXDIM))
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_number_of_array_dimensions_excee, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 63, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/protocol/codecs/array.pyx":64
+ *         raise ValueError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ *                 format(ndims[0], ARRAY_MAXDIM))             # <<<<<<<<<<<<<<
+ * 
+ *     dims[ndims[0] - 1] = <int32_t>mylen
+ */
+    __pyx_t_5 = __Pyx_PyInt_From_int32_t((__pyx_v_ndims[0])); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 64, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    __pyx_t_7 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+        __pyx_t_7 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_int_6};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 64, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_int_6};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 64, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(4, 64, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      if (__pyx_t_6) {
+        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_5);
+      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_5);
+      __Pyx_INCREF(__pyx_int_6);
+      __Pyx_GIVEREF(__pyx_int_6);
+      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_int_6);
+      __pyx_t_5 = 0;
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 64, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":62
+ * 
+ *     if ndims[0] > ARRAY_MAXDIM:
+ *         raise ValueError(             # <<<<<<<<<<<<<<
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ *                 format(ndims[0], ARRAY_MAXDIM))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 62, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(4, 62, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/array.pyx":61
+ *         raise ValueError('too many elements in array value')
+ * 
+ *     if ndims[0] > ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *         raise ValueError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":66
+ *                 format(ndims[0], ARRAY_MAXDIM))
+ * 
+ *     dims[ndims[0] - 1] = <int32_t>mylen             # <<<<<<<<<<<<<<
+ * 
+ *     for elem in obj:
+ */
+  (__pyx_v_dims[((__pyx_v_ndims[0]) - 1)]) = ((int32_t)__pyx_v_mylen);
+
+  /* "asyncpg/protocol/codecs/array.pyx":68
+ *     dims[ndims[0] - 1] = <int32_t>mylen
+ * 
+ *     for elem in obj:             # <<<<<<<<<<<<<<
+ *         if _is_sub_array_iterable(elem):
+ *             if elemlen == -2:
+ */
+  if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+    __pyx_t_4 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = 0;
+    __pyx_t_9 = NULL;
+  } else {
+    __pyx_t_1 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 68, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 68, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_9)) {
+      if (likely(PyList_CheckExact(__pyx_t_4))) {
+        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_4)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(4, 68, __pyx_L1_error)
+        #else
+        __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 68, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        #endif
+      } else {
+        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(4, 68, __pyx_L1_error)
+        #else
+        __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 68, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        #endif
+      }
+    } else {
+      __pyx_t_3 = __pyx_t_9(__pyx_t_4);
+      if (unlikely(!__pyx_t_3)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(4, 68, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_3);
+    }
+    __Pyx_XDECREF_SET(__pyx_v_elem, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":69
+ * 
+ *     for elem in obj:
+ *         if _is_sub_array_iterable(elem):             # <<<<<<<<<<<<<<
+ *             if elemlen == -2:
+ *                 elemlen = len(elem)
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__is_sub_array_iterable(__pyx_v_elem); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 69, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(4, 69, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":70
+ *     for elem in obj:
+ *         if _is_sub_array_iterable(elem):
+ *             if elemlen == -2:             # <<<<<<<<<<<<<<
+ *                 elemlen = len(elem)
+ *                 if elemlen > _MAXINT32:
+ */
+      __pyx_t_2 = ((__pyx_v_elemlen == -2L) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":71
+ *         if _is_sub_array_iterable(elem):
+ *             if elemlen == -2:
+ *                 elemlen = len(elem)             # <<<<<<<<<<<<<<
+ *                 if elemlen > _MAXINT32:
+ *                     raise ValueError('too many elements in array value')
+ */
+        __pyx_t_10 = PyObject_Length(__pyx_v_elem); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(4, 71, __pyx_L1_error)
+        __pyx_v_elemlen = __pyx_t_10;
+
+        /* "asyncpg/protocol/codecs/array.pyx":72
+ *             if elemlen == -2:
+ *                 elemlen = len(elem)
+ *                 if elemlen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *                     raise ValueError('too many elements in array value')
+ *                 ndims[0] += 1
+ */
+        __pyx_t_2 = ((__pyx_v_elemlen > 0x7FFFFFFF) != 0);
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":73
+ *                 elemlen = len(elem)
+ *                 if elemlen > _MAXINT32:
+ *                     raise ValueError('too many elements in array value')             # <<<<<<<<<<<<<<
+ *                 ndims[0] += 1
+ *                 _get_array_shape(elem, dims, ndims)
+ */
+          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 73, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 73, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":72
+ *             if elemlen == -2:
+ *                 elemlen = len(elem)
+ *                 if elemlen > _MAXINT32:             # <<<<<<<<<<<<<<
+ *                     raise ValueError('too many elements in array value')
+ *                 ndims[0] += 1
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":74
+ *                 if elemlen > _MAXINT32:
+ *                     raise ValueError('too many elements in array value')
+ *                 ndims[0] += 1             # <<<<<<<<<<<<<<
+ *                 _get_array_shape(elem, dims, ndims)
+ *             else:
+ */
+        __pyx_t_11 = 0;
+        (__pyx_v_ndims[__pyx_t_11]) = ((__pyx_v_ndims[__pyx_t_11]) + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":75
+ *                     raise ValueError('too many elements in array value')
+ *                 ndims[0] += 1
+ *                 _get_array_shape(elem, dims, ndims)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 if len(elem) != elemlen:
+ */
+        __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__get_array_shape(__pyx_v_elem, __pyx_v_dims, __pyx_v_ndims); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 75, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":70
+ *     for elem in obj:
+ *         if _is_sub_array_iterable(elem):
+ *             if elemlen == -2:             # <<<<<<<<<<<<<<
+ *                 elemlen = len(elem)
+ *                 if elemlen > _MAXINT32:
+ */
+        goto __pyx_L8;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":77
+ *                 _get_array_shape(elem, dims, ndims)
+ *             else:
+ *                 if len(elem) != elemlen:             # <<<<<<<<<<<<<<
+ *                     raise ValueError('non-homogeneous array')
+ *         else:
+ */
+      /*else*/ {
+        __pyx_t_10 = PyObject_Length(__pyx_v_elem); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(4, 77, __pyx_L1_error)
+        __pyx_t_2 = ((__pyx_t_10 != __pyx_v_elemlen) != 0);
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":78
+ *             else:
+ *                 if len(elem) != elemlen:
+ *                     raise ValueError('non-homogeneous array')             # <<<<<<<<<<<<<<
+ *         else:
+ *             if elemlen >= 0:
+ */
+          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 78, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 78, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":77
+ *                 _get_array_shape(elem, dims, ndims)
+ *             else:
+ *                 if len(elem) != elemlen:             # <<<<<<<<<<<<<<
+ *                     raise ValueError('non-homogeneous array')
+ *         else:
+ */
+        }
+      }
+      __pyx_L8:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":69
+ * 
+ *     for elem in obj:
+ *         if _is_sub_array_iterable(elem):             # <<<<<<<<<<<<<<
+ *             if elemlen == -2:
+ *                 elemlen = len(elem)
+ */
+      goto __pyx_L7;
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":80
+ *                     raise ValueError('non-homogeneous array')
+ *         else:
+ *             if elemlen >= 0:             # <<<<<<<<<<<<<<
+ *                 raise ValueError('non-homogeneous array')
+ *             else:
+ */
+    /*else*/ {
+      __pyx_t_2 = ((__pyx_v_elemlen >= 0) != 0);
+      if (unlikely(__pyx_t_2)) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":81
+ *         else:
+ *             if elemlen >= 0:
+ *                 raise ValueError('non-homogeneous array')             # <<<<<<<<<<<<<<
+ *             else:
+ *                 elemlen = -1
+ */
+        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 81, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __PYX_ERR(4, 81, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/array.pyx":80
+ *                     raise ValueError('non-homogeneous array')
+ *         else:
+ *             if elemlen >= 0:             # <<<<<<<<<<<<<<
+ *                 raise ValueError('non-homogeneous array')
+ *             else:
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":83
+ *                 raise ValueError('non-homogeneous array')
+ *             else:
+ *                 elemlen = -1             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+      /*else*/ {
+        __pyx_v_elemlen = -1L;
+      }
+    }
+    __pyx_L7:;
+
+    /* "asyncpg/protocol/codecs/array.pyx":68
+ *     dims[ndims[0] - 1] = <int32_t>mylen
+ * 
+ *     for elem in obj:             # <<<<<<<<<<<<<<
+ *         if _is_sub_array_iterable(elem):
+ *             if elemlen == -2:
+ */
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":52
+ * 
+ * 
+ * cdef _get_array_shape(object obj, int32_t *dims, int32_t *ndims):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ssize_t mylen = len(obj)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._get_array_shape", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_elem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":86
+ * 
+ * 
+ * cdef _write_array_data(ConnectionSettings settings, object obj, int32_t ndims,             # <<<<<<<<<<<<<<
+ *                        int32_t dim, WriteBuffer elem_data,
+ *                        encode_func_ex encoder, const void *encoder_arg):
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__write_array_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, PyObject *__pyx_v_obj, int32_t __pyx_v_ndims, int32_t __pyx_v_dim, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_elem_data, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex __pyx_v_encoder, void const *__pyx_v_encoder_arg) {
+  PyObject *__pyx_v_item = NULL;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  PyObject *(*__pyx_t_4)(PyObject *);
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  int __pyx_t_17;
+  char const *__pyx_t_18;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  PyObject *__pyx_t_21 = NULL;
+  PyObject *__pyx_t_22 = NULL;
+  PyObject *__pyx_t_23 = NULL;
+  PyObject *__pyx_t_24 = NULL;
+  __Pyx_RefNannySetupContext("_write_array_data", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":89
+ *                        int32_t dim, WriteBuffer elem_data,
+ *                        encode_func_ex encoder, const void *encoder_arg):
+ *     if dim < ndims - 1:             # <<<<<<<<<<<<<<
+ *         for item in obj:
+ *             _write_array_data(settings, item, ndims, dim + 1, elem_data,
+ */
+  __pyx_t_1 = ((__pyx_v_dim < (__pyx_v_ndims - 1)) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":90
+ *                        encode_func_ex encoder, const void *encoder_arg):
+ *     if dim < ndims - 1:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             _write_array_data(settings, item, ndims, dim + 1, elem_data,
+ *                               encoder, encoder_arg)
+ */
+    if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+      __pyx_t_2 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
+      __pyx_t_4 = NULL;
+    } else {
+      __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 90, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 90, __pyx_L1_error)
+    }
+    for (;;) {
+      if (likely(!__pyx_t_4)) {
+        if (likely(PyList_CheckExact(__pyx_t_2))) {
+          if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 90, __pyx_L1_error)
+          #else
+          __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 90, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          #endif
+        } else {
+          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 90, __pyx_L1_error)
+          #else
+          __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 90, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          #endif
+        }
+      } else {
+        __pyx_t_5 = __pyx_t_4(__pyx_t_2);
+        if (unlikely(!__pyx_t_5)) {
+          PyObject* exc_type = PyErr_Occurred();
+          if (exc_type) {
+            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+            else __PYX_ERR(4, 90, __pyx_L1_error)
+          }
+          break;
+        }
+        __Pyx_GOTREF(__pyx_t_5);
+      }
+      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_5);
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":91
+ *     if dim < ndims - 1:
+ *         for item in obj:
+ *             _write_array_data(settings, item, ndims, dim + 1, elem_data,             # <<<<<<<<<<<<<<
+ *                               encoder, encoder_arg)
+ *     else:
+ */
+      __pyx_t_5 = __pyx_f_7asyncpg_8protocol_8protocol__write_array_data(__pyx_v_settings, __pyx_v_item, __pyx_v_ndims, (__pyx_v_dim + 1), __pyx_v_elem_data, __pyx_v_encoder, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 91, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":90
+ *                        encode_func_ex encoder, const void *encoder_arg):
+ *     if dim < ndims - 1:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             _write_array_data(settings, item, ndims, dim + 1, elem_data,
+ *                               encoder, encoder_arg)
+ */
+    }
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":89
+ *                        int32_t dim, WriteBuffer elem_data,
+ *                        encode_func_ex encoder, const void *encoder_arg):
+ *     if dim < ndims - 1:             # <<<<<<<<<<<<<<
+ *         for item in obj:
+ *             _write_array_data(settings, item, ndims, dim + 1, elem_data,
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":94
+ *                               encoder, encoder_arg)
+ *     else:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             if item is None:
+ *                 elem_data.write_int32(-1)
+ */
+  /*else*/ {
+    if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+      __pyx_t_2 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
+      __pyx_t_4 = NULL;
+    } else {
+      __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 94, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 94, __pyx_L1_error)
+    }
+    for (;;) {
+      if (likely(!__pyx_t_4)) {
+        if (likely(PyList_CheckExact(__pyx_t_2))) {
+          if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 94, __pyx_L1_error)
+          #else
+          __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 94, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          #endif
+        } else {
+          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 94, __pyx_L1_error)
+          #else
+          __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 94, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          #endif
+        }
+      } else {
+        __pyx_t_5 = __pyx_t_4(__pyx_t_2);
+        if (unlikely(!__pyx_t_5)) {
+          PyObject* exc_type = PyErr_Occurred();
+          if (exc_type) {
+            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+            else __PYX_ERR(4, 94, __pyx_L1_error)
+          }
+          break;
+        }
+        __Pyx_GOTREF(__pyx_t_5);
+      }
+      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_5);
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":95
+ *     else:
+ *         for item in obj:
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 elem_data.write_int32(-1)
+ *             else:
+ */
+      __pyx_t_1 = (__pyx_v_item == Py_None);
+      __pyx_t_6 = (__pyx_t_1 != 0);
+      if (__pyx_t_6) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":96
+ *         for item in obj:
+ *             if item is None:
+ *                 elem_data.write_int32(-1)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 try:
+ */
+        __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_elem_data->__pyx_vtab)->write_int32(__pyx_v_elem_data, -1); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 96, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":95
+ *     else:
+ *         for item in obj:
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 elem_data.write_int32(-1)
+ *             else:
+ */
+        goto __pyx_L8;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":98
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+      /*else*/ {
+        {
+          __Pyx_PyThreadState_declare
+          __Pyx_PyThreadState_assign
+          __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+          __Pyx_XGOTREF(__pyx_t_7);
+          __Pyx_XGOTREF(__pyx_t_8);
+          __Pyx_XGOTREF(__pyx_t_9);
+          /*try:*/ {
+
+            /* "asyncpg/protocol/codecs/array.pyx":99
+ *             else:
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)             # <<<<<<<<<<<<<<
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ */
+            __pyx_t_5 = __pyx_v_encoder(__pyx_v_settings, __pyx_v_elem_data, __pyx_v_item, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 99, __pyx_L9_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+            /* "asyncpg/protocol/codecs/array.pyx":98
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+          }
+          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+          goto __pyx_L16_try_end;
+          __pyx_L9_error:;
+          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":100
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(e.args[0])) from None
+ */
+          __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
+          if (__pyx_t_10) {
+            __Pyx_AddTraceback("asyncpg.protocol.protocol._write_array_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+            if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_11, &__pyx_t_12) < 0) __PYX_ERR(4, 100, __pyx_L11_except_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            __Pyx_GOTREF(__pyx_t_11);
+            __Pyx_GOTREF(__pyx_t_12);
+            __Pyx_INCREF(__pyx_t_11);
+            __pyx_v_e = __pyx_t_11;
+            /*try:*/ {
+
+              /* "asyncpg/protocol/codecs/array.pyx":102
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(e.args[0])) from None             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+              __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_array_element, __pyx_n_s_format); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 102, __pyx_L22_error)
+              __Pyx_GOTREF(__pyx_t_14);
+              __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_15)) __PYX_ERR(4, 102, __pyx_L22_error)
+              __Pyx_GOTREF(__pyx_t_15);
+              __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_15, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(4, 102, __pyx_L22_error)
+              __Pyx_GOTREF(__pyx_t_16);
+              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+              __pyx_t_15 = NULL;
+              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) {
+                __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14);
+                if (likely(__pyx_t_15)) {
+                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
+                  __Pyx_INCREF(__pyx_t_15);
+                  __Pyx_INCREF(function);
+                  __Pyx_DECREF_SET(__pyx_t_14, function);
+                }
+              }
+              __pyx_t_13 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_16);
+              __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+              if (unlikely(!__pyx_t_13)) __PYX_ERR(4, 102, __pyx_L22_error)
+              __Pyx_GOTREF(__pyx_t_13);
+              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":101
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ *                     raise ValueError(             # <<<<<<<<<<<<<<
+ *                         'invalid array element: {}'.format(e.args[0])) from None
+ * 
+ */
+              __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 101, __pyx_L22_error)
+              __Pyx_GOTREF(__pyx_t_14);
+              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":102
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(e.args[0])) from None             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+              __Pyx_Raise(__pyx_t_14, 0, 0, Py_None);
+              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+              __PYX_ERR(4, 101, __pyx_L22_error)
+            }
+
+            /* "asyncpg/protocol/codecs/array.pyx":100
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(e.args[0])) from None
+ */
+            /*finally:*/ {
+              __pyx_L22_error:;
+              /*exception exit:*/{
+                __Pyx_PyThreadState_declare
+                __Pyx_PyThreadState_assign
+                __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0;
+                __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+                __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+                __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24);
+                if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21) < 0)) __Pyx_ErrFetch(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21);
+                __Pyx_XGOTREF(__pyx_t_19);
+                __Pyx_XGOTREF(__pyx_t_20);
+                __Pyx_XGOTREF(__pyx_t_21);
+                __Pyx_XGOTREF(__pyx_t_22);
+                __Pyx_XGOTREF(__pyx_t_23);
+                __Pyx_XGOTREF(__pyx_t_24);
+                __pyx_t_10 = __pyx_lineno; __pyx_t_17 = __pyx_clineno; __pyx_t_18 = __pyx_filename;
+                {
+                  __Pyx_DECREF(__pyx_v_e);
+                  __pyx_v_e = NULL;
+                }
+                if (PY_MAJOR_VERSION >= 3) {
+                  __Pyx_XGIVEREF(__pyx_t_22);
+                  __Pyx_XGIVEREF(__pyx_t_23);
+                  __Pyx_XGIVEREF(__pyx_t_24);
+                  __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_23, __pyx_t_24);
+                }
+                __Pyx_XGIVEREF(__pyx_t_19);
+                __Pyx_XGIVEREF(__pyx_t_20);
+                __Pyx_XGIVEREF(__pyx_t_21);
+                __Pyx_ErrRestore(__pyx_t_19, __pyx_t_20, __pyx_t_21);
+                __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0;
+                __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_17; __pyx_filename = __pyx_t_18;
+                goto __pyx_L11_except_error;
+              }
+            }
+          }
+          goto __pyx_L11_except_error;
+          __pyx_L11_except_error:;
+
+          /* "asyncpg/protocol/codecs/array.pyx":98
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+          __Pyx_XGIVEREF(__pyx_t_7);
+          __Pyx_XGIVEREF(__pyx_t_8);
+          __Pyx_XGIVEREF(__pyx_t_9);
+          __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+          goto __pyx_L1_error;
+          __pyx_L16_try_end:;
+        }
+      }
+      __pyx_L8:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":94
+ *                               encoder, encoder_arg)
+ *     else:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             if item is None:
+ *                 elem_data.write_int32(-1)
+ */
+    }
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/codecs/array.pyx":86
+ * 
+ * 
+ * cdef _write_array_data(ConnectionSettings settings, object obj, int32_t ndims,             # <<<<<<<<<<<<<<
+ *                        int32_t dim, WriteBuffer elem_data,
+ *                        encode_func_ex encoder, const void *encoder_arg):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._write_array_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_item);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":105
+ * 
+ * 
+ * cdef inline array_encode(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                          object obj, uint32_t elem_oid,
+ *                          encode_func_ex encoder, const void *encoder_arg):
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_array_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj, uint32_t __pyx_v_elem_oid, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex __pyx_v_encoder, void const *__pyx_v_encoder_arg) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_elem_data = 0;
+  int32_t __pyx_v_dims[6];
+  int32_t __pyx_v_ndims;
+  int32_t __pyx_v_i;
+  PyObject *__pyx_v_item = NULL;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int32_t __pyx_t_7;
+  Py_ssize_t __pyx_t_8;
+  PyObject *(*__pyx_t_9)(PyObject *);
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  int __pyx_t_20;
+  char const *__pyx_t_21;
+  PyObject *__pyx_t_22 = NULL;
+  PyObject *__pyx_t_23 = NULL;
+  PyObject *__pyx_t_24 = NULL;
+  PyObject *__pyx_t_25 = NULL;
+  PyObject *__pyx_t_26 = NULL;
+  PyObject *__pyx_t_27 = NULL;
+  int32_t __pyx_t_28;
+  int32_t __pyx_t_29;
+  __Pyx_RefNannySetupContext("array_encode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":111
+ *         WriteBuffer elem_data
+ *         int32_t dims[ARRAY_MAXDIM]
+ *         int32_t ndims = 1             # <<<<<<<<<<<<<<
+ *         int32_t i
+ * 
+ */
+  __pyx_v_ndims = 1;
+
+  /* "asyncpg/protocol/codecs/array.pyx":114
+ *         int32_t i
+ * 
+ *     if not _is_array_iterable(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol__is_array_iterable(__pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 114, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(4, 114, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = ((!__pyx_t_2) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":116
+ *     if not _is_array_iterable(obj):
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(             # <<<<<<<<<<<<<<
+ *                 type(obj).__name__))
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_a_sized_iterable_container_expec, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 116, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/protocol/codecs/array.pyx":117
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(
+ *                 type(obj).__name__))             # <<<<<<<<<<<<<<
+ * 
+ *     _get_array_shape(obj, dims, &ndims)
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_obj)), __pyx_n_s_name_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 117, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 116, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":115
+ * 
+ *     if not _is_array_iterable(obj):
+ *         raise TypeError(             # <<<<<<<<<<<<<<
+ *             'a sized iterable container expected (got type {!r})'.format(
+ *                 type(obj).__name__))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 115, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(4, 115, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/array.pyx":114
+ *         int32_t i
+ * 
+ *     if not _is_array_iterable(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":119
+ *                 type(obj).__name__))
+ * 
+ *     _get_array_shape(obj, dims, &ndims)             # <<<<<<<<<<<<<<
+ * 
+ *     elem_data = WriteBuffer.new()
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol__get_array_shape(__pyx_v_obj, __pyx_v_dims, (&__pyx_v_ndims)); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 119, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":121
+ *     _get_array_shape(obj, dims, &ndims)
+ * 
+ *     elem_data = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ * 
+ *     if ndims > 1:
+ */
+  __pyx_t_4 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 121, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_v_elem_data = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":123
+ *     elem_data = WriteBuffer.new()
+ * 
+ *     if ndims > 1:             # <<<<<<<<<<<<<<
+ *         _write_array_data(settings, obj, ndims, 0, elem_data,
+ *                           encoder, encoder_arg)
+ */
+  __pyx_t_3 = ((__pyx_v_ndims > 1) != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":124
+ * 
+ *     if ndims > 1:
+ *         _write_array_data(settings, obj, ndims, 0, elem_data,             # <<<<<<<<<<<<<<
+ *                           encoder, encoder_arg)
+ *     else:
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol__write_array_data(__pyx_v_settings, __pyx_v_obj, __pyx_v_ndims, 0, __pyx_v_elem_data, __pyx_v_encoder, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 124, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":123
+ *     elem_data = WriteBuffer.new()
+ * 
+ *     if ndims > 1:             # <<<<<<<<<<<<<<
+ *         _write_array_data(settings, obj, ndims, 0, elem_data,
+ *                           encoder, encoder_arg)
+ */
+    goto __pyx_L4;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":127
+ *                           encoder, encoder_arg)
+ *     else:
+ *         for i, item in enumerate(obj):             # <<<<<<<<<<<<<<
+ *             if item is None:
+ *                 elem_data.write_int32(-1)
+ */
+  /*else*/ {
+    __pyx_t_7 = 0;
+    if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+      __pyx_t_4 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0;
+      __pyx_t_9 = NULL;
+    } else {
+      __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 127, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 127, __pyx_L1_error)
+    }
+    for (;;) {
+      if (likely(!__pyx_t_9)) {
+        if (likely(PyList_CheckExact(__pyx_t_4))) {
+          if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(4, 127, __pyx_L1_error)
+          #else
+          __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 127, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_1);
+          #endif
+        } else {
+          if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(4, 127, __pyx_L1_error)
+          #else
+          __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 127, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_1);
+          #endif
+        }
+      } else {
+        __pyx_t_1 = __pyx_t_9(__pyx_t_4);
+        if (unlikely(!__pyx_t_1)) {
+          PyObject* exc_type = PyErr_Occurred();
+          if (exc_type) {
+            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+            else __PYX_ERR(4, 127, __pyx_L1_error)
+          }
+          break;
+        }
+        __Pyx_GOTREF(__pyx_t_1);
+      }
+      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
+      __pyx_t_1 = 0;
+      __pyx_v_i = __pyx_t_7;
+      __pyx_t_7 = (__pyx_t_7 + 1);
+
+      /* "asyncpg/protocol/codecs/array.pyx":128
+ *     else:
+ *         for i, item in enumerate(obj):
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 elem_data.write_int32(-1)
+ *             else:
+ */
+      __pyx_t_3 = (__pyx_v_item == Py_None);
+      __pyx_t_2 = (__pyx_t_3 != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":129
+ *         for i, item in enumerate(obj):
+ *             if item is None:
+ *                 elem_data.write_int32(-1)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 try:
+ */
+        __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_elem_data->__pyx_vtab)->write_int32(__pyx_v_elem_data, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 129, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":128
+ *     else:
+ *         for i, item in enumerate(obj):
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 elem_data.write_int32(-1)
+ *             else:
+ */
+        goto __pyx_L7;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":131
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+      /*else*/ {
+        {
+          __Pyx_PyThreadState_declare
+          __Pyx_PyThreadState_assign
+          __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
+          __Pyx_XGOTREF(__pyx_t_10);
+          __Pyx_XGOTREF(__pyx_t_11);
+          __Pyx_XGOTREF(__pyx_t_12);
+          /*try:*/ {
+
+            /* "asyncpg/protocol/codecs/array.pyx":132
+ *             else:
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)             # <<<<<<<<<<<<<<
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ */
+            __pyx_t_1 = __pyx_v_encoder(__pyx_v_settings, __pyx_v_elem_data, __pyx_v_item, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 132, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_1);
+            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+            /* "asyncpg/protocol/codecs/array.pyx":131
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+          }
+          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          goto __pyx_L15_try_end;
+          __pyx_L8_error:;
+          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":133
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'invalid array element at index {}: {}'.format(
+ */
+          __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
+          if (__pyx_t_13) {
+            __Pyx_AddTraceback("asyncpg.protocol.protocol.array_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+            if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(4, 133, __pyx_L10_except_error)
+            __Pyx_GOTREF(__pyx_t_1);
+            __Pyx_GOTREF(__pyx_t_5);
+            __Pyx_GOTREF(__pyx_t_6);
+            __Pyx_INCREF(__pyx_t_5);
+            __pyx_v_e = __pyx_t_5;
+            /*try:*/ {
+
+              /* "asyncpg/protocol/codecs/array.pyx":135
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ *                         'invalid array element at index {}: {}'.format(             # <<<<<<<<<<<<<<
+ *                             i, e.args[0])) from None
+ * 
+ */
+              __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_array_element_at_index, __pyx_n_s_format); if (unlikely(!__pyx_t_15)) __PYX_ERR(4, 135, __pyx_L21_error)
+              __Pyx_GOTREF(__pyx_t_15);
+
+              /* "asyncpg/protocol/codecs/array.pyx":136
+ *                     raise ValueError(
+ *                         'invalid array element at index {}: {}'.format(
+ *                             i, e.args[0])) from None             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(12 + 8 * ndims + elem_data.len())
+ */
+              __pyx_t_16 = __Pyx_PyInt_From_int32_t(__pyx_v_i); if (unlikely(!__pyx_t_16)) __PYX_ERR(4, 136, __pyx_L21_error)
+              __Pyx_GOTREF(__pyx_t_16);
+              __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_17)) __PYX_ERR(4, 136, __pyx_L21_error)
+              __Pyx_GOTREF(__pyx_t_17);
+              __pyx_t_18 = __Pyx_GetItemInt(__pyx_t_17, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_18)) __PYX_ERR(4, 136, __pyx_L21_error)
+              __Pyx_GOTREF(__pyx_t_18);
+              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
+              __pyx_t_17 = NULL;
+              __pyx_t_13 = 0;
+              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
+                __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_15);
+                if (likely(__pyx_t_17)) {
+                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
+                  __Pyx_INCREF(__pyx_t_17);
+                  __Pyx_INCREF(function);
+                  __Pyx_DECREF_SET(__pyx_t_15, function);
+                  __pyx_t_13 = 1;
+                }
+              }
+              #if CYTHON_FAST_PYCALL
+              if (PyFunction_Check(__pyx_t_15)) {
+                PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_16, __pyx_t_18};
+                __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 135, __pyx_L21_error)
+                __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+                __Pyx_GOTREF(__pyx_t_14);
+                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+                __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+              } else
+              #endif
+              #if CYTHON_FAST_PYCCALL
+              if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
+                PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_16, __pyx_t_18};
+                __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 135, __pyx_L21_error)
+                __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+                __Pyx_GOTREF(__pyx_t_14);
+                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+                __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+              } else
+              #endif
+              {
+                __pyx_t_19 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_19)) __PYX_ERR(4, 135, __pyx_L21_error)
+                __Pyx_GOTREF(__pyx_t_19);
+                if (__pyx_t_17) {
+                  __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_17); __pyx_t_17 = NULL;
+                }
+                __Pyx_GIVEREF(__pyx_t_16);
+                PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_13, __pyx_t_16);
+                __Pyx_GIVEREF(__pyx_t_18);
+                PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_13, __pyx_t_18);
+                __pyx_t_16 = 0;
+                __pyx_t_18 = 0;
+                __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_19, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 135, __pyx_L21_error)
+                __Pyx_GOTREF(__pyx_t_14);
+                __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+              }
+              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":134
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ *                     raise ValueError(             # <<<<<<<<<<<<<<
+ *                         'invalid array element at index {}: {}'.format(
+ *                             i, e.args[0])) from None
+ */
+              __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(4, 134, __pyx_L21_error)
+              __Pyx_GOTREF(__pyx_t_15);
+              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":136
+ *                     raise ValueError(
+ *                         'invalid array element at index {}: {}'.format(
+ *                             i, e.args[0])) from None             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(12 + 8 * ndims + elem_data.len())
+ */
+              __Pyx_Raise(__pyx_t_15, 0, 0, Py_None);
+              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+              __PYX_ERR(4, 134, __pyx_L21_error)
+            }
+
+            /* "asyncpg/protocol/codecs/array.pyx":133
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'invalid array element at index {}: {}'.format(
+ */
+            /*finally:*/ {
+              __pyx_L21_error:;
+              /*exception exit:*/{
+                __Pyx_PyThreadState_declare
+                __Pyx_PyThreadState_assign
+                __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; __pyx_t_27 = 0;
+                __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+                __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
+                __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
+                __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+                if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_25, &__pyx_t_26, &__pyx_t_27);
+                if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24) < 0)) __Pyx_ErrFetch(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24);
+                __Pyx_XGOTREF(__pyx_t_22);
+                __Pyx_XGOTREF(__pyx_t_23);
+                __Pyx_XGOTREF(__pyx_t_24);
+                __Pyx_XGOTREF(__pyx_t_25);
+                __Pyx_XGOTREF(__pyx_t_26);
+                __Pyx_XGOTREF(__pyx_t_27);
+                __pyx_t_13 = __pyx_lineno; __pyx_t_20 = __pyx_clineno; __pyx_t_21 = __pyx_filename;
+                {
+                  __Pyx_DECREF(__pyx_v_e);
+                  __pyx_v_e = NULL;
+                }
+                if (PY_MAJOR_VERSION >= 3) {
+                  __Pyx_XGIVEREF(__pyx_t_25);
+                  __Pyx_XGIVEREF(__pyx_t_26);
+                  __Pyx_XGIVEREF(__pyx_t_27);
+                  __Pyx_ExceptionReset(__pyx_t_25, __pyx_t_26, __pyx_t_27);
+                }
+                __Pyx_XGIVEREF(__pyx_t_22);
+                __Pyx_XGIVEREF(__pyx_t_23);
+                __Pyx_XGIVEREF(__pyx_t_24);
+                __Pyx_ErrRestore(__pyx_t_22, __pyx_t_23, __pyx_t_24);
+                __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; __pyx_t_27 = 0;
+                __pyx_lineno = __pyx_t_13; __pyx_clineno = __pyx_t_20; __pyx_filename = __pyx_t_21;
+                goto __pyx_L10_except_error;
+              }
+            }
+          }
+          goto __pyx_L10_except_error;
+          __pyx_L10_except_error:;
+
+          /* "asyncpg/protocol/codecs/array.pyx":131
+ *                 elem_data.write_int32(-1)
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+          __Pyx_XGIVEREF(__pyx_t_10);
+          __Pyx_XGIVEREF(__pyx_t_11);
+          __Pyx_XGIVEREF(__pyx_t_12);
+          __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+          goto __pyx_L1_error;
+          __pyx_L15_try_end:;
+        }
+      }
+      __pyx_L7:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":127
+ *                           encoder, encoder_arg)
+ *     else:
+ *         for i, item in enumerate(obj):             # <<<<<<<<<<<<<<
+ *             if item is None:
+ *                 elem_data.write_int32(-1)
+ */
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  }
+  __pyx_L4:;
+
+  /* "asyncpg/protocol/codecs/array.pyx":138
+ *                             i, e.args[0])) from None
+ * 
+ *     buf.write_int32(12 + 8 * ndims + elem_data.len())             # <<<<<<<<<<<<<<
+ *     # Number of dimensions
+ *     buf.write_int32(ndims)
+ */
+  __pyx_t_4 = __Pyx_PyInt_From_long((12 + (8 * __pyx_v_ndims))); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 138, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_6 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_elem_data); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 138, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 138, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  __pyx_t_7 = __Pyx_PyInt_As_int32_t(__pyx_t_5); if (unlikely((__pyx_t_7 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(4, 138, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 138, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":140
+ *     buf.write_int32(12 + 8 * ndims + elem_data.len())
+ *     # Number of dimensions
+ *     buf.write_int32(ndims)             # <<<<<<<<<<<<<<
+ *     # flags
+ *     buf.write_int32(0)
+ */
+  __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_v_ndims); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 140, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":142
+ *     buf.write_int32(ndims)
+ *     # flags
+ *     buf.write_int32(0)             # <<<<<<<<<<<<<<
+ *     # element type
+ *     buf.write_int32(<int32_t>elem_oid)
+ */
+  __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 142, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":144
+ *     buf.write_int32(0)
+ *     # element type
+ *     buf.write_int32(<int32_t>elem_oid)             # <<<<<<<<<<<<<<
+ *     # upper / lower bounds
+ *     for i in range(ndims):
+ */
+  __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, ((int32_t)__pyx_v_elem_oid)); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 144, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":146
+ *     buf.write_int32(<int32_t>elem_oid)
+ *     # upper / lower bounds
+ *     for i in range(ndims):             # <<<<<<<<<<<<<<
+ *         buf.write_int32(dims[i])
+ *         buf.write_int32(1)
+ */
+  __pyx_t_7 = __pyx_v_ndims;
+  __pyx_t_28 = __pyx_t_7;
+  for (__pyx_t_29 = 0; __pyx_t_29 < __pyx_t_28; __pyx_t_29+=1) {
+    __pyx_v_i = __pyx_t_29;
+
+    /* "asyncpg/protocol/codecs/array.pyx":147
+ *     # upper / lower bounds
+ *     for i in range(ndims):
+ *         buf.write_int32(dims[i])             # <<<<<<<<<<<<<<
+ *         buf.write_int32(1)
+ *     # element data
+ */
+    __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, (__pyx_v_dims[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 147, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":148
+ *     for i in range(ndims):
+ *         buf.write_int32(dims[i])
+ *         buf.write_int32(1)             # <<<<<<<<<<<<<<
+ *     # element data
+ *     buf.write_buffer(elem_data)
+ */
+    __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 148, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":150
+ *         buf.write_int32(1)
+ *     # element data
+ *     buf.write_buffer(elem_data)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_buffer(__pyx_v_buf, __pyx_v_elem_data); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 150, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":105
+ * 
+ * 
+ * cdef inline array_encode(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                          object obj, uint32_t elem_oid,
+ *                          encode_func_ex encoder, const void *encoder_arg):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_XDECREF(__pyx_t_17);
+  __Pyx_XDECREF(__pyx_t_18);
+  __Pyx_XDECREF(__pyx_t_19);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.array_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_data);
+  __Pyx_XDECREF(__pyx_v_item);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":153
+ * 
+ * 
+ * cdef _write_textarray_data(ConnectionSettings settings, object obj,             # <<<<<<<<<<<<<<
+ *                            int32_t ndims, int32_t dim, WriteBuffer array_data,
+ *                            encode_func_ex encoder, const void *encoder_arg,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__write_textarray_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, PyObject *__pyx_v_obj, int32_t __pyx_v_ndims, int32_t __pyx_v_dim, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_array_data, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex __pyx_v_encoder, void const *__pyx_v_encoder_arg, Py_UCS4 __pyx_v_typdelim) {
+  Py_ssize_t __pyx_v_i;
+  int8_t __pyx_v_delim;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_elem_data = 0;
+  Py_buffer __pyx_v_pybuf;
+  char const *__pyx_v_elem_str;
+  char __pyx_v_ch;
+  Py_ssize_t __pyx_v_elem_len;
+  Py_ssize_t __pyx_v_quoted_elem_len;
+  int __pyx_v_need_quoting;
+  PyObject *__pyx_v_item = NULL;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  Py_ssize_t __pyx_t_3;
+  PyObject *(*__pyx_t_4)(PyObject *);
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  int __pyx_t_17;
+  char const *__pyx_t_18;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  PyObject *__pyx_t_21 = NULL;
+  PyObject *__pyx_t_22 = NULL;
+  PyObject *__pyx_t_23 = NULL;
+  PyObject *__pyx_t_24 = NULL;
+  Py_ssize_t __pyx_t_25;
+  Py_ssize_t __pyx_t_26;
+  Py_ssize_t __pyx_t_27;
+  char const *__pyx_t_28;
+  __Pyx_RefNannySetupContext("_write_textarray_data", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":158
+ *                            Py_UCS4 typdelim):
+ *     cdef:
+ *         ssize_t i = 0             # <<<<<<<<<<<<<<
+ *         int8_t delim = <int8_t>typdelim
+ *         WriteBuffer elem_data
+ */
+  __pyx_v_i = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":159
+ *     cdef:
+ *         ssize_t i = 0
+ *         int8_t delim = <int8_t>typdelim             # <<<<<<<<<<<<<<
+ *         WriteBuffer elem_data
+ *         Py_buffer pybuf
+ */
+  __pyx_v_delim = ((int8_t)__pyx_v_typdelim);
+
+  /* "asyncpg/protocol/codecs/array.pyx":168
+ *         bint need_quoting
+ * 
+ *     array_data.write_byte(b'{')             # <<<<<<<<<<<<<<
+ * 
+ *     if dim < ndims - 1:
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, '{'); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 168, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":170
+ *     array_data.write_byte(b'{')
+ * 
+ *     if dim < ndims - 1:             # <<<<<<<<<<<<<<
+ *         for item in obj:
+ *             if i > 0:
+ */
+    __pyx_t_2 = ((__pyx_v_dim < (__pyx_v_ndims - 1)) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":171
+ * 
+ *     if dim < ndims - 1:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             if i > 0:
+ *                 array_data.write_byte(delim)
+ */
+      if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+        __pyx_t_1 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
+        __pyx_t_4 = NULL;
+      } else {
+        __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 171, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 171, __pyx_L1_error)
+      }
+      for (;;) {
+        if (likely(!__pyx_t_4)) {
+          if (likely(PyList_CheckExact(__pyx_t_1))) {
+            if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
+            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+            __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 171, __pyx_L1_error)
+            #else
+            __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 171, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            #endif
+          } else {
+            if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+            __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 171, __pyx_L1_error)
+            #else
+            __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 171, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            #endif
+          }
+        } else {
+          __pyx_t_5 = __pyx_t_4(__pyx_t_1);
+          if (unlikely(!__pyx_t_5)) {
+            PyObject* exc_type = PyErr_Occurred();
+            if (exc_type) {
+              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+              else __PYX_ERR(4, 171, __pyx_L1_error)
+            }
+            break;
+          }
+          __Pyx_GOTREF(__pyx_t_5);
+        }
+        __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_5);
+        __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":172
+ *     if dim < ndims - 1:
+ *         for item in obj:
+ *             if i > 0:             # <<<<<<<<<<<<<<
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')
+ */
+        __pyx_t_2 = ((__pyx_v_i > 0) != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":173
+ *         for item in obj:
+ *             if i > 0:
+ *                 array_data.write_byte(delim)             # <<<<<<<<<<<<<<
+ *                 array_data.write_byte(b' ')
+ *             _write_textarray_data(settings, item, ndims, dim + 1, array_data,
+ */
+          __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, __pyx_v_delim); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 173, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":174
+ *             if i > 0:
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')             # <<<<<<<<<<<<<<
+ *             _write_textarray_data(settings, item, ndims, dim + 1, array_data,
+ *                                   encoder, encoder_arg, typdelim)
+ */
+          __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, ' '); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 174, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":172
+ *     if dim < ndims - 1:
+ *         for item in obj:
+ *             if i > 0:             # <<<<<<<<<<<<<<
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":175
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')
+ *             _write_textarray_data(settings, item, ndims, dim + 1, array_data,             # <<<<<<<<<<<<<<
+ *                                   encoder, encoder_arg, typdelim)
+ *             i += 1
+ */
+        __pyx_t_5 = __pyx_f_7asyncpg_8protocol_8protocol__write_textarray_data(__pyx_v_settings, __pyx_v_item, __pyx_v_ndims, (__pyx_v_dim + 1), __pyx_v_array_data, __pyx_v_encoder, __pyx_v_encoder_arg, __pyx_v_typdelim); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 175, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":177
+ *             _write_textarray_data(settings, item, ndims, dim + 1, array_data,
+ *                                   encoder, encoder_arg, typdelim)
+ *             i += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for item in obj:
+ */
+        __pyx_v_i = (__pyx_v_i + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":171
+ * 
+ *     if dim < ndims - 1:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             if i > 0:
+ *                 array_data.write_byte(delim)
+ */
+      }
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":170
+ *     array_data.write_byte(b'{')
+ * 
+ *     if dim < ndims - 1:             # <<<<<<<<<<<<<<
+ *         for item in obj:
+ *             if i > 0:
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":179
+ *             i += 1
+ *     else:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             elem_data = WriteBuffer.new()
+ * 
+ */
+    /*else*/ {
+      if (likely(PyList_CheckExact(__pyx_v_obj)) || PyTuple_CheckExact(__pyx_v_obj)) {
+        __pyx_t_1 = __pyx_v_obj; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
+        __pyx_t_4 = NULL;
+      } else {
+        __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 179, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 179, __pyx_L1_error)
+      }
+      for (;;) {
+        if (likely(!__pyx_t_4)) {
+          if (likely(PyList_CheckExact(__pyx_t_1))) {
+            if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
+            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+            __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 179, __pyx_L1_error)
+            #else
+            __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 179, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            #endif
+          } else {
+            if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+            __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(4, 179, __pyx_L1_error)
+            #else
+            __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 179, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            #endif
+          }
+        } else {
+          __pyx_t_5 = __pyx_t_4(__pyx_t_1);
+          if (unlikely(!__pyx_t_5)) {
+            PyObject* exc_type = PyErr_Occurred();
+            if (exc_type) {
+              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+              else __PYX_ERR(4, 179, __pyx_L1_error)
+            }
+            break;
+          }
+          __Pyx_GOTREF(__pyx_t_5);
+        }
+        __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_5);
+        __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":180
+ *     else:
+ *         for item in obj:
+ *             elem_data = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ * 
+ *             if i > 0:
+ */
+        __pyx_t_5 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 180, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_XDECREF_SET(__pyx_v_elem_data, ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_5));
+        __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":182
+ *             elem_data = WriteBuffer.new()
+ * 
+ *             if i > 0:             # <<<<<<<<<<<<<<
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')
+ */
+        __pyx_t_2 = ((__pyx_v_i > 0) != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":183
+ * 
+ *             if i > 0:
+ *                 array_data.write_byte(delim)             # <<<<<<<<<<<<<<
+ *                 array_data.write_byte(b' ')
+ * 
+ */
+          __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, __pyx_v_delim); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 183, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":184
+ *             if i > 0:
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')             # <<<<<<<<<<<<<<
+ * 
+ *             if item is None:
+ */
+          __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, ' '); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 184, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":182
+ *             elem_data = WriteBuffer.new()
+ * 
+ *             if i > 0:             # <<<<<<<<<<<<<<
+ *                 array_data.write_byte(delim)
+ *                 array_data.write_byte(b' ')
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":186
+ *                 array_data.write_byte(b' ')
+ * 
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 array_data.write_bytes(b'NULL')
+ *                 i += 1
+ */
+        __pyx_t_2 = (__pyx_v_item == Py_None);
+        __pyx_t_6 = (__pyx_t_2 != 0);
+        if (__pyx_t_6) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":187
+ * 
+ *             if item is None:
+ *                 array_data.write_bytes(b'NULL')             # <<<<<<<<<<<<<<
+ *                 i += 1
+ *                 continue
+ */
+          __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_bytes(__pyx_v_array_data, __pyx_n_b_NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 187, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_5);
+          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":188
+ *             if item is None:
+ *                 array_data.write_bytes(b'NULL')
+ *                 i += 1             # <<<<<<<<<<<<<<
+ *                 continue
+ *             else:
+ */
+          __pyx_v_i = (__pyx_v_i + 1);
+
+          /* "asyncpg/protocol/codecs/array.pyx":189
+ *                 array_data.write_bytes(b'NULL')
+ *                 i += 1
+ *                 continue             # <<<<<<<<<<<<<<
+ *             else:
+ *                 try:
+ */
+          goto __pyx_L7_continue;
+
+          /* "asyncpg/protocol/codecs/array.pyx":186
+ *                 array_data.write_byte(b' ')
+ * 
+ *             if item is None:             # <<<<<<<<<<<<<<
+ *                 array_data.write_bytes(b'NULL')
+ *                 i += 1
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":191
+ *                 continue
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+        /*else*/ {
+          {
+            __Pyx_PyThreadState_declare
+            __Pyx_PyThreadState_assign
+            __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+            __Pyx_XGOTREF(__pyx_t_7);
+            __Pyx_XGOTREF(__pyx_t_8);
+            __Pyx_XGOTREF(__pyx_t_9);
+            /*try:*/ {
+
+              /* "asyncpg/protocol/codecs/array.pyx":192
+ *             else:
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)             # <<<<<<<<<<<<<<
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ */
+              __pyx_t_5 = __pyx_v_encoder(__pyx_v_settings, __pyx_v_elem_data, __pyx_v_item, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 192, __pyx_L11_error)
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":191
+ *                 continue
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+            }
+            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+            goto __pyx_L18_try_end;
+            __pyx_L11_error:;
+            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+            /* "asyncpg/protocol/codecs/array.pyx":193
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(
+ */
+            __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
+            if (__pyx_t_10) {
+              __Pyx_AddTraceback("asyncpg.protocol.protocol._write_textarray_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+              if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_11, &__pyx_t_12) < 0) __PYX_ERR(4, 193, __pyx_L13_except_error)
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_GOTREF(__pyx_t_11);
+              __Pyx_GOTREF(__pyx_t_12);
+              __Pyx_INCREF(__pyx_t_11);
+              __pyx_v_e = __pyx_t_11;
+              /*try:*/ {
+
+                /* "asyncpg/protocol/codecs/array.pyx":195
+ *                 except TypeError as e:
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(             # <<<<<<<<<<<<<<
+ *                             e.args[0])) from None
+ * 
+ */
+                __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_array_element, __pyx_n_s_format); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 195, __pyx_L24_error)
+                __Pyx_GOTREF(__pyx_t_14);
+
+                /* "asyncpg/protocol/codecs/array.pyx":196
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(
+ *                             e.args[0])) from None             # <<<<<<<<<<<<<<
+ * 
+ *             # element string length (first four bytes are the encoded length.)
+ */
+                __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_15)) __PYX_ERR(4, 196, __pyx_L24_error)
+                __Pyx_GOTREF(__pyx_t_15);
+                __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_15, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(4, 196, __pyx_L24_error)
+                __Pyx_GOTREF(__pyx_t_16);
+                __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+                __pyx_t_15 = NULL;
+                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) {
+                  __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14);
+                  if (likely(__pyx_t_15)) {
+                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
+                    __Pyx_INCREF(__pyx_t_15);
+                    __Pyx_INCREF(function);
+                    __Pyx_DECREF_SET(__pyx_t_14, function);
+                  }
+                }
+                __pyx_t_13 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_16);
+                __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+                if (unlikely(!__pyx_t_13)) __PYX_ERR(4, 195, __pyx_L24_error)
+                __Pyx_GOTREF(__pyx_t_13);
+                __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+
+                /* "asyncpg/protocol/codecs/array.pyx":194
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ *                     raise ValueError(             # <<<<<<<<<<<<<<
+ *                         'invalid array element: {}'.format(
+ *                             e.args[0])) from None
+ */
+                __pyx_t_14 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 194, __pyx_L24_error)
+                __Pyx_GOTREF(__pyx_t_14);
+                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+
+                /* "asyncpg/protocol/codecs/array.pyx":196
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(
+ *                             e.args[0])) from None             # <<<<<<<<<<<<<<
+ * 
+ *             # element string length (first four bytes are the encoded length.)
+ */
+                __Pyx_Raise(__pyx_t_14, 0, 0, Py_None);
+                __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+                __PYX_ERR(4, 194, __pyx_L24_error)
+              }
+
+              /* "asyncpg/protocol/codecs/array.pyx":193
+ *                 try:
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'invalid array element: {}'.format(
+ */
+              /*finally:*/ {
+                __pyx_L24_error:;
+                /*exception exit:*/{
+                  __Pyx_PyThreadState_declare
+                  __Pyx_PyThreadState_assign
+                  __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0;
+                  __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+                  __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                  __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+                  __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                  if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24);
+                  if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21) < 0)) __Pyx_ErrFetch(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21);
+                  __Pyx_XGOTREF(__pyx_t_19);
+                  __Pyx_XGOTREF(__pyx_t_20);
+                  __Pyx_XGOTREF(__pyx_t_21);
+                  __Pyx_XGOTREF(__pyx_t_22);
+                  __Pyx_XGOTREF(__pyx_t_23);
+                  __Pyx_XGOTREF(__pyx_t_24);
+                  __pyx_t_10 = __pyx_lineno; __pyx_t_17 = __pyx_clineno; __pyx_t_18 = __pyx_filename;
+                  {
+                    __Pyx_DECREF(__pyx_v_e);
+                    __pyx_v_e = NULL;
+                  }
+                  if (PY_MAJOR_VERSION >= 3) {
+                    __Pyx_XGIVEREF(__pyx_t_22);
+                    __Pyx_XGIVEREF(__pyx_t_23);
+                    __Pyx_XGIVEREF(__pyx_t_24);
+                    __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_23, __pyx_t_24);
+                  }
+                  __Pyx_XGIVEREF(__pyx_t_19);
+                  __Pyx_XGIVEREF(__pyx_t_20);
+                  __Pyx_XGIVEREF(__pyx_t_21);
+                  __Pyx_ErrRestore(__pyx_t_19, __pyx_t_20, __pyx_t_21);
+                  __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0;
+                  __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_17; __pyx_filename = __pyx_t_18;
+                  goto __pyx_L13_except_error;
+                }
+              }
+            }
+            goto __pyx_L13_except_error;
+            __pyx_L13_except_error:;
+
+            /* "asyncpg/protocol/codecs/array.pyx":191
+ *                 continue
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     encoder(settings, elem_data, item, encoder_arg)
+ *                 except TypeError as e:
+ */
+            __Pyx_XGIVEREF(__pyx_t_7);
+            __Pyx_XGIVEREF(__pyx_t_8);
+            __Pyx_XGIVEREF(__pyx_t_9);
+            __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+            goto __pyx_L1_error;
+            __pyx_L18_try_end:;
+          }
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":199
+ * 
+ *             # element string length (first four bytes are the encoded length.)
+ *             elem_len = elem_data.len() - 4             # <<<<<<<<<<<<<<
+ * 
+ *             if elem_len == 0:
+ */
+        __pyx_t_12 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_elem_data); if (unlikely(!__pyx_t_12)) __PYX_ERR(4, 199, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_12);
+        __pyx_t_11 = __Pyx_PyInt_SubtractObjC(__pyx_t_12, __pyx_int_4, 4, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 199, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+        __pyx_t_25 = PyInt_AsSsize_t(__pyx_t_11); if (unlikely((__pyx_t_25 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(4, 199, __pyx_L1_error)
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __pyx_v_elem_len = __pyx_t_25;
+
+        /* "asyncpg/protocol/codecs/array.pyx":201
+ *             elem_len = elem_data.len() - 4
+ * 
+ *             if elem_len == 0:             # <<<<<<<<<<<<<<
+ *                 # Empty string
+ *                 array_data.write_bytes(b'""')
+ */
+        __pyx_t_6 = ((__pyx_v_elem_len == 0) != 0);
+        if (__pyx_t_6) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":203
+ *             if elem_len == 0:
+ *                 # Empty string
+ *                 array_data.write_bytes(b'""')             # <<<<<<<<<<<<<<
+ *             else:
+ *                 cpython.PyObject_GetBuffer(
+ */
+          __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_bytes(__pyx_v_array_data, __pyx_kp_b__18); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 203, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":201
+ *             elem_len = elem_data.len() - 4
+ * 
+ *             if elem_len == 0:             # <<<<<<<<<<<<<<
+ *                 # Empty string
+ *                 array_data.write_bytes(b'""')
+ */
+          goto __pyx_L30;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":205
+ *                 array_data.write_bytes(b'""')
+ *             else:
+ *                 cpython.PyObject_GetBuffer(             # <<<<<<<<<<<<<<
+ *                     elem_data, &pybuf, cpython.PyBUF_SIMPLE)
+ * 
+ */
+        /*else*/ {
+
+          /* "asyncpg/protocol/codecs/array.pyx":206
+ *             else:
+ *                 cpython.PyObject_GetBuffer(
+ *                     elem_data, &pybuf, cpython.PyBUF_SIMPLE)             # <<<<<<<<<<<<<<
+ * 
+ *                 elem_str = <const char*>(pybuf.buf) + 4
+ */
+          __pyx_t_17 = PyObject_GetBuffer(((PyObject *)__pyx_v_elem_data), (&__pyx_v_pybuf), PyBUF_SIMPLE); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(4, 205, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":208
+ *                     elem_data, &pybuf, cpython.PyBUF_SIMPLE)
+ * 
+ *                 elem_str = <const char*>(pybuf.buf) + 4             # <<<<<<<<<<<<<<
+ * 
+ *                 try:
+ */
+          __pyx_v_elem_str = (((char const *)__pyx_v_pybuf.buf) + 4);
+
+          /* "asyncpg/protocol/codecs/array.pyx":210
+ *                 elem_str = <const char*>(pybuf.buf) + 4
+ * 
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     if not apg_strcasecmp_char(elem_str, b'NULL'):
+ *                         array_data.write_bytes(b'"NULL"')
+ */
+          /*try:*/ {
+
+            /* "asyncpg/protocol/codecs/array.pyx":211
+ * 
+ *                 try:
+ *                     if not apg_strcasecmp_char(elem_str, b'NULL'):             # <<<<<<<<<<<<<<
+ *                         array_data.write_bytes(b'"NULL"')
+ *                     else:
+ */
+            __pyx_t_6 = ((!(__pyx_f_7asyncpg_8protocol_8protocol_apg_strcasecmp_char(__pyx_v_elem_str, ((char const *)"NULL")) != 0)) != 0);
+            if (__pyx_t_6) {
+
+              /* "asyncpg/protocol/codecs/array.pyx":212
+ *                 try:
+ *                     if not apg_strcasecmp_char(elem_str, b'NULL'):
+ *                         array_data.write_bytes(b'"NULL"')             # <<<<<<<<<<<<<<
+ *                     else:
+ *                         quoted_elem_len = elem_len
+ */
+              __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_bytes(__pyx_v_array_data, __pyx_kp_b_NULL_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 212, __pyx_L34_error)
+              __Pyx_GOTREF(__pyx_t_11);
+              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":211
+ * 
+ *                 try:
+ *                     if not apg_strcasecmp_char(elem_str, b'NULL'):             # <<<<<<<<<<<<<<
+ *                         array_data.write_bytes(b'"NULL"')
+ *                     else:
+ */
+              goto __pyx_L36;
+            }
+
+            /* "asyncpg/protocol/codecs/array.pyx":214
+ *                         array_data.write_bytes(b'"NULL"')
+ *                     else:
+ *                         quoted_elem_len = elem_len             # <<<<<<<<<<<<<<
+ *                         need_quoting = False
+ * 
+ */
+            /*else*/ {
+              __pyx_v_quoted_elem_len = __pyx_v_elem_len;
+
+              /* "asyncpg/protocol/codecs/array.pyx":215
+ *                     else:
+ *                         quoted_elem_len = elem_len
+ *                         need_quoting = False             # <<<<<<<<<<<<<<
+ * 
+ *                         for i in range(elem_len):
+ */
+              __pyx_v_need_quoting = 0;
+
+              /* "asyncpg/protocol/codecs/array.pyx":217
+ *                         need_quoting = False
+ * 
+ *                         for i in range(elem_len):             # <<<<<<<<<<<<<<
+ *                             ch = elem_str[i]
+ *                             if ch == b'"' or ch == b'\\':
+ */
+              __pyx_t_25 = __pyx_v_elem_len;
+              __pyx_t_26 = __pyx_t_25;
+              for (__pyx_t_27 = 0; __pyx_t_27 < __pyx_t_26; __pyx_t_27+=1) {
+                __pyx_v_i = __pyx_t_27;
+
+                /* "asyncpg/protocol/codecs/array.pyx":218
+ * 
+ *                         for i in range(elem_len):
+ *                             ch = elem_str[i]             # <<<<<<<<<<<<<<
+ *                             if ch == b'"' or ch == b'\\':
+ *                                 # Quotes and backslashes need escaping.
+ */
+                __pyx_v_ch = (__pyx_v_elem_str[__pyx_v_i]);
+
+                /* "asyncpg/protocol/codecs/array.pyx":219
+ *                         for i in range(elem_len):
+ *                             ch = elem_str[i]
+ *                             if ch == b'"' or ch == b'\\':             # <<<<<<<<<<<<<<
+ *                                 # Quotes and backslashes need escaping.
+ *                                 quoted_elem_len += 1
+ */
+                switch (__pyx_v_ch) {
+                  case '"':
+                  case '\\':
+                  __pyx_t_6 = 1;
+                  break;
+                  default:
+                  __pyx_t_6 = 0;
+                  break;
+                }
+                if (__pyx_t_6) {
+
+                  /* "asyncpg/protocol/codecs/array.pyx":221
+ *                             if ch == b'"' or ch == b'\\':
+ *                                 # Quotes and backslashes need escaping.
+ *                                 quoted_elem_len += 1             # <<<<<<<<<<<<<<
+ *                                 need_quoting = True
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or
+ */
+                  __pyx_v_quoted_elem_len = (__pyx_v_quoted_elem_len + 1);
+
+                  /* "asyncpg/protocol/codecs/array.pyx":222
+ *                                 # Quotes and backslashes need escaping.
+ *                                 quoted_elem_len += 1
+ *                                 need_quoting = True             # <<<<<<<<<<<<<<
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or
+ *                                     apg_ascii_isspace(<uint32_t>ch)):
+ */
+                  __pyx_v_need_quoting = 1;
+
+                  /* "asyncpg/protocol/codecs/array.pyx":219
+ *                         for i in range(elem_len):
+ *                             ch = elem_str[i]
+ *                             if ch == b'"' or ch == b'\\':             # <<<<<<<<<<<<<<
+ *                                 # Quotes and backslashes need escaping.
+ *                                 quoted_elem_len += 1
+ */
+                  goto __pyx_L39;
+                }
+
+                /* "asyncpg/protocol/codecs/array.pyx":223
+ *                                 quoted_elem_len += 1
+ *                                 need_quoting = True
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or             # <<<<<<<<<<<<<<
+ *                                     apg_ascii_isspace(<uint32_t>ch)):
+ *                                 need_quoting = True
+ */
+                __pyx_t_2 = ((__pyx_v_ch == '{') != 0);
+                  if (!__pyx_t_2) {
+                  } else {
+                    __pyx_t_6 = __pyx_t_2;
+                    goto __pyx_L40_bool_binop_done;
+                  }
+                __pyx_t_2 = ((__pyx_v_ch == '}') != 0);
+                if (!__pyx_t_2) {
+                } else {
+                  __pyx_t_6 = __pyx_t_2;
+                  goto __pyx_L40_bool_binop_done;
+                }
+                __pyx_t_2 = ((__pyx_v_ch == __pyx_v_delim) != 0);
+                if (!__pyx_t_2) {
+                } else {
+                  __pyx_t_6 = __pyx_t_2;
+                  goto __pyx_L40_bool_binop_done;
+                }
+
+                /* "asyncpg/protocol/codecs/array.pyx":224
+ *                                 need_quoting = True
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or
+ *                                     apg_ascii_isspace(<uint32_t>ch)):             # <<<<<<<<<<<<<<
+ *                                 need_quoting = True
+ * 
+ */
+                __pyx_t_2 = (__pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace(((uint32_t)__pyx_v_ch)) != 0);
+                __pyx_t_6 = __pyx_t_2;
+                __pyx_L40_bool_binop_done:;
+
+                /* "asyncpg/protocol/codecs/array.pyx":223
+ *                                 quoted_elem_len += 1
+ *                                 need_quoting = True
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or             # <<<<<<<<<<<<<<
+ *                                     apg_ascii_isspace(<uint32_t>ch)):
+ *                                 need_quoting = True
+ */
+                if (__pyx_t_6) {
+
+                  /* "asyncpg/protocol/codecs/array.pyx":225
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or
+ *                                     apg_ascii_isspace(<uint32_t>ch)):
+ *                                 need_quoting = True             # <<<<<<<<<<<<<<
+ * 
+ *                         if need_quoting:
+ */
+                  __pyx_v_need_quoting = 1;
+
+                  /* "asyncpg/protocol/codecs/array.pyx":223
+ *                                 quoted_elem_len += 1
+ *                                 need_quoting = True
+ *                             elif (ch == b'{' or ch == b'}' or ch == delim or             # <<<<<<<<<<<<<<
+ *                                     apg_ascii_isspace(<uint32_t>ch)):
+ *                                 need_quoting = True
+ */
+                }
+                __pyx_L39:;
+              }
+
+              /* "asyncpg/protocol/codecs/array.pyx":227
+ *                                 need_quoting = True
+ * 
+ *                         if need_quoting:             # <<<<<<<<<<<<<<
+ *                             array_data.write_byte(b'"')
+ * 
+ */
+              __pyx_t_6 = (__pyx_v_need_quoting != 0);
+              if (__pyx_t_6) {
+
+                /* "asyncpg/protocol/codecs/array.pyx":228
+ * 
+ *                         if need_quoting:
+ *                             array_data.write_byte(b'"')             # <<<<<<<<<<<<<<
+ * 
+ *                             if quoted_elem_len == elem_len:
+ */
+                __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, '"'); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 228, __pyx_L34_error)
+                __Pyx_GOTREF(__pyx_t_11);
+                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+                /* "asyncpg/protocol/codecs/array.pyx":230
+ *                             array_data.write_byte(b'"')
+ * 
+ *                             if quoted_elem_len == elem_len:             # <<<<<<<<<<<<<<
+ *                                 array_data.write_cstr(elem_str, elem_len)
+ *                             else:
+ */
+                __pyx_t_6 = ((__pyx_v_quoted_elem_len == __pyx_v_elem_len) != 0);
+                if (__pyx_t_6) {
+
+                  /* "asyncpg/protocol/codecs/array.pyx":231
+ * 
+ *                             if quoted_elem_len == elem_len:
+ *                                 array_data.write_cstr(elem_str, elem_len)             # <<<<<<<<<<<<<<
+ *                             else:
+ *                                 # Escaping required.
+ */
+                  __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_cstr(__pyx_v_array_data, __pyx_v_elem_str, __pyx_v_elem_len); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 231, __pyx_L34_error)
+                  __Pyx_GOTREF(__pyx_t_11);
+                  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+                  /* "asyncpg/protocol/codecs/array.pyx":230
+ *                             array_data.write_byte(b'"')
+ * 
+ *                             if quoted_elem_len == elem_len:             # <<<<<<<<<<<<<<
+ *                                 array_data.write_cstr(elem_str, elem_len)
+ *                             else:
+ */
+                  goto __pyx_L45;
+                }
+
+                /* "asyncpg/protocol/codecs/array.pyx":234
+ *                             else:
+ *                                 # Escaping required.
+ *                                 for i in range(elem_len):             # <<<<<<<<<<<<<<
+ *                                     ch = elem_str[i]
+ *                                     if ch == b'"' or ch == b'\\':
+ */
+                /*else*/ {
+                  __pyx_t_25 = __pyx_v_elem_len;
+                  __pyx_t_26 = __pyx_t_25;
+                  for (__pyx_t_27 = 0; __pyx_t_27 < __pyx_t_26; __pyx_t_27+=1) {
+                    __pyx_v_i = __pyx_t_27;
+
+                    /* "asyncpg/protocol/codecs/array.pyx":235
+ *                                 # Escaping required.
+ *                                 for i in range(elem_len):
+ *                                     ch = elem_str[i]             # <<<<<<<<<<<<<<
+ *                                     if ch == b'"' or ch == b'\\':
+ *                                         array_data.write_byte(b'\\')
+ */
+                    __pyx_v_ch = (__pyx_v_elem_str[__pyx_v_i]);
+
+                    /* "asyncpg/protocol/codecs/array.pyx":236
+ *                                 for i in range(elem_len):
+ *                                     ch = elem_str[i]
+ *                                     if ch == b'"' or ch == b'\\':             # <<<<<<<<<<<<<<
+ *                                         array_data.write_byte(b'\\')
+ *                                     array_data.write_byte(ch)
+ */
+                    switch (__pyx_v_ch) {
+                      case '"':
+                      case '\\':
+
+                      /* "asyncpg/protocol/codecs/array.pyx":237
+ *                                     ch = elem_str[i]
+ *                                     if ch == b'"' or ch == b'\\':
+ *                                         array_data.write_byte(b'\\')             # <<<<<<<<<<<<<<
+ *                                     array_data.write_byte(ch)
+ * 
+ */
+                      __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, '\\'); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 237, __pyx_L34_error)
+                      __Pyx_GOTREF(__pyx_t_11);
+                      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+                      /* "asyncpg/protocol/codecs/array.pyx":236
+ *                                 for i in range(elem_len):
+ *                                     ch = elem_str[i]
+ *                                     if ch == b'"' or ch == b'\\':             # <<<<<<<<<<<<<<
+ *                                         array_data.write_byte(b'\\')
+ *                                     array_data.write_byte(ch)
+ */
+                      break;
+                      default: break;
+                    }
+
+                    /* "asyncpg/protocol/codecs/array.pyx":238
+ *                                     if ch == b'"' or ch == b'\\':
+ *                                         array_data.write_byte(b'\\')
+ *                                     array_data.write_byte(ch)             # <<<<<<<<<<<<<<
+ * 
+ *                             array_data.write_byte(b'"')
+ */
+                    __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, __pyx_v_ch); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 238, __pyx_L34_error)
+                    __Pyx_GOTREF(__pyx_t_11);
+                    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                  }
+                }
+                __pyx_L45:;
+
+                /* "asyncpg/protocol/codecs/array.pyx":240
+ *                                     array_data.write_byte(ch)
+ * 
+ *                             array_data.write_byte(b'"')             # <<<<<<<<<<<<<<
+ *                         else:
+ *                             array_data.write_cstr(elem_str, elem_len)
+ */
+                __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, '"'); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 240, __pyx_L34_error)
+                __Pyx_GOTREF(__pyx_t_11);
+                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+                /* "asyncpg/protocol/codecs/array.pyx":227
+ *                                 need_quoting = True
+ * 
+ *                         if need_quoting:             # <<<<<<<<<<<<<<
+ *                             array_data.write_byte(b'"')
+ * 
+ */
+                goto __pyx_L44;
+              }
+
+              /* "asyncpg/protocol/codecs/array.pyx":242
+ *                             array_data.write_byte(b'"')
+ *                         else:
+ *                             array_data.write_cstr(elem_str, elem_len)             # <<<<<<<<<<<<<<
+ *                 finally:
+ *                     cpython.PyBuffer_Release(&pybuf)
+ */
+              /*else*/ {
+                __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_cstr(__pyx_v_array_data, __pyx_v_elem_str, __pyx_v_elem_len); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 242, __pyx_L34_error)
+                __Pyx_GOTREF(__pyx_t_11);
+                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+              }
+              __pyx_L44:;
+            }
+            __pyx_L36:;
+          }
+
+          /* "asyncpg/protocol/codecs/array.pyx":244
+ *                             array_data.write_cstr(elem_str, elem_len)
+ *                 finally:
+ *                     cpython.PyBuffer_Release(&pybuf)             # <<<<<<<<<<<<<<
+ * 
+ *             i += 1
+ */
+          /*finally:*/ {
+            /*normal exit:*/{
+              PyBuffer_Release((&__pyx_v_pybuf));
+              goto __pyx_L35;
+            }
+            __pyx_L34_error:;
+            /*exception exit:*/{
+              __Pyx_PyThreadState_declare
+              __Pyx_PyThreadState_assign
+              __pyx_t_9 = 0; __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_24 = 0; __pyx_t_23 = 0; __pyx_t_22 = 0;
+              __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+              __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+              __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+              if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_24, &__pyx_t_23, &__pyx_t_22);
+              if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
+              __Pyx_XGOTREF(__pyx_t_9);
+              __Pyx_XGOTREF(__pyx_t_8);
+              __Pyx_XGOTREF(__pyx_t_7);
+              __Pyx_XGOTREF(__pyx_t_24);
+              __Pyx_XGOTREF(__pyx_t_23);
+              __Pyx_XGOTREF(__pyx_t_22);
+              __pyx_t_17 = __pyx_lineno; __pyx_t_10 = __pyx_clineno; __pyx_t_28 = __pyx_filename;
+              {
+                PyBuffer_Release((&__pyx_v_pybuf));
+              }
+              if (PY_MAJOR_VERSION >= 3) {
+                __Pyx_XGIVEREF(__pyx_t_24);
+                __Pyx_XGIVEREF(__pyx_t_23);
+                __Pyx_XGIVEREF(__pyx_t_22);
+                __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_23, __pyx_t_22);
+              }
+              __Pyx_XGIVEREF(__pyx_t_9);
+              __Pyx_XGIVEREF(__pyx_t_8);
+              __Pyx_XGIVEREF(__pyx_t_7);
+              __Pyx_ErrRestore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
+              __pyx_t_9 = 0; __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_24 = 0; __pyx_t_23 = 0; __pyx_t_22 = 0;
+              __pyx_lineno = __pyx_t_17; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_28;
+              goto __pyx_L1_error;
+            }
+            __pyx_L35:;
+          }
+        }
+        __pyx_L30:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":246
+ *                     cpython.PyBuffer_Release(&pybuf)
+ * 
+ *             i += 1             # <<<<<<<<<<<<<<
+ * 
+ *     array_data.write_byte(b'}')
+ */
+        __pyx_v_i = (__pyx_v_i + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":179
+ *             i += 1
+ *     else:
+ *         for item in obj:             # <<<<<<<<<<<<<<
+ *             elem_data = WriteBuffer.new()
+ * 
+ */
+        __pyx_L7_continue:;
+      }
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    }
+    __pyx_L3:;
+
+    /* "asyncpg/protocol/codecs/array.pyx":248
+ *             i += 1
+ * 
+ *     array_data.write_byte(b'}')             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_array_data->__pyx_vtab)->write_byte(__pyx_v_array_data, '}'); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 248, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":153
+ * 
+ * 
+ * cdef _write_textarray_data(ConnectionSettings settings, object obj,             # <<<<<<<<<<<<<<
+ *                            int32_t ndims, int32_t dim, WriteBuffer array_data,
+ *                            encode_func_ex encoder, const void *encoder_arg,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._write_textarray_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_data);
+  __Pyx_XDECREF(__pyx_v_item);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":251
+ * 
+ * 
+ * cdef inline textarray_encode(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                              object obj, encode_func_ex encoder,
+ *                              const void *encoder_arg, Py_UCS4 typdelim):
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_textarray_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex __pyx_v_encoder, void const *__pyx_v_encoder_arg, Py_UCS4 __pyx_v_typdelim) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_array_data = 0;
+  int32_t __pyx_v_dims[6];
+  int32_t __pyx_v_ndims;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int32_t __pyx_t_7;
+  __Pyx_RefNannySetupContext("textarray_encode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":257
+ *         WriteBuffer array_data
+ *         int32_t dims[ARRAY_MAXDIM]
+ *         int32_t ndims = 1             # <<<<<<<<<<<<<<
+ *         int32_t i
+ * 
+ */
+  __pyx_v_ndims = 1;
+
+  /* "asyncpg/protocol/codecs/array.pyx":260
+ *         int32_t i
+ * 
+ *     if not _is_array_iterable(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol__is_array_iterable(__pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 260, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(4, 260, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = ((!__pyx_t_2) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":262
+ *     if not _is_array_iterable(obj):
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(             # <<<<<<<<<<<<<<
+ *                 type(obj).__name__))
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_a_sized_iterable_container_expec, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 262, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/protocol/codecs/array.pyx":263
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(
+ *                 type(obj).__name__))             # <<<<<<<<<<<<<<
+ * 
+ *     _get_array_shape(obj, dims, &ndims)
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_obj)), __pyx_n_s_name_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 263, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 262, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":261
+ * 
+ *     if not _is_array_iterable(obj):
+ *         raise TypeError(             # <<<<<<<<<<<<<<
+ *             'a sized iterable container expected (got type {!r})'.format(
+ *                 type(obj).__name__))
+ */
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 261, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __PYX_ERR(4, 261, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/array.pyx":260
+ *         int32_t i
+ * 
+ *     if not _is_array_iterable(obj):             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'a sized iterable container expected (got type {!r})'.format(
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":265
+ *                 type(obj).__name__))
+ * 
+ *     _get_array_shape(obj, dims, &ndims)             # <<<<<<<<<<<<<<
+ * 
+ *     array_data = WriteBuffer.new()
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol__get_array_shape(__pyx_v_obj, __pyx_v_dims, (&__pyx_v_ndims)); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 265, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":267
+ *     _get_array_shape(obj, dims, &ndims)
+ * 
+ *     array_data = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ *     _write_textarray_data(settings, obj, ndims, 0, array_data,
+ *                           encoder, encoder_arg, typdelim)
+ */
+  __pyx_t_4 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 267, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_v_array_data = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":268
+ * 
+ *     array_data = WriteBuffer.new()
+ *     _write_textarray_data(settings, obj, ndims, 0, array_data,             # <<<<<<<<<<<<<<
+ *                           encoder, encoder_arg, typdelim)
+ *     buf.write_int32(array_data.len())
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol__write_textarray_data(__pyx_v_settings, __pyx_v_obj, __pyx_v_ndims, 0, __pyx_v_array_data, __pyx_v_encoder, __pyx_v_encoder_arg, __pyx_v_typdelim); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 268, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":270
+ *     _write_textarray_data(settings, obj, ndims, 0, array_data,
+ *                           encoder, encoder_arg, typdelim)
+ *     buf.write_int32(array_data.len())             # <<<<<<<<<<<<<<
+ *     buf.write_buffer(array_data)
+ * 
+ */
+  __pyx_t_4 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_array_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 270, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_7 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_7 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(4, 270, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 270, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":271
+ *                           encoder, encoder_arg, typdelim)
+ *     buf.write_int32(array_data.len())
+ *     buf.write_buffer(array_data)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_buffer(__pyx_v_buf, __pyx_v_array_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 271, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":251
+ * 
+ * 
+ * cdef inline textarray_encode(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                              object obj, encode_func_ex encoder,
+ *                              const void *encoder_arg, Py_UCS4 typdelim):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.textarray_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_array_data);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":274
+ * 
+ * 
+ * cdef inline array_decode(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                          decode_func_ex decoder, const void *decoder_arg):
+ *     cdef:
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_array_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex __pyx_v_decoder, void const *__pyx_v_decoder_arg) {
+  int32_t __pyx_v_ndims;
+  CYTHON_UNUSED int32_t __pyx_v_flags;
+  CYTHON_UNUSED uint32_t __pyx_v_elem_oid;
+  PyObject *__pyx_v_result = 0;
+  int __pyx_v_i;
+  int32_t __pyx_v_elem_len;
+  int32_t __pyx_v_elem_count;
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer __pyx_v_elem_buf;
+  int32_t __pyx_v_dims[6];
+  PyObject *__pyx_v_elem = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  int32_t __pyx_t_11;
+  int32_t __pyx_t_12;
+  __Pyx_RefNannySetupContext("array_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":277
+ *                          decode_func_ex decoder, const void *decoder_arg):
+ *     cdef:
+ *         int32_t ndims = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         int32_t flags = hton.unpack_int32(frb_read(buf, 4))
+ *         uint32_t elem_oid = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(4, 277, __pyx_L1_error)
+  __pyx_v_ndims = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/protocol/codecs/array.pyx":278
+ *     cdef:
+ *         int32_t ndims = hton.unpack_int32(frb_read(buf, 4))
+ *         int32_t flags = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         uint32_t elem_oid = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         list result
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(4, 278, __pyx_L1_error)
+  __pyx_v_flags = unpack_int32(__pyx_t_1);
+
+  /* "asyncpg/protocol/codecs/array.pyx":279
+ *         int32_t ndims = hton.unpack_int32(frb_read(buf, 4))
+ *         int32_t flags = hton.unpack_int32(frb_read(buf, 4))
+ *         uint32_t elem_oid = <uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         list result
+ *         int i
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(4, 279, __pyx_L1_error)
+  __pyx_v_elem_oid = ((uint32_t)unpack_int32(__pyx_t_1));
+
+  /* "asyncpg/protocol/codecs/array.pyx":283
+ *         int i
+ *         int32_t elem_len
+ *         int32_t elem_count = 1             # <<<<<<<<<<<<<<
+ *         FRBuffer elem_buf
+ *         int32_t dims[ARRAY_MAXDIM]
+ */
+  __pyx_v_elem_count = 1;
+
+  /* "asyncpg/protocol/codecs/array.pyx":288
+ *         Codec elem_codec
+ * 
+ *     if ndims == 0:             # <<<<<<<<<<<<<<
+ *         result = cpython.PyList_New(0)
+ *         return result
+ */
+  __pyx_t_2 = ((__pyx_v_ndims == 0) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":289
+ * 
+ *     if ndims == 0:
+ *         result = cpython.PyList_New(0)             # <<<<<<<<<<<<<<
+ *         return result
+ * 
+ */
+    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 289, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_v_result = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":290
+ *     if ndims == 0:
+ *         result = cpython.PyList_New(0)
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     if ndims > ARRAY_MAXDIM:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(__pyx_v_result);
+    __pyx_r = __pyx_v_result;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":288
+ *         Codec elem_codec
+ * 
+ *     if ndims == 0:             # <<<<<<<<<<<<<<
+ *         result = cpython.PyList_New(0)
+ *         return result
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":292
+ *         return result
+ * 
+ *     if ndims > ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *         raise exceptions.ProtocolError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ */
+  __pyx_t_2 = ((__pyx_v_ndims > 6) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":293
+ * 
+ *     if ndims > ARRAY_MAXDIM:
+ *         raise exceptions.ProtocolError(             # <<<<<<<<<<<<<<
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ *             format(ndims, ARRAY_MAXDIM))
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 293, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 293, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":294
+ *     if ndims > ARRAY_MAXDIM:
+ *         raise exceptions.ProtocolError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.             # <<<<<<<<<<<<<<
+ *             format(ndims, ARRAY_MAXDIM))
+ * 
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_number_of_array_dimensions_excee, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 294, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+
+    /* "asyncpg/protocol/codecs/array.pyx":295
+ *         raise exceptions.ProtocolError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ *             format(ndims, ARRAY_MAXDIM))             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(ndims):
+ */
+    __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_ndims); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 295, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = NULL;
+    __pyx_t_9 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+        __pyx_t_9 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_int_6};
+      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 295, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_int_6};
+      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 295, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 295, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_10);
+      if (__pyx_t_8) {
+        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_7);
+      __Pyx_INCREF(__pyx_int_6);
+      __Pyx_GIVEREF(__pyx_int_6);
+      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_int_6);
+      __pyx_t_7 = 0;
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 295, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 293, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(4, 293, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/array.pyx":292
+ *         return result
+ * 
+ *     if ndims > ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *         raise exceptions.ProtocolError(
+ *             'number of array dimensions ({}) exceed the maximum expected ({})'.
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":297
+ *             format(ndims, ARRAY_MAXDIM))
+ * 
+ *     for i in range(ndims):             # <<<<<<<<<<<<<<
+ *         dims[i] = hton.unpack_int32(frb_read(buf, 4))
+ *         # Ignore the lower bound information
+ */
+  __pyx_t_11 = __pyx_v_ndims;
+  __pyx_t_12 = __pyx_t_11;
+  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_12; __pyx_t_9+=1) {
+    __pyx_v_i = __pyx_t_9;
+
+    /* "asyncpg/protocol/codecs/array.pyx":298
+ * 
+ *     for i in range(ndims):
+ *         dims[i] = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         # Ignore the lower bound information
+ *         frb_read(buf, 4)
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(4, 298, __pyx_L1_error)
+    (__pyx_v_dims[__pyx_v_i]) = unpack_int32(__pyx_t_1);
+
+    /* "asyncpg/protocol/codecs/array.pyx":300
+ *         dims[i] = hton.unpack_int32(frb_read(buf, 4))
+ *         # Ignore the lower bound information
+ *         frb_read(buf, 4)             # <<<<<<<<<<<<<<
+ * 
+ *     if ndims == 1:
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(4, 300, __pyx_L1_error)
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":302
+ *         frb_read(buf, 4)
+ * 
+ *     if ndims == 1:             # <<<<<<<<<<<<<<
+ *         # Fast path for flat arrays
+ *         elem_count = dims[0]
+ */
+  __pyx_t_2 = ((__pyx_v_ndims == 1) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":304
+ *     if ndims == 1:
+ *         # Fast path for flat arrays
+ *         elem_count = dims[0]             # <<<<<<<<<<<<<<
+ *         result = cpython.PyList_New(elem_count)
+ * 
+ */
+    __pyx_v_elem_count = (__pyx_v_dims[0]);
+
+    /* "asyncpg/protocol/codecs/array.pyx":305
+ *         # Fast path for flat arrays
+ *         elem_count = dims[0]
+ *         result = cpython.PyList_New(elem_count)             # <<<<<<<<<<<<<<
+ * 
+ *         for i in range(elem_count):
+ */
+    __pyx_t_3 = PyList_New(__pyx_v_elem_count); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 305, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_v_result = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":307
+ *         result = cpython.PyList_New(elem_count)
+ * 
+ *         for i in range(elem_count):             # <<<<<<<<<<<<<<
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:
+ */
+    __pyx_t_11 = __pyx_v_elem_count;
+    __pyx_t_12 = __pyx_t_11;
+    for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_12; __pyx_t_9+=1) {
+      __pyx_v_i = __pyx_t_9;
+
+      /* "asyncpg/protocol/codecs/array.pyx":308
+ * 
+ *         for i in range(elem_count):
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *             if elem_len == -1:
+ *                 elem = None
+ */
+      __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(4, 308, __pyx_L1_error)
+      __pyx_v_elem_len = unpack_int32(__pyx_t_1);
+
+      /* "asyncpg/protocol/codecs/array.pyx":309
+ *         for i in range(elem_count):
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:             # <<<<<<<<<<<<<<
+ *                 elem = None
+ *             else:
+ */
+      __pyx_t_2 = ((__pyx_v_elem_len == -1L) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":310
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:
+ *                 elem = None             # <<<<<<<<<<<<<<
+ *             else:
+ *                 frb_slice_from(&elem_buf, buf, elem_len)
+ */
+        __Pyx_INCREF(Py_None);
+        __Pyx_XDECREF_SET(__pyx_v_elem, Py_None);
+
+        /* "asyncpg/protocol/codecs/array.pyx":309
+ *         for i in range(elem_count):
+ *             elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *             if elem_len == -1:             # <<<<<<<<<<<<<<
+ *                 elem = None
+ *             else:
+ */
+        goto __pyx_L10;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":312
+ *                 elem = None
+ *             else:
+ *                 frb_slice_from(&elem_buf, buf, elem_len)             # <<<<<<<<<<<<<<
+ *                 elem = decoder(settings, &elem_buf, decoder_arg)
+ * 
+ */
+      /*else*/ {
+        (void)(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from((&__pyx_v_elem_buf), __pyx_v_buf, __pyx_v_elem_len));
+
+        /* "asyncpg/protocol/codecs/array.pyx":313
+ *             else:
+ *                 frb_slice_from(&elem_buf, buf, elem_len)
+ *                 elem = decoder(settings, &elem_buf, decoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *             cpython.Py_INCREF(elem)
+ */
+        __pyx_t_3 = __pyx_v_decoder(__pyx_v_settings, (&__pyx_v_elem_buf), __pyx_v_decoder_arg); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 313, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_XDECREF_SET(__pyx_v_elem, __pyx_t_3);
+        __pyx_t_3 = 0;
+      }
+      __pyx_L10:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":315
+ *                 elem = decoder(settings, &elem_buf, decoder_arg)
+ * 
+ *             cpython.Py_INCREF(elem)             # <<<<<<<<<<<<<<
+ *             cpython.PyList_SET_ITEM(result, i, elem)
+ * 
+ */
+      Py_INCREF(__pyx_v_elem);
+
+      /* "asyncpg/protocol/codecs/array.pyx":316
+ * 
+ *             cpython.Py_INCREF(elem)
+ *             cpython.PyList_SET_ITEM(result, i, elem)             # <<<<<<<<<<<<<<
+ * 
+ *     else:
+ */
+      PyList_SET_ITEM(__pyx_v_result, __pyx_v_i, __pyx_v_elem);
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":302
+ *         frb_read(buf, 4)
+ * 
+ *     if ndims == 1:             # <<<<<<<<<<<<<<
+ *         # Fast path for flat arrays
+ *         elem_count = dims[0]
+ */
+    goto __pyx_L7;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":319
+ * 
+ *     else:
+ *         result = _nested_array_decode(settings, buf,             # <<<<<<<<<<<<<<
+ *                                       decoder, decoder_arg, ndims, dims,
+ *                                       &elem_buf)
+ */
+  /*else*/ {
+
+    /* "asyncpg/protocol/codecs/array.pyx":321
+ *         result = _nested_array_decode(settings, buf,
+ *                                       decoder, decoder_arg, ndims, dims,
+ *                                       &elem_buf)             # <<<<<<<<<<<<<<
+ * 
+ *     return result
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__nested_array_decode(__pyx_v_settings, __pyx_v_buf, __pyx_v_decoder, __pyx_v_decoder_arg, __pyx_v_ndims, __pyx_v_dims, (&__pyx_v_elem_buf)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 319, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/protocol/codecs/array.pyx":319
+ * 
+ *     else:
+ *         result = _nested_array_decode(settings, buf,             # <<<<<<<<<<<<<<
+ *                                       decoder, decoder_arg, ndims, dims,
+ *                                       &elem_buf)
+ */
+    if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(4, 319, __pyx_L1_error)
+    __pyx_v_result = ((PyObject*)__pyx_t_3);
+    __pyx_t_3 = 0;
+  }
+  __pyx_L7:;
+
+  /* "asyncpg/protocol/codecs/array.pyx":323
+ *                                       &elem_buf)
+ * 
+ *     return result             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":274
+ * 
+ * 
+ * cdef inline array_decode(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                          decode_func_ex decoder, const void *decoder_arg):
+ *     cdef:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.array_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF(__pyx_v_elem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":326
+ * 
+ * 
+ * cdef _nested_array_decode(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                           FRBuffer *buf,
+ *                           decode_func_ex decoder,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__nested_array_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex __pyx_v_decoder, void const *__pyx_v_decoder_arg, int32_t __pyx_v_ndims, int32_t *__pyx_v_dims, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_elem_buf) {
+  int32_t __pyx_v_elem_len;
+  int64_t __pyx_v_i;
+  int64_t __pyx_v_j;
+  int64_t __pyx_v_array_len;
+  PyObject *__pyx_v_elem = 0;
+  PyObject *__pyx_v_stride = 0;
+  void *__pyx_v_strides[6];
+  int32_t __pyx_v_indexes[6];
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int32_t __pyx_t_8;
+  int32_t __pyx_t_9;
+  int64_t __pyx_t_10;
+  int64_t __pyx_t_11;
+  int64_t __pyx_t_12;
+  char const *__pyx_t_13;
+  int64_t __pyx_t_14;
+  int64_t __pyx_t_15;
+  int __pyx_t_16;
+  __Pyx_RefNannySetupContext("_nested_array_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":336
+ *         int32_t elem_len
+ *         int64_t i, j
+ *         int64_t array_len = 1             # <<<<<<<<<<<<<<
+ *         object elem, stride
+ *         # An array of pointers to lists for each current array level.
+ */
+  __pyx_v_array_len = 1;
+
+  /* "asyncpg/protocol/codecs/array.pyx":343
+ *         int32_t indexes[ARRAY_MAXDIM]
+ * 
+ *     if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *         if ndims <= 0:
+ *             raise exceptions.ProtocolError(
+ */
+  __pyx_t_1 = (PG_DEBUG != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":344
+ * 
+ *     if PG_DEBUG:
+ *         if ndims <= 0:             # <<<<<<<<<<<<<<
+ *             raise exceptions.ProtocolError(
+ *                 'unexpected ndims value: {}'.format(ndims))
+ */
+    __pyx_t_1 = ((__pyx_v_ndims <= 0) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":345
+ *     if PG_DEBUG:
+ *         if ndims <= 0:
+ *             raise exceptions.ProtocolError(             # <<<<<<<<<<<<<<
+ *                 'unexpected ndims value: {}'.format(ndims))
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 345, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 345, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":346
+ *         if ndims <= 0:
+ *             raise exceptions.ProtocolError(
+ *                 'unexpected ndims value: {}'.format(ndims))             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(ndims):
+ */
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_ndims_value, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(4, 346, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = __Pyx_PyInt_From_int32_t(__pyx_v_ndims); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 346, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_7 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_7)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_7);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 346, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_t_5 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_5)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_5);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 345, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __PYX_ERR(4, 345, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":344
+ * 
+ *     if PG_DEBUG:
+ *         if ndims <= 0:             # <<<<<<<<<<<<<<
+ *             raise exceptions.ProtocolError(
+ *                 'unexpected ndims value: {}'.format(ndims))
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":343
+ *         int32_t indexes[ARRAY_MAXDIM]
+ * 
+ *     if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *         if ndims <= 0:
+ *             raise exceptions.ProtocolError(
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":348
+ *                 'unexpected ndims value: {}'.format(ndims))
+ * 
+ *     for i in range(ndims):             # <<<<<<<<<<<<<<
+ *         array_len *= dims[i]
+ *         indexes[i] = 0
+ */
+  __pyx_t_8 = __pyx_v_ndims;
+  __pyx_t_9 = __pyx_t_8;
+  for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
+    __pyx_v_i = __pyx_t_10;
+
+    /* "asyncpg/protocol/codecs/array.pyx":349
+ * 
+ *     for i in range(ndims):
+ *         array_len *= dims[i]             # <<<<<<<<<<<<<<
+ *         indexes[i] = 0
+ * 
+ */
+    __pyx_v_array_len = (__pyx_v_array_len * (__pyx_v_dims[__pyx_v_i]));
+
+    /* "asyncpg/protocol/codecs/array.pyx":350
+ *     for i in range(ndims):
+ *         array_len *= dims[i]
+ *         indexes[i] = 0             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(array_len):
+ */
+    (__pyx_v_indexes[__pyx_v_i]) = 0;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":352
+ *         indexes[i] = 0
+ * 
+ *     for i in range(array_len):             # <<<<<<<<<<<<<<
+ *         # Decode the element.
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ */
+  __pyx_t_10 = __pyx_v_array_len;
+  __pyx_t_11 = __pyx_t_10;
+  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
+    __pyx_v_i = __pyx_t_12;
+
+    /* "asyncpg/protocol/codecs/array.pyx":354
+ *     for i in range(array_len):
+ *         # Decode the element.
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         if elem_len == -1:
+ *             elem = None
+ */
+    __pyx_t_13 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_13 == ((char const *)NULL))) __PYX_ERR(4, 354, __pyx_L1_error)
+    __pyx_v_elem_len = unpack_int32(__pyx_t_13);
+
+    /* "asyncpg/protocol/codecs/array.pyx":355
+ *         # Decode the element.
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len == -1:             # <<<<<<<<<<<<<<
+ *             elem = None
+ *         else:
+ */
+    __pyx_t_1 = ((__pyx_v_elem_len == -1L) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":356
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len == -1:
+ *             elem = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             elem = decoder(settings,
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_elem, Py_None);
+
+      /* "asyncpg/protocol/codecs/array.pyx":355
+ *         # Decode the element.
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if elem_len == -1:             # <<<<<<<<<<<<<<
+ *             elem = None
+ *         else:
+ */
+      goto __pyx_L9;
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":358
+ *             elem = None
+ *         else:
+ *             elem = decoder(settings,             # <<<<<<<<<<<<<<
+ *                            frb_slice_from(elem_buf, buf, elem_len),
+ *                            decoder_arg)
+ */
+    /*else*/ {
+
+      /* "asyncpg/protocol/codecs/array.pyx":360
+ *             elem = decoder(settings,
+ *                            frb_slice_from(elem_buf, buf, elem_len),
+ *                            decoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *         # Take an explicit reference for PyList_SET_ITEM in the below
+ */
+      __pyx_t_2 = __pyx_v_decoder(__pyx_v_settings, __pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from(__pyx_v_elem_buf, __pyx_v_buf, __pyx_v_elem_len), __pyx_v_decoder_arg); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 358, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_XDECREF_SET(__pyx_v_elem, __pyx_t_2);
+      __pyx_t_2 = 0;
+    }
+    __pyx_L9:;
+
+    /* "asyncpg/protocol/codecs/array.pyx":364
+ *         # Take an explicit reference for PyList_SET_ITEM in the below
+ *         # loop expects this.
+ *         cpython.Py_INCREF(elem)             # <<<<<<<<<<<<<<
+ * 
+ *         # Iterate over array dimentions and put the element in
+ */
+    Py_INCREF(__pyx_v_elem);
+
+    /* "asyncpg/protocol/codecs/array.pyx":368
+ *         # Iterate over array dimentions and put the element in
+ *         # the correctly nested sublist.
+ *         for j in reversed(range(ndims)):             # <<<<<<<<<<<<<<
+ *             if indexes[j] == 0:
+ *                 # Allocate the list for this array level.
+ */
+    for (__pyx_t_14 = __pyx_v_ndims-1; __pyx_t_14 >= 0; __pyx_t_14-=1) {
+      __pyx_v_j = __pyx_t_14;
+
+      /* "asyncpg/protocol/codecs/array.pyx":369
+ *         # the correctly nested sublist.
+ *         for j in reversed(range(ndims)):
+ *             if indexes[j] == 0:             # <<<<<<<<<<<<<<
+ *                 # Allocate the list for this array level.
+ *                 stride = cpython.PyList_New(dims[j])
+ */
+      __pyx_t_1 = (((__pyx_v_indexes[__pyx_v_j]) == 0) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":371
+ *             if indexes[j] == 0:
+ *                 # Allocate the list for this array level.
+ *                 stride = cpython.PyList_New(dims[j])             # <<<<<<<<<<<<<<
+ * 
+ *                 strides[j] = <void*><cpython.PyObject>stride
+ */
+        __pyx_t_2 = PyList_New((__pyx_v_dims[__pyx_v_j])); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 371, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_XDECREF_SET(__pyx_v_stride, __pyx_t_2);
+        __pyx_t_2 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":373
+ *                 stride = cpython.PyList_New(dims[j])
+ * 
+ *                 strides[j] = <void*><cpython.PyObject>stride             # <<<<<<<<<<<<<<
+ *                 # Take an explicit reference for PyList_SET_ITEM below
+ *                 # expects this.
+ */
+        (__pyx_v_strides[__pyx_v_j]) = ((void *)__pyx_v_stride);
+
+        /* "asyncpg/protocol/codecs/array.pyx":376
+ *                 # Take an explicit reference for PyList_SET_ITEM below
+ *                 # expects this.
+ *                 cpython.Py_INCREF(stride)             # <<<<<<<<<<<<<<
+ * 
+ *             stride = <object><cpython.PyObject*>strides[j]
+ */
+        Py_INCREF(__pyx_v_stride);
+
+        /* "asyncpg/protocol/codecs/array.pyx":369
+ *         # the correctly nested sublist.
+ *         for j in reversed(range(ndims)):
+ *             if indexes[j] == 0:             # <<<<<<<<<<<<<<
+ *                 # Allocate the list for this array level.
+ *                 stride = cpython.PyList_New(dims[j])
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":378
+ *                 cpython.Py_INCREF(stride)
+ * 
+ *             stride = <object><cpython.PyObject*>strides[j]             # <<<<<<<<<<<<<<
+ *             cpython.PyList_SET_ITEM(stride, indexes[j], elem)
+ *             indexes[j] += 1
+ */
+      __pyx_t_2 = ((PyObject *)((PyObject *)(__pyx_v_strides[__pyx_v_j])));
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_XDECREF_SET(__pyx_v_stride, __pyx_t_2);
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":379
+ * 
+ *             stride = <object><cpython.PyObject*>strides[j]
+ *             cpython.PyList_SET_ITEM(stride, indexes[j], elem)             # <<<<<<<<<<<<<<
+ *             indexes[j] += 1
+ * 
+ */
+      PyList_SET_ITEM(__pyx_v_stride, (__pyx_v_indexes[__pyx_v_j]), __pyx_v_elem);
+
+      /* "asyncpg/protocol/codecs/array.pyx":380
+ *             stride = <object><cpython.PyObject*>strides[j]
+ *             cpython.PyList_SET_ITEM(stride, indexes[j], elem)
+ *             indexes[j] += 1             # <<<<<<<<<<<<<<
+ * 
+ *             if indexes[j] == dims[j] and j != 0:
+ */
+      __pyx_t_15 = __pyx_v_j;
+      (__pyx_v_indexes[__pyx_t_15]) = ((__pyx_v_indexes[__pyx_t_15]) + 1);
+
+      /* "asyncpg/protocol/codecs/array.pyx":382
+ *             indexes[j] += 1
+ * 
+ *             if indexes[j] == dims[j] and j != 0:             # <<<<<<<<<<<<<<
+ *                 # This array level is full, continue the
+ *                 # ascent in the dimensions so that this level
+ */
+      __pyx_t_16 = (((__pyx_v_indexes[__pyx_v_j]) == (__pyx_v_dims[__pyx_v_j])) != 0);
+      if (__pyx_t_16) {
+      } else {
+        __pyx_t_1 = __pyx_t_16;
+        goto __pyx_L14_bool_binop_done;
+      }
+      __pyx_t_16 = ((__pyx_v_j != 0) != 0);
+      __pyx_t_1 = __pyx_t_16;
+      __pyx_L14_bool_binop_done:;
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":386
+ *                 # ascent in the dimensions so that this level
+ *                 # sublist will be appened to the parent list.
+ *                 elem = stride             # <<<<<<<<<<<<<<
+ *                 # Reset the index, this will cause the
+ *                 # new list to be allocated on the next
+ */
+        __Pyx_INCREF(__pyx_v_stride);
+        __Pyx_DECREF_SET(__pyx_v_elem, __pyx_v_stride);
+
+        /* "asyncpg/protocol/codecs/array.pyx":390
+ *                 # new list to be allocated on the next
+ *                 # iteration on this array axis.
+ *                 indexes[j] = 0             # <<<<<<<<<<<<<<
+ *             else:
+ *                 break
+ */
+        (__pyx_v_indexes[__pyx_v_j]) = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":382
+ *             indexes[j] += 1
+ * 
+ *             if indexes[j] == dims[j] and j != 0:             # <<<<<<<<<<<<<<
+ *                 # This array level is full, continue the
+ *                 # ascent in the dimensions so that this level
+ */
+        goto __pyx_L13;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":392
+ *                 indexes[j] = 0
+ *             else:
+ *                 break             # <<<<<<<<<<<<<<
+ * 
+ *     stride = <object><cpython.PyObject*>strides[0]
+ */
+      /*else*/ {
+        goto __pyx_L11_break;
+      }
+      __pyx_L13:;
+    }
+    __pyx_L11_break:;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":394
+ *                 break
+ * 
+ *     stride = <object><cpython.PyObject*>strides[0]             # <<<<<<<<<<<<<<
+ *     # Since each element in strides has a refcount of 1,
+ *     # returning strides[0] will increment it to 2, so
+ */
+  __pyx_t_2 = ((PyObject *)((PyObject *)(__pyx_v_strides[0])));
+  __Pyx_INCREF(__pyx_t_2);
+  __Pyx_XDECREF_SET(__pyx_v_stride, __pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":398
+ *     # returning strides[0] will increment it to 2, so
+ *     # balance that.
+ *     cpython.Py_DECREF(stride)             # <<<<<<<<<<<<<<
+ *     return stride
+ * 
+ */
+  Py_DECREF(__pyx_v_stride);
+
+  /* "asyncpg/protocol/codecs/array.pyx":399
+ *     # balance that.
+ *     cpython.Py_DECREF(stride)
+ *     return stride             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_stride);
+  __pyx_r = __pyx_v_stride;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":326
+ * 
+ * 
+ * cdef _nested_array_decode(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                           FRBuffer *buf,
+ *                           decode_func_ex decoder,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._nested_array_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_elem);
+  __Pyx_XDECREF(__pyx_v_stride);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":402
+ * 
+ * 
+ * cdef textarray_decode(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                       decode_func_ex decoder, const void *decoder_arg,
+ *                       Py_UCS4 typdelim):
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_textarray_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex __pyx_v_decoder, void const *__pyx_v_decoder_arg, Py_UCS4 __pyx_v_typdelim) {
+  Py_UCS4 *__pyx_v_array_text;
+  PyObject *__pyx_v_s = 0;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_UCS4 *__pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  int __pyx_t_16;
+  char const *__pyx_t_17;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  PyObject *__pyx_t_21 = NULL;
+  PyObject *__pyx_t_22 = NULL;
+  PyObject *__pyx_t_23 = NULL;
+  char const *__pyx_t_24;
+  __Pyx_RefNannySetupContext("textarray_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":411
+ *     # Make a copy of array data since we will be mutating it for
+ *     # the purposes of element decoding.
+ *     s = pgproto.text_decode(settings, buf)             # <<<<<<<<<<<<<<
+ *     array_text = cpythonx.PyUnicode_AsUCS4Copy(s)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 411, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(4, 411, __pyx_L1_error)
+  __pyx_v_s = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":412
+ *     # the purposes of element decoding.
+ *     s = pgproto.text_decode(settings, buf)
+ *     array_text = cpythonx.PyUnicode_AsUCS4Copy(s)             # <<<<<<<<<<<<<<
+ * 
+ *     try:
+ */
+  __pyx_t_2 = PyUnicode_AsUCS4Copy(__pyx_v_s); if (unlikely(__pyx_t_2 == ((Py_UCS4 *)NULL))) __PYX_ERR(4, 412, __pyx_L1_error)
+  __pyx_v_array_text = __pyx_t_2;
+
+  /* "asyncpg/protocol/codecs/array.pyx":414
+ *     array_text = cpythonx.PyUnicode_AsUCS4Copy(s)
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         return _textarray_decode(
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ */
+  /*try:*/ {
+    {
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_3);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/codecs/array.pyx":415
+ * 
+ *     try:
+ *         return _textarray_decode(             # <<<<<<<<<<<<<<
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ *     except ValueError as e:
+ */
+        __Pyx_XDECREF(__pyx_r);
+
+        /* "asyncpg/protocol/codecs/array.pyx":416
+ *     try:
+ *         return _textarray_decode(
+ *             settings, array_text, decoder, decoder_arg, typdelim)             # <<<<<<<<<<<<<<
+ *     except ValueError as e:
+ *         raise exceptions.ProtocolError(
+ */
+        __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol__textarray_decode(__pyx_v_settings, __pyx_v_array_text, __pyx_v_decoder, __pyx_v_decoder_arg, __pyx_v_typdelim); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 415, __pyx_L6_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __pyx_r = __pyx_t_1;
+        __pyx_t_1 = 0;
+        goto __pyx_L10_try_return;
+
+        /* "asyncpg/protocol/codecs/array.pyx":414
+ *     array_text = cpythonx.PyUnicode_AsUCS4Copy(s)
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         return _textarray_decode(
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ */
+      }
+      __pyx_L6_error:;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":417
+ *         return _textarray_decode(
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ *     except ValueError as e:             # <<<<<<<<<<<<<<
+ *         raise exceptions.ProtocolError(
+ *             'malformed array literal {!r}: {}'.format(s, e.args[0]))
+ */
+      __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
+      if (__pyx_t_6) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.textarray_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(4, 417, __pyx_L8_except_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_INCREF(__pyx_t_7);
+        __pyx_v_e = __pyx_t_7;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/codecs/array.pyx":418
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ *     except ValueError as e:
+ *         raise exceptions.ProtocolError(             # <<<<<<<<<<<<<<
+ *             'malformed array literal {!r}: {}'.format(s, e.args[0]))
+ *     finally:
+ */
+          __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 418, __pyx_L17_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_11)) __PYX_ERR(4, 418, __pyx_L17_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":419
+ *     except ValueError as e:
+ *         raise exceptions.ProtocolError(
+ *             'malformed array literal {!r}: {}'.format(s, e.args[0]))             # <<<<<<<<<<<<<<
+ *     finally:
+ *         cpython.PyMem_Free(array_text)
+ */
+          __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_malformed_array_literal_r, __pyx_n_s_format); if (unlikely(!__pyx_t_12)) __PYX_ERR(4, 419, __pyx_L17_error)
+          __Pyx_GOTREF(__pyx_t_12);
+          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_13)) __PYX_ERR(4, 419, __pyx_L17_error)
+          __Pyx_GOTREF(__pyx_t_13);
+          __pyx_t_14 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(4, 419, __pyx_L17_error)
+          __Pyx_GOTREF(__pyx_t_14);
+          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __pyx_t_13 = NULL;
+          __pyx_t_6 = 0;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
+            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
+            if (likely(__pyx_t_13)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
+              __Pyx_INCREF(__pyx_t_13);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_12, function);
+              __pyx_t_6 = 1;
+            }
+          }
+          #if CYTHON_FAST_PYCALL
+          if (PyFunction_Check(__pyx_t_12)) {
+            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_s, __pyx_t_14};
+            __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 419, __pyx_L17_error)
+            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+            __Pyx_GOTREF(__pyx_t_10);
+            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+          } else
+          #endif
+          #if CYTHON_FAST_PYCCALL
+          if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
+            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_s, __pyx_t_14};
+            __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 419, __pyx_L17_error)
+            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+            __Pyx_GOTREF(__pyx_t_10);
+            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+          } else
+          #endif
+          {
+            __pyx_t_15 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_15)) __PYX_ERR(4, 419, __pyx_L17_error)
+            __Pyx_GOTREF(__pyx_t_15);
+            if (__pyx_t_13) {
+              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
+            }
+            __Pyx_INCREF(__pyx_v_s);
+            __Pyx_GIVEREF(__pyx_v_s);
+            PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_6, __pyx_v_s);
+            __Pyx_GIVEREF(__pyx_t_14);
+            PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_6, __pyx_t_14);
+            __pyx_t_14 = 0;
+            __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_15, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(4, 419, __pyx_L17_error)
+            __Pyx_GOTREF(__pyx_t_10);
+            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+          }
+          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_9 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_10);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+          if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 418, __pyx_L17_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_Raise(__pyx_t_9, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __PYX_ERR(4, 418, __pyx_L17_error)
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":417
+ *         return _textarray_decode(
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ *     except ValueError as e:             # <<<<<<<<<<<<<<
+ *         raise exceptions.ProtocolError(
+ *             'malformed array literal {!r}: {}'.format(s, e.args[0]))
+ */
+        /*finally:*/ {
+          __pyx_L17_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_declare
+            __Pyx_PyThreadState_assign
+            __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0;
+            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+            __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20) < 0)) __Pyx_ErrFetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __Pyx_XGOTREF(__pyx_t_21);
+            __Pyx_XGOTREF(__pyx_t_22);
+            __Pyx_XGOTREF(__pyx_t_23);
+            __pyx_t_6 = __pyx_lineno; __pyx_t_16 = __pyx_clineno; __pyx_t_17 = __pyx_filename;
+            {
+              __Pyx_DECREF(__pyx_v_e);
+              __pyx_v_e = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_21);
+              __Pyx_XGIVEREF(__pyx_t_22);
+              __Pyx_XGIVEREF(__pyx_t_23);
+              __Pyx_ExceptionReset(__pyx_t_21, __pyx_t_22, __pyx_t_23);
+            }
+            __Pyx_XGIVEREF(__pyx_t_18);
+            __Pyx_XGIVEREF(__pyx_t_19);
+            __Pyx_XGIVEREF(__pyx_t_20);
+            __Pyx_ErrRestore(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0;
+            __pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_16; __pyx_filename = __pyx_t_17;
+            goto __pyx_L8_except_error;
+          }
+        }
+      }
+      goto __pyx_L8_except_error;
+      __pyx_L8_except_error:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":414
+ *     array_text = cpythonx.PyUnicode_AsUCS4Copy(s)
+ * 
+ *     try:             # <<<<<<<<<<<<<<
+ *         return _textarray_decode(
+ *             settings, array_text, decoder, decoder_arg, typdelim)
+ */
+      __Pyx_XGIVEREF(__pyx_t_3);
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+      goto __pyx_L4_error;
+      __pyx_L10_try_return:;
+      __Pyx_XGIVEREF(__pyx_t_3);
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+      goto __pyx_L3_return;
+    }
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":421
+ *             'malformed array literal {!r}: {}'.format(s, e.args[0]))
+ *     finally:
+ *         cpython.PyMem_Free(array_text)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*finally:*/ {
+    __pyx_L4_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; __pyx_t_23 = 0; __pyx_t_22 = 0; __pyx_t_21 = 0;
+      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_23, &__pyx_t_22, &__pyx_t_21);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3) < 0)) __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_3);
+      __Pyx_XGOTREF(__pyx_t_23);
+      __Pyx_XGOTREF(__pyx_t_22);
+      __Pyx_XGOTREF(__pyx_t_21);
+      __pyx_t_16 = __pyx_lineno; __pyx_t_6 = __pyx_clineno; __pyx_t_24 = __pyx_filename;
+      {
+        PyMem_Free(__pyx_v_array_text);
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_23);
+        __Pyx_XGIVEREF(__pyx_t_22);
+        __Pyx_XGIVEREF(__pyx_t_21);
+        __Pyx_ExceptionReset(__pyx_t_23, __pyx_t_22, __pyx_t_21);
+      }
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_3);
+      __Pyx_ErrRestore(__pyx_t_5, __pyx_t_4, __pyx_t_3);
+      __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; __pyx_t_23 = 0; __pyx_t_22 = 0; __pyx_t_21 = 0;
+      __pyx_lineno = __pyx_t_16; __pyx_clineno = __pyx_t_6; __pyx_filename = __pyx_t_24;
+      goto __pyx_L1_error;
+    }
+    __pyx_L3_return: {
+      __pyx_t_21 = __pyx_r;
+      __pyx_r = 0;
+      PyMem_Free(__pyx_v_array_text);
+      __pyx_r = __pyx_t_21;
+      __pyx_t_21 = 0;
+      goto __pyx_L0;
+    }
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":402
+ * 
+ * 
+ * cdef textarray_decode(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                       decode_func_ex decoder, const void *decoder_arg,
+ *                       Py_UCS4 typdelim):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.textarray_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_s);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":424
+ * 
+ * 
+ * cdef _textarray_decode(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                        Py_UCS4 *array_text,
+ *                        decode_func_ex decoder,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__textarray_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, Py_UCS4 *__pyx_v_array_text, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex __pyx_v_decoder, void const *__pyx_v_decoder_arg, Py_UCS4 __pyx_v_typdelim) {
+  PyObject *__pyx_v_result = 0;
+  PyObject *__pyx_v_new_stride = 0;
+  Py_UCS4 *__pyx_v_ptr;
+  int32_t __pyx_v_ndims;
+  int32_t __pyx_v_ubound;
+  int32_t __pyx_v_lbound;
+  int32_t __pyx_v_dims[6];
+  int32_t __pyx_v_inferred_dims[6];
+  int32_t __pyx_v_inferred_ndims;
+  void *__pyx_v_strides[6];
+  int32_t __pyx_v_indexes[6];
+  int32_t __pyx_v_nest_level;
+  int32_t __pyx_v_item_level;
+  int __pyx_v_end_of_array;
+  int __pyx_v_end_of_item;
+  int __pyx_v_has_quoting;
+  int __pyx_v_strip_spaces;
+  int __pyx_v_in_quotes;
+  Py_UCS4 *__pyx_v_item_start;
+  Py_UCS4 *__pyx_v_item_ptr;
+  Py_UCS4 *__pyx_v_item_end;
+  int __pyx_v_i;
+  PyObject *__pyx_v_item = 0;
+  PyObject *__pyx_v_item_text = 0;
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer __pyx_v_item_buf;
+  char *__pyx_v_pg_item_str;
+  Py_ssize_t __pyx_v_pg_item_len;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  int32_t __pyx_t_8;
+  int32_t __pyx_t_9;
+  PyObject *__pyx_t_10;
+  int __pyx_t_11;
+  long __pyx_t_12;
+  __Pyx_RefNannySetupContext("_textarray_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":435
+ *         list new_stride
+ *         Py_UCS4 *ptr
+ *         int32_t ndims = 0             # <<<<<<<<<<<<<<
+ *         int32_t ubound = 0
+ *         int32_t lbound = 0
+ */
+  __pyx_v_ndims = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":436
+ *         Py_UCS4 *ptr
+ *         int32_t ndims = 0
+ *         int32_t ubound = 0             # <<<<<<<<<<<<<<
+ *         int32_t lbound = 0
+ *         int32_t dims[ARRAY_MAXDIM]
+ */
+  __pyx_v_ubound = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":437
+ *         int32_t ndims = 0
+ *         int32_t ubound = 0
+ *         int32_t lbound = 0             # <<<<<<<<<<<<<<
+ *         int32_t dims[ARRAY_MAXDIM]
+ *         int32_t inferred_dims[ARRAY_MAXDIM]
+ */
+  __pyx_v_lbound = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":440
+ *         int32_t dims[ARRAY_MAXDIM]
+ *         int32_t inferred_dims[ARRAY_MAXDIM]
+ *         int32_t inferred_ndims = 0             # <<<<<<<<<<<<<<
+ *         void *strides[ARRAY_MAXDIM]
+ *         int32_t indexes[ARRAY_MAXDIM]
+ */
+  __pyx_v_inferred_ndims = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":443
+ *         void *strides[ARRAY_MAXDIM]
+ *         int32_t indexes[ARRAY_MAXDIM]
+ *         int32_t nest_level = 0             # <<<<<<<<<<<<<<
+ *         int32_t item_level = 0
+ *         bint end_of_array = False
+ */
+  __pyx_v_nest_level = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":444
+ *         int32_t indexes[ARRAY_MAXDIM]
+ *         int32_t nest_level = 0
+ *         int32_t item_level = 0             # <<<<<<<<<<<<<<
+ *         bint end_of_array = False
+ * 
+ */
+  __pyx_v_item_level = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":445
+ *         int32_t nest_level = 0
+ *         int32_t item_level = 0
+ *         bint end_of_array = False             # <<<<<<<<<<<<<<
+ * 
+ *         bint end_of_item = False
+ */
+  __pyx_v_end_of_array = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":447
+ *         bint end_of_array = False
+ * 
+ *         bint end_of_item = False             # <<<<<<<<<<<<<<
+ *         bint has_quoting = False
+ *         bint strip_spaces = False
+ */
+  __pyx_v_end_of_item = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":448
+ * 
+ *         bint end_of_item = False
+ *         bint has_quoting = False             # <<<<<<<<<<<<<<
+ *         bint strip_spaces = False
+ *         bint in_quotes = False
+ */
+  __pyx_v_has_quoting = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":449
+ *         bint end_of_item = False
+ *         bint has_quoting = False
+ *         bint strip_spaces = False             # <<<<<<<<<<<<<<
+ *         bint in_quotes = False
+ *         Py_UCS4 *item_start
+ */
+  __pyx_v_strip_spaces = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":450
+ *         bint has_quoting = False
+ *         bint strip_spaces = False
+ *         bint in_quotes = False             # <<<<<<<<<<<<<<
+ *         Py_UCS4 *item_start
+ *         Py_UCS4 *item_ptr
+ */
+  __pyx_v_in_quotes = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":462
+ *         ssize_t pg_item_len
+ * 
+ *     ptr = array_text             # <<<<<<<<<<<<<<
+ * 
+ *     while True:
+ */
+  __pyx_v_ptr = __pyx_v_array_text;
+
+  /* "asyncpg/protocol/codecs/array.pyx":464
+ *     ptr = array_text
+ * 
+ *     while True:             # <<<<<<<<<<<<<<
+ *         while apg_ascii_isspace(ptr[0]):
+ *             ptr += 1
+ */
+  while (1) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":465
+ * 
+ *     while True:
+ *         while apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *             ptr += 1
+ * 
+ */
+    while (1) {
+      __pyx_t_1 = (__pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace((__pyx_v_ptr[0])) != 0);
+      if (!__pyx_t_1) break;
+
+      /* "asyncpg/protocol/codecs/array.pyx":466
+ *     while True:
+ *         while apg_ascii_isspace(ptr[0]):
+ *             ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *         if ptr[0] != '[':
+ */
+      __pyx_v_ptr = (__pyx_v_ptr + 1);
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":468
+ *             ptr += 1
+ * 
+ *         if ptr[0] != '[':             # <<<<<<<<<<<<<<
+ *             # Finished parsing dimensions spec.
+ *             break
+ */
+    __pyx_t_1 = (((__pyx_v_ptr[0]) != 91) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":470
+ *         if ptr[0] != '[':
+ *             # Finished parsing dimensions spec.
+ *             break             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1  # '['
+ */
+      goto __pyx_L4_break;
+
+      /* "asyncpg/protocol/codecs/array.pyx":468
+ *             ptr += 1
+ * 
+ *         if ptr[0] != '[':             # <<<<<<<<<<<<<<
+ *             # Finished parsing dimensions spec.
+ *             break
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":472
+ *             break
+ * 
+ *         ptr += 1  # '['             # <<<<<<<<<<<<<<
+ * 
+ *         if ndims > ARRAY_MAXDIM:
+ */
+    __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+    /* "asyncpg/protocol/codecs/array.pyx":474
+ *         ptr += 1  # '['
+ * 
+ *         if ndims > ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                 'number of array dimensions ({}) exceed the '
+ */
+    __pyx_t_1 = ((__pyx_v_ndims > 6) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":477
+ *             raise ValueError(
+ *                 'number of array dimensions ({}) exceed the '
+ *                 'maximum expected ({})'.format(ndims, ARRAY_MAXDIM))             # <<<<<<<<<<<<<<
+ * 
+ *         ptr = apg_parse_int32(ptr, &ubound)
+ */
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_number_of_array_dimensions_excee, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 477, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_ndims); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 477, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = NULL;
+      __pyx_t_6 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_5)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_5);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+          __pyx_t_6 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_3)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_int_6};
+        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 477, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, __pyx_int_6};
+        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 477, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 477, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        if (__pyx_t_5) {
+          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+        }
+        __Pyx_GIVEREF(__pyx_t_4);
+        PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_4);
+        __Pyx_INCREF(__pyx_int_6);
+        __Pyx_GIVEREF(__pyx_int_6);
+        PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_int_6);
+        __pyx_t_4 = 0;
+        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 477, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":475
+ * 
+ *         if ndims > ARRAY_MAXDIM:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                 'number of array dimensions ({}) exceed the '
+ *                 'maximum expected ({})'.format(ndims, ARRAY_MAXDIM))
+ */
+      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 475, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(4, 475, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":474
+ *         ptr += 1  # '['
+ * 
+ *         if ndims > ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                 'number of array dimensions ({}) exceed the '
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":479
+ *                 'maximum expected ({})'.format(ndims, ARRAY_MAXDIM))
+ * 
+ *         ptr = apg_parse_int32(ptr, &ubound)             # <<<<<<<<<<<<<<
+ *         if ptr == NULL:
+ *             raise ValueError('missing array dimension value')
+ */
+    __pyx_v_ptr = __pyx_f_7asyncpg_8protocol_8protocol_apg_parse_int32(__pyx_v_ptr, (&__pyx_v_ubound));
+
+    /* "asyncpg/protocol/codecs/array.pyx":480
+ * 
+ *         ptr = apg_parse_int32(ptr, &ubound)
+ *         if ptr == NULL:             # <<<<<<<<<<<<<<
+ *             raise ValueError('missing array dimension value')
+ * 
+ */
+    __pyx_t_1 = ((__pyx_v_ptr == NULL) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":481
+ *         ptr = apg_parse_int32(ptr, &ubound)
+ *         if ptr == NULL:
+ *             raise ValueError('missing array dimension value')             # <<<<<<<<<<<<<<
+ * 
+ *         if ptr[0] == ':':
+ */
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 481, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(4, 481, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":480
+ * 
+ *         ptr = apg_parse_int32(ptr, &ubound)
+ *         if ptr == NULL:             # <<<<<<<<<<<<<<
+ *             raise ValueError('missing array dimension value')
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":483
+ *             raise ValueError('missing array dimension value')
+ * 
+ *         if ptr[0] == ':':             # <<<<<<<<<<<<<<
+ *             ptr += 1
+ *             lbound = ubound
+ */
+    __pyx_t_1 = (((__pyx_v_ptr[0]) == 58) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":484
+ * 
+ *         if ptr[0] == ':':
+ *             ptr += 1             # <<<<<<<<<<<<<<
+ *             lbound = ubound
+ * 
+ */
+      __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+      /* "asyncpg/protocol/codecs/array.pyx":485
+ *         if ptr[0] == ':':
+ *             ptr += 1
+ *             lbound = ubound             # <<<<<<<<<<<<<<
+ * 
+ *             # [lower:upper] spec.  We disregard the lbound for decoding.
+ */
+      __pyx_v_lbound = __pyx_v_ubound;
+
+      /* "asyncpg/protocol/codecs/array.pyx":488
+ * 
+ *             # [lower:upper] spec.  We disregard the lbound for decoding.
+ *             ptr = apg_parse_int32(ptr, &ubound)             # <<<<<<<<<<<<<<
+ *             if ptr == NULL:
+ *                 raise ValueError('missing array dimension value')
+ */
+      __pyx_v_ptr = __pyx_f_7asyncpg_8protocol_8protocol_apg_parse_int32(__pyx_v_ptr, (&__pyx_v_ubound));
+
+      /* "asyncpg/protocol/codecs/array.pyx":489
+ *             # [lower:upper] spec.  We disregard the lbound for decoding.
+ *             ptr = apg_parse_int32(ptr, &ubound)
+ *             if ptr == NULL:             # <<<<<<<<<<<<<<
+ *                 raise ValueError('missing array dimension value')
+ *         else:
+ */
+      __pyx_t_1 = ((__pyx_v_ptr == NULL) != 0);
+      if (unlikely(__pyx_t_1)) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":490
+ *             ptr = apg_parse_int32(ptr, &ubound)
+ *             if ptr == NULL:
+ *                 raise ValueError('missing array dimension value')             # <<<<<<<<<<<<<<
+ *         else:
+ *             lbound = 1
+ */
+        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 490, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __PYX_ERR(4, 490, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/array.pyx":489
+ *             # [lower:upper] spec.  We disregard the lbound for decoding.
+ *             ptr = apg_parse_int32(ptr, &ubound)
+ *             if ptr == NULL:             # <<<<<<<<<<<<<<
+ *                 raise ValueError('missing array dimension value')
+ *         else:
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":483
+ *             raise ValueError('missing array dimension value')
+ * 
+ *         if ptr[0] == ':':             # <<<<<<<<<<<<<<
+ *             ptr += 1
+ *             lbound = ubound
+ */
+      goto __pyx_L10;
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":492
+ *                 raise ValueError('missing array dimension value')
+ *         else:
+ *             lbound = 1             # <<<<<<<<<<<<<<
+ * 
+ *         if ptr[0] != ']':
+ */
+    /*else*/ {
+      __pyx_v_lbound = 1;
+    }
+    __pyx_L10:;
+
+    /* "asyncpg/protocol/codecs/array.pyx":494
+ *             lbound = 1
+ * 
+ *         if ptr[0] != ']':             # <<<<<<<<<<<<<<
+ *             raise ValueError('missing \']\' after array dimensions')
+ * 
+ */
+    __pyx_t_1 = (((__pyx_v_ptr[0]) != 93) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":495
+ * 
+ *         if ptr[0] != ']':
+ *             raise ValueError('missing \']\' after array dimensions')             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1  # ']'
+ */
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 495, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(4, 495, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":494
+ *             lbound = 1
+ * 
+ *         if ptr[0] != ']':             # <<<<<<<<<<<<<<
+ *             raise ValueError('missing \']\' after array dimensions')
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":497
+ *             raise ValueError('missing \']\' after array dimensions')
+ * 
+ *         ptr += 1  # ']'             # <<<<<<<<<<<<<<
+ * 
+ *         dims[ndims] = ubound - lbound + 1
+ */
+    __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+    /* "asyncpg/protocol/codecs/array.pyx":499
+ *         ptr += 1  # ']'
+ * 
+ *         dims[ndims] = ubound - lbound + 1             # <<<<<<<<<<<<<<
+ *         ndims += 1
+ * 
+ */
+    (__pyx_v_dims[__pyx_v_ndims]) = ((__pyx_v_ubound - __pyx_v_lbound) + 1);
+
+    /* "asyncpg/protocol/codecs/array.pyx":500
+ * 
+ *         dims[ndims] = ubound - lbound + 1
+ *         ndims += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if ndims != 0:
+ */
+    __pyx_v_ndims = (__pyx_v_ndims + 1);
+  }
+  __pyx_L4_break:;
+
+  /* "asyncpg/protocol/codecs/array.pyx":502
+ *         ndims += 1
+ * 
+ *     if ndims != 0:             # <<<<<<<<<<<<<<
+ *         # If dimensions were given, the '=' token is expected.
+ *         if ptr[0] != '=':
+ */
+  __pyx_t_1 = ((__pyx_v_ndims != 0) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":504
+ *     if ndims != 0:
+ *         # If dimensions were given, the '=' token is expected.
+ *         if ptr[0] != '=':             # <<<<<<<<<<<<<<
+ *             raise ValueError('missing \'=\' after array dimensions')
+ * 
+ */
+    __pyx_t_1 = (((__pyx_v_ptr[0]) != 61) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":505
+ *         # If dimensions were given, the '=' token is expected.
+ *         if ptr[0] != '=':
+ *             raise ValueError('missing \'=\' after array dimensions')             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1  # '='
+ */
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 505, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(4, 505, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":504
+ *     if ndims != 0:
+ *         # If dimensions were given, the '=' token is expected.
+ *         if ptr[0] != '=':             # <<<<<<<<<<<<<<
+ *             raise ValueError('missing \'=\' after array dimensions')
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":507
+ *             raise ValueError('missing \'=\' after array dimensions')
+ * 
+ *         ptr += 1  # '='             # <<<<<<<<<<<<<<
+ * 
+ *         # Skip any whitespace after the '=', whitespace
+ */
+    __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+    /* "asyncpg/protocol/codecs/array.pyx":511
+ *         # Skip any whitespace after the '=', whitespace
+ *         # before was consumed in the above loop.
+ *         while apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *             ptr += 1
+ * 
+ */
+    while (1) {
+      __pyx_t_1 = (__pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace((__pyx_v_ptr[0])) != 0);
+      if (!__pyx_t_1) break;
+
+      /* "asyncpg/protocol/codecs/array.pyx":512
+ *         # before was consumed in the above loop.
+ *         while apg_ascii_isspace(ptr[0]):
+ *             ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *         # Infer the dimensions from the brace structure in the
+ */
+      __pyx_v_ptr = (__pyx_v_ptr + 1);
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":517
+ *         # array literal body, and check that it matches the explicit
+ *         # spec.  This also validates that the array literal is sane.
+ *         _infer_array_dims(ptr, typdelim, inferred_dims, &inferred_ndims)             # <<<<<<<<<<<<<<
+ * 
+ *         if inferred_ndims != ndims:
+ */
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__infer_array_dims(__pyx_v_ptr, __pyx_v_typdelim, __pyx_v_inferred_dims, (&__pyx_v_inferred_ndims)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 517, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":519
+ *         _infer_array_dims(ptr, typdelim, inferred_dims, &inferred_ndims)
+ * 
+ *         if inferred_ndims != ndims:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                 'specified array dimensions do not match array content')
+ */
+    __pyx_t_1 = ((__pyx_v_inferred_ndims != __pyx_v_ndims) != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":520
+ * 
+ *         if inferred_ndims != ndims:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                 'specified array dimensions do not match array content')
+ * 
+ */
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 520, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(4, 520, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":519
+ *         _infer_array_dims(ptr, typdelim, inferred_dims, &inferred_ndims)
+ * 
+ *         if inferred_ndims != ndims:             # <<<<<<<<<<<<<<
+ *             raise ValueError(
+ *                 'specified array dimensions do not match array content')
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":523
+ *                 'specified array dimensions do not match array content')
+ * 
+ *         for i in range(ndims):             # <<<<<<<<<<<<<<
+ *             if inferred_dims[i] != dims[i]:
+ *                 raise ValueError(
+ */
+    __pyx_t_8 = __pyx_v_ndims;
+    __pyx_t_9 = __pyx_t_8;
+    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_9; __pyx_t_6+=1) {
+      __pyx_v_i = __pyx_t_6;
+
+      /* "asyncpg/protocol/codecs/array.pyx":524
+ * 
+ *         for i in range(ndims):
+ *             if inferred_dims[i] != dims[i]:             # <<<<<<<<<<<<<<
+ *                 raise ValueError(
+ *                     'specified array dimensions do not match array content')
+ */
+      __pyx_t_1 = (((__pyx_v_inferred_dims[__pyx_v_i]) != (__pyx_v_dims[__pyx_v_i])) != 0);
+      if (unlikely(__pyx_t_1)) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":525
+ *         for i in range(ndims):
+ *             if inferred_dims[i] != dims[i]:
+ *                 raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'specified array dimensions do not match array content')
+ *     else:
+ */
+        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 525, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __PYX_ERR(4, 525, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/array.pyx":524
+ * 
+ *         for i in range(ndims):
+ *             if inferred_dims[i] != dims[i]:             # <<<<<<<<<<<<<<
+ *                 raise ValueError(
+ *                     'specified array dimensions do not match array content')
+ */
+      }
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":502
+ *         ndims += 1
+ * 
+ *     if ndims != 0:             # <<<<<<<<<<<<<<
+ *         # If dimensions were given, the '=' token is expected.
+ *         if ptr[0] != '=':
+ */
+    goto __pyx_L13;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":530
+ *         # Infer the dimensions from the brace structure in the array literal
+ *         # body.  This also validates that the array literal is sane.
+ *         _infer_array_dims(ptr, typdelim, dims, &ndims)             # <<<<<<<<<<<<<<
+ * 
+ *     while not end_of_array:
+ */
+  /*else*/ {
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__infer_array_dims(__pyx_v_ptr, __pyx_v_typdelim, __pyx_v_dims, (&__pyx_v_ndims)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 530, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  }
+  __pyx_L13:;
+
+  /* "asyncpg/protocol/codecs/array.pyx":532
+ *         _infer_array_dims(ptr, typdelim, dims, &ndims)
+ * 
+ *     while not end_of_array:             # <<<<<<<<<<<<<<
+ *         # We iterate over the literal character by character
+ *         # and modify the string in-place removing the array-specific
+ */
+  while (1) {
+    __pyx_t_1 = ((!(__pyx_v_end_of_array != 0)) != 0);
+    if (!__pyx_t_1) break;
+
+    /* "asyncpg/protocol/codecs/array.pyx":536
+ *         # and modify the string in-place removing the array-specific
+ *         # quoting and determining the boundaries of each element.
+ *         end_of_item = has_quoting = in_quotes = False             # <<<<<<<<<<<<<<
+ *         strip_spaces = True
+ * 
+ */
+    __pyx_v_end_of_item = 0;
+    __pyx_v_has_quoting = 0;
+    __pyx_v_in_quotes = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":537
+ *         # quoting and determining the boundaries of each element.
+ *         end_of_item = has_quoting = in_quotes = False
+ *         strip_spaces = True             # <<<<<<<<<<<<<<
+ * 
+ *         # Pointers to array element start, end, and the current pointer
+ */
+    __pyx_v_strip_spaces = 1;
+
+    /* "asyncpg/protocol/codecs/array.pyx":542
+ *         # tracking the position where characters are written when
+ *         # escaping is folded.
+ *         item_start = item_end = item_ptr = ptr             # <<<<<<<<<<<<<<
+ *         item_level = 0
+ * 
+ */
+    __pyx_v_item_start = __pyx_v_ptr;
+    __pyx_v_item_end = __pyx_v_ptr;
+    __pyx_v_item_ptr = __pyx_v_ptr;
+
+    /* "asyncpg/protocol/codecs/array.pyx":543
+ *         # escaping is folded.
+ *         item_start = item_end = item_ptr = ptr
+ *         item_level = 0             # <<<<<<<<<<<<<<
+ * 
+ *         while not end_of_item:
+ */
+    __pyx_v_item_level = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":545
+ *         item_level = 0
+ * 
+ *         while not end_of_item:             # <<<<<<<<<<<<<<
+ *             if ptr[0] == '"':
+ *                 in_quotes = not in_quotes
+ */
+    while (1) {
+      __pyx_t_1 = ((!(__pyx_v_end_of_item != 0)) != 0);
+      if (!__pyx_t_1) break;
+
+      /* "asyncpg/protocol/codecs/array.pyx":546
+ * 
+ *         while not end_of_item:
+ *             if ptr[0] == '"':             # <<<<<<<<<<<<<<
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:
+ */
+      __pyx_t_1 = (((__pyx_v_ptr[0]) == 34) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":547
+ *         while not end_of_item:
+ *             if ptr[0] == '"':
+ *                 in_quotes = not in_quotes             # <<<<<<<<<<<<<<
+ *                 if in_quotes:
+ *                     strip_spaces = False
+ */
+        __pyx_v_in_quotes = (!(__pyx_v_in_quotes != 0));
+
+        /* "asyncpg/protocol/codecs/array.pyx":548
+ *             if ptr[0] == '"':
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:             # <<<<<<<<<<<<<<
+ *                     strip_spaces = False
+ *                 else:
+ */
+        __pyx_t_1 = (__pyx_v_in_quotes != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":549
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:
+ *                     strip_spaces = False             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     item_end = item_ptr
+ */
+          __pyx_v_strip_spaces = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":548
+ *             if ptr[0] == '"':
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:             # <<<<<<<<<<<<<<
+ *                     strip_spaces = False
+ *                 else:
+ */
+          goto __pyx_L26;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":551
+ *                     strip_spaces = False
+ *                 else:
+ *                     item_end = item_ptr             # <<<<<<<<<<<<<<
+ *                 has_quoting = True
+ * 
+ */
+        /*else*/ {
+          __pyx_v_item_end = __pyx_v_item_ptr;
+        }
+        __pyx_L26:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":552
+ *                 else:
+ *                     item_end = item_ptr
+ *                 has_quoting = True             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '\\':
+ */
+        __pyx_v_has_quoting = 1;
+
+        /* "asyncpg/protocol/codecs/array.pyx":546
+ * 
+ *         while not end_of_item:
+ *             if ptr[0] == '"':             # <<<<<<<<<<<<<<
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":554
+ *                 has_quoting = True
+ * 
+ *             elif ptr[0] == '\\':             # <<<<<<<<<<<<<<
+ *                 # Quoted character, collapse the backslash.
+ *                 ptr += 1
+ */
+      __pyx_t_1 = (((__pyx_v_ptr[0]) == 92) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":556
+ *             elif ptr[0] == '\\':
+ *                 # Quoted character, collapse the backslash.
+ *                 ptr += 1             # <<<<<<<<<<<<<<
+ *                 has_quoting = True
+ *                 item_ptr[0] = ptr[0]
+ */
+        __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":557
+ *                 # Quoted character, collapse the backslash.
+ *                 ptr += 1
+ *                 has_quoting = True             # <<<<<<<<<<<<<<
+ *                 item_ptr[0] = ptr[0]
+ *                 item_ptr += 1
+ */
+        __pyx_v_has_quoting = 1;
+
+        /* "asyncpg/protocol/codecs/array.pyx":558
+ *                 ptr += 1
+ *                 has_quoting = True
+ *                 item_ptr[0] = ptr[0]             # <<<<<<<<<<<<<<
+ *                 item_ptr += 1
+ *                 strip_spaces = False
+ */
+        (__pyx_v_item_ptr[0]) = (__pyx_v_ptr[0]);
+
+        /* "asyncpg/protocol/codecs/array.pyx":559
+ *                 has_quoting = True
+ *                 item_ptr[0] = ptr[0]
+ *                 item_ptr += 1             # <<<<<<<<<<<<<<
+ *                 strip_spaces = False
+ *                 item_end = item_ptr
+ */
+        __pyx_v_item_ptr = (__pyx_v_item_ptr + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":560
+ *                 item_ptr[0] = ptr[0]
+ *                 item_ptr += 1
+ *                 strip_spaces = False             # <<<<<<<<<<<<<<
+ *                 item_end = item_ptr
+ * 
+ */
+        __pyx_v_strip_spaces = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":561
+ *                 item_ptr += 1
+ *                 strip_spaces = False
+ *                 item_end = item_ptr             # <<<<<<<<<<<<<<
+ * 
+ *             elif in_quotes:
+ */
+        __pyx_v_item_end = __pyx_v_item_ptr;
+
+        /* "asyncpg/protocol/codecs/array.pyx":554
+ *                 has_quoting = True
+ * 
+ *             elif ptr[0] == '\\':             # <<<<<<<<<<<<<<
+ *                 # Quoted character, collapse the backslash.
+ *                 ptr += 1
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":563
+ *                 item_end = item_ptr
+ * 
+ *             elif in_quotes:             # <<<<<<<<<<<<<<
+ *                 # Consume the string until we see the closing quote.
+ *                 item_ptr[0] = ptr[0]
+ */
+      __pyx_t_1 = (__pyx_v_in_quotes != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":565
+ *             elif in_quotes:
+ *                 # Consume the string until we see the closing quote.
+ *                 item_ptr[0] = ptr[0]             # <<<<<<<<<<<<<<
+ *                 item_ptr += 1
+ * 
+ */
+        (__pyx_v_item_ptr[0]) = (__pyx_v_ptr[0]);
+
+        /* "asyncpg/protocol/codecs/array.pyx":566
+ *                 # Consume the string until we see the closing quote.
+ *                 item_ptr[0] = ptr[0]
+ *                 item_ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '{':
+ */
+        __pyx_v_item_ptr = (__pyx_v_item_ptr + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":563
+ *                 item_end = item_ptr
+ * 
+ *             elif in_quotes:             # <<<<<<<<<<<<<<
+ *                 # Consume the string until we see the closing quote.
+ *                 item_ptr[0] = ptr[0]
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":568
+ *                 item_ptr += 1
+ * 
+ *             elif ptr[0] == '{':             # <<<<<<<<<<<<<<
+ *                 # Nesting level increase.
+ *                 nest_level += 1
+ */
+      __pyx_t_1 = (((__pyx_v_ptr[0]) == 0x7B) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":570
+ *             elif ptr[0] == '{':
+ *                 # Nesting level increase.
+ *                 nest_level += 1             # <<<<<<<<<<<<<<
+ * 
+ *                 indexes[nest_level - 1] = 0
+ */
+        __pyx_v_nest_level = (__pyx_v_nest_level + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":572
+ *                 nest_level += 1
+ * 
+ *                 indexes[nest_level - 1] = 0             # <<<<<<<<<<<<<<
+ *                 new_stride = cpython.PyList_New(dims[nest_level - 1])
+ *                 strides[nest_level - 1] = \
+ */
+        (__pyx_v_indexes[(__pyx_v_nest_level - 1)]) = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":573
+ * 
+ *                 indexes[nest_level - 1] = 0
+ *                 new_stride = cpython.PyList_New(dims[nest_level - 1])             # <<<<<<<<<<<<<<
+ *                 strides[nest_level - 1] = \
+ *                     <void*>(<cpython.PyObject>new_stride)
+ */
+        __pyx_t_3 = PyList_New((__pyx_v_dims[(__pyx_v_nest_level - 1)])); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 573, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_XDECREF_SET(__pyx_v_new_stride, ((PyObject*)__pyx_t_3));
+        __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":574
+ *                 indexes[nest_level - 1] = 0
+ *                 new_stride = cpython.PyList_New(dims[nest_level - 1])
+ *                 strides[nest_level - 1] = \             # <<<<<<<<<<<<<<
+ *                     <void*>(<cpython.PyObject>new_stride)
+ * 
+ */
+        (__pyx_v_strides[(__pyx_v_nest_level - 1)]) = ((void *)__pyx_v_new_stride);
+
+        /* "asyncpg/protocol/codecs/array.pyx":577
+ *                     <void*>(<cpython.PyObject>new_stride)
+ * 
+ *                 if nest_level > 1:             # <<<<<<<<<<<<<<
+ *                     cpython.Py_INCREF(new_stride)
+ *                     cpython.PyList_SET_ITEM(
+ */
+        __pyx_t_1 = ((__pyx_v_nest_level > 1) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":578
+ * 
+ *                 if nest_level > 1:
+ *                     cpython.Py_INCREF(new_stride)             # <<<<<<<<<<<<<<
+ *                     cpython.PyList_SET_ITEM(
+ *                         <object><cpython.PyObject*>strides[nest_level - 2],
+ */
+          Py_INCREF(__pyx_v_new_stride);
+
+          /* "asyncpg/protocol/codecs/array.pyx":580
+ *                     cpython.Py_INCREF(new_stride)
+ *                     cpython.PyList_SET_ITEM(
+ *                         <object><cpython.PyObject*>strides[nest_level - 2],             # <<<<<<<<<<<<<<
+ *                         indexes[nest_level - 2],
+ *                         new_stride)
+ */
+          __pyx_t_10 = ((PyObject *)(__pyx_v_strides[(__pyx_v_nest_level - 2)]));
+
+          /* "asyncpg/protocol/codecs/array.pyx":579
+ *                 if nest_level > 1:
+ *                     cpython.Py_INCREF(new_stride)
+ *                     cpython.PyList_SET_ITEM(             # <<<<<<<<<<<<<<
+ *                         <object><cpython.PyObject*>strides[nest_level - 2],
+ *                         indexes[nest_level - 2],
+ */
+          PyList_SET_ITEM(((PyObject *)__pyx_t_10), (__pyx_v_indexes[(__pyx_v_nest_level - 2)]), __pyx_v_new_stride);
+
+          /* "asyncpg/protocol/codecs/array.pyx":577
+ *                     <void*>(<cpython.PyObject>new_stride)
+ * 
+ *                 if nest_level > 1:             # <<<<<<<<<<<<<<
+ *                     cpython.Py_INCREF(new_stride)
+ *                     cpython.PyList_SET_ITEM(
+ */
+          goto __pyx_L27;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":584
+ *                         new_stride)
+ *                 else:
+ *                     result = new_stride             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '}':
+ */
+        /*else*/ {
+          __Pyx_INCREF(__pyx_v_new_stride);
+          __Pyx_XDECREF_SET(__pyx_v_result, __pyx_v_new_stride);
+        }
+        __pyx_L27:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":568
+ *                 item_ptr += 1
+ * 
+ *             elif ptr[0] == '{':             # <<<<<<<<<<<<<<
+ *                 # Nesting level increase.
+ *                 nest_level += 1
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":586
+ *                     result = new_stride
+ * 
+ *             elif ptr[0] == '}':             # <<<<<<<<<<<<<<
+ *                 if item_level == 0:
+ *                     # Make sure we keep track of which nesting
+ */
+      __pyx_t_1 = (((__pyx_v_ptr[0]) == 0x7D) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":587
+ * 
+ *             elif ptr[0] == '}':
+ *                 if item_level == 0:             # <<<<<<<<<<<<<<
+ *                     # Make sure we keep track of which nesting
+ *                     # level the item belongs to, as the loop
+ */
+        __pyx_t_1 = ((__pyx_v_item_level == 0) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":592
+ *                     # will continue to consume closing braces
+ *                     # until the delimiter or the end of input.
+ *                     item_level = nest_level             # <<<<<<<<<<<<<<
+ * 
+ *                 nest_level -= 1
+ */
+          __pyx_v_item_level = __pyx_v_nest_level;
+
+          /* "asyncpg/protocol/codecs/array.pyx":587
+ * 
+ *             elif ptr[0] == '}':
+ *                 if item_level == 0:             # <<<<<<<<<<<<<<
+ *                     # Make sure we keep track of which nesting
+ *                     # level the item belongs to, as the loop
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":594
+ *                     item_level = nest_level
+ * 
+ *                 nest_level -= 1             # <<<<<<<<<<<<<<
+ * 
+ *                 if nest_level == 0:
+ */
+        __pyx_v_nest_level = (__pyx_v_nest_level - 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":596
+ *                 nest_level -= 1
+ * 
+ *                 if nest_level == 0:             # <<<<<<<<<<<<<<
+ *                     end_of_array = end_of_item = True
+ * 
+ */
+        __pyx_t_1 = ((__pyx_v_nest_level == 0) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":597
+ * 
+ *                 if nest_level == 0:
+ *                     end_of_array = end_of_item = True             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == typdelim:
+ */
+          __pyx_v_end_of_array = 1;
+          __pyx_v_end_of_item = 1;
+
+          /* "asyncpg/protocol/codecs/array.pyx":596
+ *                 nest_level -= 1
+ * 
+ *                 if nest_level == 0:             # <<<<<<<<<<<<<<
+ *                     end_of_array = end_of_item = True
+ * 
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":586
+ *                     result = new_stride
+ * 
+ *             elif ptr[0] == '}':             # <<<<<<<<<<<<<<
+ *                 if item_level == 0:
+ *                     # Make sure we keep track of which nesting
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":599
+ *                     end_of_array = end_of_item = True
+ * 
+ *             elif ptr[0] == typdelim:             # <<<<<<<<<<<<<<
+ *                 # Array element delimiter,
+ *                 end_of_item = True
+ */
+      __pyx_t_1 = (((__pyx_v_ptr[0]) == __pyx_v_typdelim) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":601
+ *             elif ptr[0] == typdelim:
+ *                 # Array element delimiter,
+ *                 end_of_item = True             # <<<<<<<<<<<<<<
+ *                 if item_level == 0:
+ *                     item_level = nest_level
+ */
+        __pyx_v_end_of_item = 1;
+
+        /* "asyncpg/protocol/codecs/array.pyx":602
+ *                 # Array element delimiter,
+ *                 end_of_item = True
+ *                 if item_level == 0:             # <<<<<<<<<<<<<<
+ *                     item_level = nest_level
+ * 
+ */
+        __pyx_t_1 = ((__pyx_v_item_level == 0) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":603
+ *                 end_of_item = True
+ *                 if item_level == 0:
+ *                     item_level = nest_level             # <<<<<<<<<<<<<<
+ * 
+ *             elif apg_ascii_isspace(ptr[0]):
+ */
+          __pyx_v_item_level = __pyx_v_nest_level;
+
+          /* "asyncpg/protocol/codecs/array.pyx":602
+ *                 # Array element delimiter,
+ *                 end_of_item = True
+ *                 if item_level == 0:             # <<<<<<<<<<<<<<
+ *                     item_level = nest_level
+ * 
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":599
+ *                     end_of_array = end_of_item = True
+ * 
+ *             elif ptr[0] == typdelim:             # <<<<<<<<<<<<<<
+ *                 # Array element delimiter,
+ *                 end_of_item = True
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":605
+ *                     item_level = nest_level
+ * 
+ *             elif apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *                 if not strip_spaces:
+ *                     item_ptr[0] = ptr[0]
+ */
+      __pyx_t_1 = (__pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace((__pyx_v_ptr[0])) != 0);
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":606
+ * 
+ *             elif apg_ascii_isspace(ptr[0]):
+ *                 if not strip_spaces:             # <<<<<<<<<<<<<<
+ *                     item_ptr[0] = ptr[0]
+ *                     item_ptr += 1
+ */
+        __pyx_t_1 = ((!(__pyx_v_strip_spaces != 0)) != 0);
+        if (__pyx_t_1) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":607
+ *             elif apg_ascii_isspace(ptr[0]):
+ *                 if not strip_spaces:
+ *                     item_ptr[0] = ptr[0]             # <<<<<<<<<<<<<<
+ *                     item_ptr += 1
+ *                 # Ignore the leading literal whitespace.
+ */
+          (__pyx_v_item_ptr[0]) = (__pyx_v_ptr[0]);
+
+          /* "asyncpg/protocol/codecs/array.pyx":608
+ *                 if not strip_spaces:
+ *                     item_ptr[0] = ptr[0]
+ *                     item_ptr += 1             # <<<<<<<<<<<<<<
+ *                 # Ignore the leading literal whitespace.
+ * 
+ */
+          __pyx_v_item_ptr = (__pyx_v_item_ptr + 1);
+
+          /* "asyncpg/protocol/codecs/array.pyx":606
+ * 
+ *             elif apg_ascii_isspace(ptr[0]):
+ *                 if not strip_spaces:             # <<<<<<<<<<<<<<
+ *                     item_ptr[0] = ptr[0]
+ *                     item_ptr += 1
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":605
+ *                     item_level = nest_level
+ * 
+ *             elif apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *                 if not strip_spaces:
+ *                     item_ptr[0] = ptr[0]
+ */
+        goto __pyx_L25;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":612
+ * 
+ *             else:
+ *                 item_ptr[0] = ptr[0]             # <<<<<<<<<<<<<<
+ *                 item_ptr += 1
+ *                 strip_spaces = False
+ */
+      /*else*/ {
+        (__pyx_v_item_ptr[0]) = (__pyx_v_ptr[0]);
+
+        /* "asyncpg/protocol/codecs/array.pyx":613
+ *             else:
+ *                 item_ptr[0] = ptr[0]
+ *                 item_ptr += 1             # <<<<<<<<<<<<<<
+ *                 strip_spaces = False
+ *                 item_end = item_ptr
+ */
+        __pyx_v_item_ptr = (__pyx_v_item_ptr + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":614
+ *                 item_ptr[0] = ptr[0]
+ *                 item_ptr += 1
+ *                 strip_spaces = False             # <<<<<<<<<<<<<<
+ *                 item_end = item_ptr
+ * 
+ */
+        __pyx_v_strip_spaces = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":615
+ *                 item_ptr += 1
+ *                 strip_spaces = False
+ *                 item_end = item_ptr             # <<<<<<<<<<<<<<
+ * 
+ *             ptr += 1
+ */
+        __pyx_v_item_end = __pyx_v_item_ptr;
+      }
+      __pyx_L25:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":617
+ *                 item_end = item_ptr
+ * 
+ *             ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *         # end while not end_of_item
+ */
+      __pyx_v_ptr = (__pyx_v_ptr + 1);
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":621
+ *         # end while not end_of_item
+ * 
+ *         if item_end == item_start:             # <<<<<<<<<<<<<<
+ *             # Empty array
+ *             continue
+ */
+    __pyx_t_1 = ((__pyx_v_item_end == __pyx_v_item_start) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":623
+ *         if item_end == item_start:
+ *             # Empty array
+ *             continue             # <<<<<<<<<<<<<<
+ * 
+ *         item_end[0] = '\0'
+ */
+      goto __pyx_L21_continue;
+
+      /* "asyncpg/protocol/codecs/array.pyx":621
+ *         # end while not end_of_item
+ * 
+ *         if item_end == item_start:             # <<<<<<<<<<<<<<
+ *             # Empty array
+ *             continue
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":625
+ *             continue
+ * 
+ *         item_end[0] = '\0'             # <<<<<<<<<<<<<<
+ * 
+ *         if not has_quoting and apg_strcasecmp(item_start, APG_NULL) == 0:
+ */
+    (__pyx_v_item_end[0]) = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":627
+ *         item_end[0] = '\0'
+ * 
+ *         if not has_quoting and apg_strcasecmp(item_start, APG_NULL) == 0:             # <<<<<<<<<<<<<<
+ *             # NULL element.
+ *             item = None
+ */
+    __pyx_t_11 = ((!(__pyx_v_has_quoting != 0)) != 0);
+    if (__pyx_t_11) {
+    } else {
+      __pyx_t_1 = __pyx_t_11;
+      goto __pyx_L34_bool_binop_done;
+    }
+    __pyx_t_11 = ((__pyx_f_7asyncpg_8protocol_8protocol_apg_strcasecmp(__pyx_v_item_start, __pyx_v_7asyncpg_8protocol_8protocol_APG_NULL) == 0) != 0);
+    __pyx_t_1 = __pyx_t_11;
+    __pyx_L34_bool_binop_done:;
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":629
+ *         if not has_quoting and apg_strcasecmp(item_start, APG_NULL) == 0:
+ *             # NULL element.
+ *             item = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             # XXX: find a way to avoid the redundant encode/decode
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_item, Py_None);
+
+      /* "asyncpg/protocol/codecs/array.pyx":627
+ *         item_end[0] = '\0'
+ * 
+ *         if not has_quoting and apg_strcasecmp(item_start, APG_NULL) == 0:             # <<<<<<<<<<<<<<
+ *             # NULL element.
+ *             item = None
+ */
+      goto __pyx_L33;
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":633
+ *             # XXX: find a way to avoid the redundant encode/decode
+ *             # cycle here.
+ *             item_text = cpythonx.PyUnicode_FromKindAndData(             # <<<<<<<<<<<<<<
+ *                 cpythonx.PyUnicode_4BYTE_KIND,
+ *                 <void *>item_start,
+ */
+    /*else*/ {
+
+      /* "asyncpg/protocol/codecs/array.pyx":636
+ *                 cpythonx.PyUnicode_4BYTE_KIND,
+ *                 <void *>item_start,
+ *                 item_end - item_start)             # <<<<<<<<<<<<<<
+ * 
+ *             # Prepare the element buffer and call the text decoder
+ */
+      __pyx_t_3 = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, ((void *)__pyx_v_item_start), (__pyx_v_item_end - __pyx_v_item_start)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 633, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+
+      /* "asyncpg/protocol/codecs/array.pyx":633
+ *             # XXX: find a way to avoid the redundant encode/decode
+ *             # cycle here.
+ *             item_text = cpythonx.PyUnicode_FromKindAndData(             # <<<<<<<<<<<<<<
+ *                 cpythonx.PyUnicode_4BYTE_KIND,
+ *                 <void *>item_start,
+ */
+      if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(4, 633, __pyx_L1_error)
+      __Pyx_XDECREF_SET(__pyx_v_item_text, ((PyObject*)__pyx_t_3));
+      __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":640
+ *             # Prepare the element buffer and call the text decoder
+ *             # for the element type.
+ *             pgproto.as_pg_string_and_size(             # <<<<<<<<<<<<<<
+ *                 settings, item_text, &pg_item_str, &pg_item_len)
+ *             frb_init(&item_buf, pg_item_str, pg_item_len)
+ */
+      __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_item_text, (&__pyx_v_pg_item_str), (&__pyx_v_pg_item_len)); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 640, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/codecs/array.pyx":642
+ *             pgproto.as_pg_string_and_size(
+ *                 settings, item_text, &pg_item_str, &pg_item_len)
+ *             frb_init(&item_buf, pg_item_str, pg_item_len)             # <<<<<<<<<<<<<<
+ *             item = decoder(settings, &item_buf, decoder_arg)
+ * 
+ */
+      __pyx_f_7asyncpg_7pgproto_7pgproto_frb_init((&__pyx_v_item_buf), __pyx_v_pg_item_str, __pyx_v_pg_item_len);
+
+      /* "asyncpg/protocol/codecs/array.pyx":643
+ *                 settings, item_text, &pg_item_str, &pg_item_len)
+ *             frb_init(&item_buf, pg_item_str, pg_item_len)
+ *             item = decoder(settings, &item_buf, decoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *         # Place the decoded element in the array.
+ */
+      __pyx_t_3 = __pyx_v_decoder(__pyx_v_settings, (&__pyx_v_item_buf), __pyx_v_decoder_arg); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 643, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_3);
+      __pyx_t_3 = 0;
+    }
+    __pyx_L33:;
+
+    /* "asyncpg/protocol/codecs/array.pyx":646
+ * 
+ *         # Place the decoded element in the array.
+ *         cpython.Py_INCREF(item)             # <<<<<<<<<<<<<<
+ *         cpython.PyList_SET_ITEM(
+ *             <object><cpython.PyObject*>strides[item_level - 1],
+ */
+    Py_INCREF(__pyx_v_item);
+
+    /* "asyncpg/protocol/codecs/array.pyx":648
+ *         cpython.Py_INCREF(item)
+ *         cpython.PyList_SET_ITEM(
+ *             <object><cpython.PyObject*>strides[item_level - 1],             # <<<<<<<<<<<<<<
+ *             indexes[item_level - 1],
+ *             item)
+ */
+    __pyx_t_10 = ((PyObject *)(__pyx_v_strides[(__pyx_v_item_level - 1)]));
+
+    /* "asyncpg/protocol/codecs/array.pyx":647
+ *         # Place the decoded element in the array.
+ *         cpython.Py_INCREF(item)
+ *         cpython.PyList_SET_ITEM(             # <<<<<<<<<<<<<<
+ *             <object><cpython.PyObject*>strides[item_level - 1],
+ *             indexes[item_level - 1],
+ */
+    PyList_SET_ITEM(((PyObject *)__pyx_t_10), (__pyx_v_indexes[(__pyx_v_item_level - 1)]), __pyx_v_item);
+
+    /* "asyncpg/protocol/codecs/array.pyx":652
+ *             item)
+ * 
+ *         if nest_level > 0:             # <<<<<<<<<<<<<<
+ *             indexes[nest_level - 1] += 1
+ * 
+ */
+    __pyx_t_1 = ((__pyx_v_nest_level > 0) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":653
+ * 
+ *         if nest_level > 0:
+ *             indexes[nest_level - 1] += 1             # <<<<<<<<<<<<<<
+ * 
+ *     return result
+ */
+      __pyx_t_12 = (__pyx_v_nest_level - 1);
+      (__pyx_v_indexes[__pyx_t_12]) = ((__pyx_v_indexes[__pyx_t_12]) + 1);
+
+      /* "asyncpg/protocol/codecs/array.pyx":652
+ *             item)
+ * 
+ *         if nest_level > 0:             # <<<<<<<<<<<<<<
+ *             indexes[nest_level - 1] += 1
+ * 
+ */
+    }
+    __pyx_L21_continue:;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":655
+ *             indexes[nest_level - 1] += 1
+ * 
+ *     return result             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  if (unlikely(!__pyx_v_result)) { __Pyx_RaiseUnboundLocalError("result"); __PYX_ERR(4, 655, __pyx_L1_error) }
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":424
+ * 
+ * 
+ * cdef _textarray_decode(ConnectionSettings settings,             # <<<<<<<<<<<<<<
+ *                        Py_UCS4 *array_text,
+ *                        decode_func_ex decoder,
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._textarray_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF(__pyx_v_new_stride);
+  __Pyx_XDECREF(__pyx_v_item);
+  __Pyx_XDECREF(__pyx_v_item_text);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":667
+ * 
+ * 
+ * cdef _UnexpectedCharacter(const Py_UCS4 *array_text, const Py_UCS4 *ptr):             # <<<<<<<<<<<<<<
+ *     return ValueError('unexpected character {!r} at position {}'.format(
+ *         cpython.PyUnicode_FromOrdinal(<int>ptr[0]), ptr - array_text + 1))
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(Py_UCS4 const *__pyx_v_array_text, Py_UCS4 const *__pyx_v_ptr) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("_UnexpectedCharacter", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":668
+ * 
+ * cdef _UnexpectedCharacter(const Py_UCS4 *array_text, const Py_UCS4 *ptr):
+ *     return ValueError('unexpected character {!r} at position {}'.format(             # <<<<<<<<<<<<<<
+ *         cpython.PyUnicode_FromOrdinal(<int>ptr[0]), ptr - array_text + 1))
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_character_r_at_positi, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 668, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+
+  /* "asyncpg/protocol/codecs/array.pyx":669
+ * cdef _UnexpectedCharacter(const Py_UCS4 *array_text, const Py_UCS4 *ptr):
+ *     return ValueError('unexpected character {!r} at position {}'.format(
+ *         cpython.PyUnicode_FromOrdinal(<int>ptr[0]), ptr - array_text + 1))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_3 = PyUnicode_FromOrdinal(((int)(__pyx_v_ptr[0]))); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 669, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyInt_From_ptrdiff_t(((__pyx_v_ptr - __pyx_v_array_text) + 1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(4, 669, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  __pyx_t_6 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+      __pyx_t_6 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_t_4};
+    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 668, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_t_4};
+    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 668, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  } else
+  #endif
+  {
+    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 668, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    if (__pyx_t_5) {
+      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_3);
+    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_3);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_4);
+    __pyx_t_3 = 0;
+    __pyx_t_4 = 0;
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 668, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":668
+ * 
+ * cdef _UnexpectedCharacter(const Py_UCS4 *array_text, const Py_UCS4 *ptr):
+ *     return ValueError('unexpected character {!r} at position {}'.format(             # <<<<<<<<<<<<<<
+ *         cpython.PyUnicode_FromOrdinal(<int>ptr[0]), ptr - array_text + 1))
+ * 
+ */
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 668, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":667
+ * 
+ * 
+ * cdef _UnexpectedCharacter(const Py_UCS4 *array_text, const Py_UCS4 *ptr):             # <<<<<<<<<<<<<<
+ *     return ValueError('unexpected character {!r} at position {}'.format(
+ *         cpython.PyUnicode_FromOrdinal(<int>ptr[0]), ptr - array_text + 1))
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._UnexpectedCharacter", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":672
+ * 
+ * 
+ * cdef _infer_array_dims(const Py_UCS4 *array_text,             # <<<<<<<<<<<<<<
+ *                        Py_UCS4 typdelim,
+ *                        int32_t *dims,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__infer_array_dims(Py_UCS4 const *__pyx_v_array_text, Py_UCS4 __pyx_v_typdelim, int32_t *__pyx_v_dims, int32_t *__pyx_v_ndims) {
+  Py_UCS4 const *__pyx_v_ptr;
+  int __pyx_v_i;
+  int __pyx_v_nest_level;
+  int __pyx_v_end_of_array;
+  int __pyx_v_end_of_item;
+  int __pyx_v_in_quotes;
+  int __pyx_v_array_is_empty;
+  int __pyx_v_stride_len[6];
+  int __pyx_v_prev_stride_len[6];
+  enum __pyx_t_7asyncpg_8protocol_8protocol__ArrayParseState __pyx_v_parse_state;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  long __pyx_t_10;
+  __Pyx_RefNannySetupContext("_infer_array_dims", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":677
+ *                        int32_t *ndims):
+ *     cdef:
+ *         const Py_UCS4 *ptr = array_text             # <<<<<<<<<<<<<<
+ *         int i
+ *         int nest_level = 0
+ */
+  __pyx_v_ptr = __pyx_v_array_text;
+
+  /* "asyncpg/protocol/codecs/array.pyx":679
+ *         const Py_UCS4 *ptr = array_text
+ *         int i
+ *         int nest_level = 0             # <<<<<<<<<<<<<<
+ *         bint end_of_array = False
+ *         bint end_of_item = False
+ */
+  __pyx_v_nest_level = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":680
+ *         int i
+ *         int nest_level = 0
+ *         bint end_of_array = False             # <<<<<<<<<<<<<<
+ *         bint end_of_item = False
+ *         bint in_quotes = False
+ */
+  __pyx_v_end_of_array = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":681
+ *         int nest_level = 0
+ *         bint end_of_array = False
+ *         bint end_of_item = False             # <<<<<<<<<<<<<<
+ *         bint in_quotes = False
+ *         bint array_is_empty = True
+ */
+  __pyx_v_end_of_item = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":682
+ *         bint end_of_array = False
+ *         bint end_of_item = False
+ *         bint in_quotes = False             # <<<<<<<<<<<<<<
+ *         bint array_is_empty = True
+ *         int stride_len[ARRAY_MAXDIM]
+ */
+  __pyx_v_in_quotes = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":683
+ *         bint end_of_item = False
+ *         bint in_quotes = False
+ *         bint array_is_empty = True             # <<<<<<<<<<<<<<
+ *         int stride_len[ARRAY_MAXDIM]
+ *         int prev_stride_len[ARRAY_MAXDIM]
+ */
+  __pyx_v_array_is_empty = 1;
+
+  /* "asyncpg/protocol/codecs/array.pyx":686
+ *         int stride_len[ARRAY_MAXDIM]
+ *         int prev_stride_len[ARRAY_MAXDIM]
+ *         _ArrayParseState parse_state = APS_START             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(ARRAY_MAXDIM):
+ */
+  __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_START;
+
+  /* "asyncpg/protocol/codecs/array.pyx":688
+ *         _ArrayParseState parse_state = APS_START
+ * 
+ *     for i in range(ARRAY_MAXDIM):             # <<<<<<<<<<<<<<
+ *         dims[i] = prev_stride_len[i] = 0
+ *         stride_len[i] = 1
+ */
+  for (__pyx_t_1 = 0; __pyx_t_1 < 6; __pyx_t_1+=1) {
+    __pyx_v_i = __pyx_t_1;
+
+    /* "asyncpg/protocol/codecs/array.pyx":689
+ * 
+ *     for i in range(ARRAY_MAXDIM):
+ *         dims[i] = prev_stride_len[i] = 0             # <<<<<<<<<<<<<<
+ *         stride_len[i] = 1
+ * 
+ */
+    (__pyx_v_dims[__pyx_v_i]) = 0;
+    (__pyx_v_prev_stride_len[__pyx_v_i]) = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":690
+ *     for i in range(ARRAY_MAXDIM):
+ *         dims[i] = prev_stride_len[i] = 0
+ *         stride_len[i] = 1             # <<<<<<<<<<<<<<
+ * 
+ *     while not end_of_array:
+ */
+    (__pyx_v_stride_len[__pyx_v_i]) = 1;
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":692
+ *         stride_len[i] = 1
+ * 
+ *     while not end_of_array:             # <<<<<<<<<<<<<<
+ *         end_of_item = False
+ * 
+ */
+  while (1) {
+    __pyx_t_2 = ((!(__pyx_v_end_of_array != 0)) != 0);
+    if (!__pyx_t_2) break;
+
+    /* "asyncpg/protocol/codecs/array.pyx":693
+ * 
+ *     while not end_of_array:
+ *         end_of_item = False             # <<<<<<<<<<<<<<
+ * 
+ *         while not end_of_item:
+ */
+    __pyx_v_end_of_item = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":695
+ *         end_of_item = False
+ * 
+ *         while not end_of_item:             # <<<<<<<<<<<<<<
+ *             if ptr[0] == '\0':
+ *                 raise ValueError('unexpected end of string')
+ */
+    while (1) {
+      __pyx_t_2 = ((!(__pyx_v_end_of_item != 0)) != 0);
+      if (!__pyx_t_2) break;
+
+      /* "asyncpg/protocol/codecs/array.pyx":696
+ * 
+ *         while not end_of_item:
+ *             if ptr[0] == '\0':             # <<<<<<<<<<<<<<
+ *                 raise ValueError('unexpected end of string')
+ * 
+ */
+      __pyx_t_2 = (((__pyx_v_ptr[0]) == 0) != 0);
+      if (unlikely(__pyx_t_2)) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":697
+ *         while not end_of_item:
+ *             if ptr[0] == '\0':
+ *                 raise ValueError('unexpected end of string')             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '"':
+ */
+        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 697, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __PYX_ERR(4, 697, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/array.pyx":696
+ * 
+ *         while not end_of_item:
+ *             if ptr[0] == '\0':             # <<<<<<<<<<<<<<
+ *                 raise ValueError('unexpected end of string')
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":699
+ *                 raise ValueError('unexpected end of string')
+ * 
+ *             elif ptr[0] == '"':             # <<<<<<<<<<<<<<
+ *                 if (parse_state not in (APS_STRIDE_STARTED,
+ *                                         APS_ELEM_DELIMITED) and
+ */
+      __pyx_t_2 = (((__pyx_v_ptr[0]) == 34) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":700
+ * 
+ *             elif ptr[0] == '"':
+ *                 if (parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                         APS_ELEM_DELIMITED) and
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):
+ */
+        switch (__pyx_v_parse_state) {
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED:
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_DELIMITED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":701
+ *             elif ptr[0] == '"':
+ *                 if (parse_state not in (APS_STRIDE_STARTED,
+ *                                         APS_ELEM_DELIMITED) and             # <<<<<<<<<<<<<<
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+          __pyx_t_4 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":700
+ * 
+ *             elif ptr[0] == '"':
+ *                 if (parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                         APS_ELEM_DELIMITED) and
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):
+ */
+          break;
+          default:
+          __pyx_t_4 = 1;
+          break;
+        }
+        __pyx_t_5 = (__pyx_t_4 != 0);
+        if (__pyx_t_5) {
+        } else {
+          __pyx_t_2 = __pyx_t_5;
+          goto __pyx_L11_bool_binop_done;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":702
+ *                 if (parse_state not in (APS_STRIDE_STARTED,
+ *                                         APS_ELEM_DELIMITED) and
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):             # <<<<<<<<<<<<<<
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+        __pyx_t_4 = ((__pyx_v_parse_state == __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED) != 0);
+        if (__pyx_t_4) {
+        } else {
+          __pyx_t_5 = __pyx_t_4;
+          goto __pyx_L13_bool_binop_done;
+        }
+        __pyx_t_4 = (__pyx_v_in_quotes != 0);
+        __pyx_t_5 = __pyx_t_4;
+        __pyx_L13_bool_binop_done:;
+        __pyx_t_4 = ((!__pyx_t_5) != 0);
+        __pyx_t_2 = __pyx_t_4;
+        __pyx_L11_bool_binop_done:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":700
+ * 
+ *             elif ptr[0] == '"':
+ *                 if (parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                         APS_ELEM_DELIMITED) and
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):
+ */
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":703
+ *                                         APS_ELEM_DELIMITED) and
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 in_quotes = not in_quotes
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 703, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 703, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":700
+ * 
+ *             elif ptr[0] == '"':
+ *                 if (parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                         APS_ELEM_DELIMITED) and
+ *                         not (parse_state == APS_ELEM_STARTED and in_quotes)):
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":705
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 in_quotes = not in_quotes             # <<<<<<<<<<<<<<
+ *                 if in_quotes:
+ *                     parse_state = APS_ELEM_STARTED
+ */
+        __pyx_v_in_quotes = (!(__pyx_v_in_quotes != 0));
+
+        /* "asyncpg/protocol/codecs/array.pyx":706
+ * 
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:             # <<<<<<<<<<<<<<
+ *                     parse_state = APS_ELEM_STARTED
+ *                     array_is_empty = False
+ */
+        __pyx_t_2 = (__pyx_v_in_quotes != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":707
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:
+ *                     parse_state = APS_ELEM_STARTED             # <<<<<<<<<<<<<<
+ *                     array_is_empty = False
+ * 
+ */
+          __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED;
+
+          /* "asyncpg/protocol/codecs/array.pyx":708
+ *                 if in_quotes:
+ *                     parse_state = APS_ELEM_STARTED
+ *                     array_is_empty = False             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '\\':
+ */
+          __pyx_v_array_is_empty = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":706
+ * 
+ *                 in_quotes = not in_quotes
+ *                 if in_quotes:             # <<<<<<<<<<<<<<
+ *                     parse_state = APS_ELEM_STARTED
+ *                     array_is_empty = False
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":699
+ *                 raise ValueError('unexpected end of string')
+ * 
+ *             elif ptr[0] == '"':             # <<<<<<<<<<<<<<
+ *                 if (parse_state not in (APS_STRIDE_STARTED,
+ *                                         APS_ELEM_DELIMITED) and
+ */
+        goto __pyx_L9;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":710
+ *                     array_is_empty = False
+ * 
+ *             elif ptr[0] == '\\':             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_STRIDE_STARTED,
+ *                                        APS_ELEM_STARTED,
+ */
+      __pyx_t_2 = (((__pyx_v_ptr[0]) == 92) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":711
+ * 
+ *             elif ptr[0] == '\\':
+ *                 if parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ */
+        switch (__pyx_v_parse_state) {
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED:
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":712
+ *             elif ptr[0] == '\\':
+ *                 if parse_state not in (APS_STRIDE_STARTED,
+ *                                        APS_ELEM_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_DELIMITED):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_DELIMITED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":711
+ * 
+ *             elif ptr[0] == '\\':
+ *                 if parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ */
+          __pyx_t_2 = 0;
+          break;
+          default:
+          __pyx_t_2 = 1;
+          break;
+        }
+        __pyx_t_4 = (__pyx_t_2 != 0);
+        if (unlikely(__pyx_t_4)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":714
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 parse_state = APS_ELEM_STARTED
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 714, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 714, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":711
+ * 
+ *             elif ptr[0] == '\\':
+ *                 if parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":716
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 parse_state = APS_ELEM_STARTED             # <<<<<<<<<<<<<<
+ *                 array_is_empty = False
+ * 
+ */
+        __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED;
+
+        /* "asyncpg/protocol/codecs/array.pyx":717
+ * 
+ *                 parse_state = APS_ELEM_STARTED
+ *                 array_is_empty = False             # <<<<<<<<<<<<<<
+ * 
+ *                 if ptr[1] != '\0':
+ */
+        __pyx_v_array_is_empty = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":719
+ *                 array_is_empty = False
+ * 
+ *                 if ptr[1] != '\0':             # <<<<<<<<<<<<<<
+ *                     ptr += 1
+ *                 else:
+ */
+        __pyx_t_4 = (((__pyx_v_ptr[1]) != 0) != 0);
+        if (likely(__pyx_t_4)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":720
+ * 
+ *                 if ptr[1] != '\0':
+ *                     ptr += 1             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     raise ValueError('unexpected end of string')
+ */
+          __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+          /* "asyncpg/protocol/codecs/array.pyx":719
+ *                 array_is_empty = False
+ * 
+ *                 if ptr[1] != '\0':             # <<<<<<<<<<<<<<
+ *                     ptr += 1
+ *                 else:
+ */
+          goto __pyx_L17;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":722
+ *                     ptr += 1
+ *                 else:
+ *                     raise ValueError('unexpected end of string')             # <<<<<<<<<<<<<<
+ * 
+ *             elif in_quotes:
+ */
+        /*else*/ {
+          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 722, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 722, __pyx_L1_error)
+        }
+        __pyx_L17:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":710
+ *                     array_is_empty = False
+ * 
+ *             elif ptr[0] == '\\':             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_STRIDE_STARTED,
+ *                                        APS_ELEM_STARTED,
+ */
+        goto __pyx_L9;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":724
+ *                     raise ValueError('unexpected end of string')
+ * 
+ *             elif in_quotes:             # <<<<<<<<<<<<<<
+ *                 # Ignore everything inside the quotes.
+ *                 pass
+ */
+      __pyx_t_4 = (__pyx_v_in_quotes != 0);
+      if (__pyx_t_4) {
+        goto __pyx_L9;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":728
+ *                 pass
+ * 
+ *             elif ptr[0] == '{':             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_START,
+ *                                        APS_STRIDE_STARTED,
+ */
+      __pyx_t_4 = (((__pyx_v_ptr[0]) == 0x7B) != 0);
+      if (__pyx_t_4) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":729
+ * 
+ *             elif ptr[0] == '{':
+ *                 if parse_state not in (APS_START,             # <<<<<<<<<<<<<<
+ *                                        APS_STRIDE_STARTED,
+ *                                        APS_STRIDE_DELIMITED):
+ */
+        switch (__pyx_v_parse_state) {
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_START:
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":730
+ *             elif ptr[0] == '{':
+ *                 if parse_state not in (APS_START,
+ *                                        APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_STRIDE_DELIMITED):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DELIMITED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":729
+ * 
+ *             elif ptr[0] == '{':
+ *                 if parse_state not in (APS_START,             # <<<<<<<<<<<<<<
+ *                                        APS_STRIDE_STARTED,
+ *                                        APS_STRIDE_DELIMITED):
+ */
+          __pyx_t_4 = 0;
+          break;
+          default:
+          __pyx_t_4 = 1;
+          break;
+        }
+        __pyx_t_2 = (__pyx_t_4 != 0);
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":732
+ *                                        APS_STRIDE_STARTED,
+ *                                        APS_STRIDE_DELIMITED):
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 parse_state = APS_STRIDE_STARTED
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 732, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 732, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":729
+ * 
+ *             elif ptr[0] == '{':
+ *                 if parse_state not in (APS_START,             # <<<<<<<<<<<<<<
+ *                                        APS_STRIDE_STARTED,
+ *                                        APS_STRIDE_DELIMITED):
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":734
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 parse_state = APS_STRIDE_STARTED             # <<<<<<<<<<<<<<
+ *                 if nest_level >= ARRAY_MAXDIM:
+ *                     raise ValueError(
+ */
+        __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED;
+
+        /* "asyncpg/protocol/codecs/array.pyx":735
+ * 
+ *                 parse_state = APS_STRIDE_STARTED
+ *                 if nest_level >= ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'number of array dimensions ({}) exceed the '
+ */
+        __pyx_t_2 = ((__pyx_v_nest_level >= 6) != 0);
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":738
+ *                     raise ValueError(
+ *                         'number of array dimensions ({}) exceed the '
+ *                         'maximum expected ({})'.format(             # <<<<<<<<<<<<<<
+ *                             nest_level, ARRAY_MAXDIM))
+ * 
+ */
+          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_number_of_array_dimensions_excee, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 738, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_6);
+
+          /* "asyncpg/protocol/codecs/array.pyx":739
+ *                         'number of array dimensions ({}) exceed the '
+ *                         'maximum expected ({})'.format(
+ *                             nest_level, ARRAY_MAXDIM))             # <<<<<<<<<<<<<<
+ * 
+ *                 dims[nest_level] = 0
+ */
+          __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_nest_level); if (unlikely(!__pyx_t_7)) __PYX_ERR(4, 739, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_7);
+          __pyx_t_8 = NULL;
+          __pyx_t_1 = 0;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
+            if (likely(__pyx_t_8)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+              __Pyx_INCREF(__pyx_t_8);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_6, function);
+              __pyx_t_1 = 1;
+            }
+          }
+          #if CYTHON_FAST_PYCALL
+          if (PyFunction_Check(__pyx_t_6)) {
+            PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_int_6};
+            __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 738, __pyx_L1_error)
+            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+          } else
+          #endif
+          #if CYTHON_FAST_PYCCALL
+          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+            PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_int_6};
+            __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 738, __pyx_L1_error)
+            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+          } else
+          #endif
+          {
+            __pyx_t_9 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 738, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_9);
+            if (__pyx_t_8) {
+              __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
+            }
+            __Pyx_GIVEREF(__pyx_t_7);
+            PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_1, __pyx_t_7);
+            __Pyx_INCREF(__pyx_int_6);
+            __Pyx_GIVEREF(__pyx_int_6);
+            PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_1, __pyx_int_6);
+            __pyx_t_7 = 0;
+            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 738, __pyx_L1_error)
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          }
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":736
+ *                 parse_state = APS_STRIDE_STARTED
+ *                 if nest_level >= ARRAY_MAXDIM:
+ *                     raise ValueError(             # <<<<<<<<<<<<<<
+ *                         'number of array dimensions ({}) exceed the '
+ *                         'maximum expected ({})'.format(
+ */
+          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 736, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __PYX_ERR(4, 736, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":735
+ * 
+ *                 parse_state = APS_STRIDE_STARTED
+ *                 if nest_level >= ARRAY_MAXDIM:             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'number of array dimensions ({}) exceed the '
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":741
+ *                             nest_level, ARRAY_MAXDIM))
+ * 
+ *                 dims[nest_level] = 0             # <<<<<<<<<<<<<<
+ *                 nest_level += 1
+ *                 if ndims[0] < nest_level:
+ */
+        (__pyx_v_dims[__pyx_v_nest_level]) = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":742
+ * 
+ *                 dims[nest_level] = 0
+ *                 nest_level += 1             # <<<<<<<<<<<<<<
+ *                 if ndims[0] < nest_level:
+ *                     ndims[0] = nest_level
+ */
+        __pyx_v_nest_level = (__pyx_v_nest_level + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":743
+ *                 dims[nest_level] = 0
+ *                 nest_level += 1
+ *                 if ndims[0] < nest_level:             # <<<<<<<<<<<<<<
+ *                     ndims[0] = nest_level
+ * 
+ */
+        __pyx_t_2 = (((__pyx_v_ndims[0]) < __pyx_v_nest_level) != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":744
+ *                 nest_level += 1
+ *                 if ndims[0] < nest_level:
+ *                     ndims[0] = nest_level             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '}':
+ */
+          (__pyx_v_ndims[0]) = __pyx_v_nest_level;
+
+          /* "asyncpg/protocol/codecs/array.pyx":743
+ *                 dims[nest_level] = 0
+ *                 nest_level += 1
+ *                 if ndims[0] < nest_level:             # <<<<<<<<<<<<<<
+ *                     ndims[0] = nest_level
+ * 
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":728
+ *                 pass
+ * 
+ *             elif ptr[0] == '{':             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_START,
+ *                                        APS_STRIDE_STARTED,
+ */
+        goto __pyx_L9;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":746
+ *                     ndims[0] = nest_level
+ * 
+ *             elif ptr[0] == '}':             # <<<<<<<<<<<<<<
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and
+ *                         not (nest_level == 1 and
+ */
+      __pyx_t_2 = (((__pyx_v_ptr[0]) == 0x7D) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":747
+ * 
+ *             elif ptr[0] == '}':
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and             # <<<<<<<<<<<<<<
+ *                         not (nest_level == 1 and
+ *                              parse_state == APS_STRIDE_STARTED)):
+ */
+        switch (__pyx_v_parse_state) {
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED:
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DONE:
+          __pyx_t_4 = 0;
+          break;
+          default:
+          __pyx_t_4 = 1;
+          break;
+        }
+        __pyx_t_5 = (__pyx_t_4 != 0);
+        if (__pyx_t_5) {
+        } else {
+          __pyx_t_2 = __pyx_t_5;
+          goto __pyx_L22_bool_binop_done;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":748
+ *             elif ptr[0] == '}':
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and
+ *                         not (nest_level == 1 and             # <<<<<<<<<<<<<<
+ *                              parse_state == APS_STRIDE_STARTED)):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+        __pyx_t_4 = ((__pyx_v_nest_level == 1) != 0);
+        if (__pyx_t_4) {
+        } else {
+          __pyx_t_5 = __pyx_t_4;
+          goto __pyx_L24_bool_binop_done;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":749
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and
+ *                         not (nest_level == 1 and
+ *                              parse_state == APS_STRIDE_STARTED)):             # <<<<<<<<<<<<<<
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+        __pyx_t_4 = ((__pyx_v_parse_state == __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED) != 0);
+        __pyx_t_5 = __pyx_t_4;
+        __pyx_L24_bool_binop_done:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":748
+ *             elif ptr[0] == '}':
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and
+ *                         not (nest_level == 1 and             # <<<<<<<<<<<<<<
+ *                              parse_state == APS_STRIDE_STARTED)):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+        __pyx_t_4 = ((!__pyx_t_5) != 0);
+        __pyx_t_2 = __pyx_t_4;
+        __pyx_L22_bool_binop_done:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":747
+ * 
+ *             elif ptr[0] == '}':
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and             # <<<<<<<<<<<<<<
+ *                         not (nest_level == 1 and
+ *                              parse_state == APS_STRIDE_STARTED)):
+ */
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":750
+ *                         not (nest_level == 1 and
+ *                              parse_state == APS_STRIDE_STARTED)):
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 parse_state = APS_STRIDE_DONE
+ */
+          __pyx_t_6 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 750, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __PYX_ERR(4, 750, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":747
+ * 
+ *             elif ptr[0] == '}':
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and             # <<<<<<<<<<<<<<
+ *                         not (nest_level == 1 and
+ *                              parse_state == APS_STRIDE_STARTED)):
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":752
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 parse_state = APS_STRIDE_DONE             # <<<<<<<<<<<<<<
+ * 
+ *                 if nest_level == 0:
+ */
+        __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DONE;
+
+        /* "asyncpg/protocol/codecs/array.pyx":754
+ *                 parse_state = APS_STRIDE_DONE
+ * 
+ *                 if nest_level == 0:             # <<<<<<<<<<<<<<
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+        __pyx_t_2 = ((__pyx_v_nest_level == 0) != 0);
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":755
+ * 
+ *                 if nest_level == 0:
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 nest_level -= 1
+ */
+          __pyx_t_6 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 755, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __PYX_ERR(4, 755, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":754
+ *                 parse_state = APS_STRIDE_DONE
+ * 
+ *                 if nest_level == 0:             # <<<<<<<<<<<<<<
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":757
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 nest_level -= 1             # <<<<<<<<<<<<<<
+ * 
+ *                 if (prev_stride_len[nest_level] != 0 and
+ */
+        __pyx_v_nest_level = (__pyx_v_nest_level - 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":759
+ *                 nest_level -= 1
+ * 
+ *                 if (prev_stride_len[nest_level] != 0 and             # <<<<<<<<<<<<<<
+ *                         stride_len[nest_level] != prev_stride_len[nest_level]):
+ *                     raise ValueError(
+ */
+        __pyx_t_4 = (((__pyx_v_prev_stride_len[__pyx_v_nest_level]) != 0) != 0);
+        if (__pyx_t_4) {
+        } else {
+          __pyx_t_2 = __pyx_t_4;
+          goto __pyx_L28_bool_binop_done;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":760
+ * 
+ *                 if (prev_stride_len[nest_level] != 0 and
+ *                         stride_len[nest_level] != prev_stride_len[nest_level]):             # <<<<<<<<<<<<<<
+ *                     raise ValueError(
+ *                         'inconsistent sub-array dimensions'
+ */
+        __pyx_t_4 = (((__pyx_v_stride_len[__pyx_v_nest_level]) != (__pyx_v_prev_stride_len[__pyx_v_nest_level])) != 0);
+        __pyx_t_2 = __pyx_t_4;
+        __pyx_L28_bool_binop_done:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":759
+ *                 nest_level -= 1
+ * 
+ *                 if (prev_stride_len[nest_level] != 0 and             # <<<<<<<<<<<<<<
+ *                         stride_len[nest_level] != prev_stride_len[nest_level]):
+ *                     raise ValueError(
+ */
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":763
+ *                     raise ValueError(
+ *                         'inconsistent sub-array dimensions'
+ *                         ' at position {}'.format(             # <<<<<<<<<<<<<<
+ *                             ptr - array_text + 1))
+ * 
+ */
+          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_inconsistent_sub_array_dimension, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 763, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+
+          /* "asyncpg/protocol/codecs/array.pyx":764
+ *                         'inconsistent sub-array dimensions'
+ *                         ' at position {}'.format(
+ *                             ptr - array_text + 1))             # <<<<<<<<<<<<<<
+ * 
+ *                 prev_stride_len[nest_level] = stride_len[nest_level]
+ */
+          __pyx_t_9 = __Pyx_PyInt_From_ptrdiff_t(((__pyx_v_ptr - __pyx_v_array_text) + 1)); if (unlikely(!__pyx_t_9)) __PYX_ERR(4, 764, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __pyx_t_7 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
+            if (likely(__pyx_t_7)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+              __Pyx_INCREF(__pyx_t_7);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_3, function);
+            }
+          }
+          __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9);
+          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          if (unlikely(!__pyx_t_6)) __PYX_ERR(4, 763, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+          /* "asyncpg/protocol/codecs/array.pyx":761
+ *                 if (prev_stride_len[nest_level] != 0 and
+ *                         stride_len[nest_level] != prev_stride_len[nest_level]):
+ *                     raise ValueError(             # <<<<<<<<<<<<<<
+ *                         'inconsistent sub-array dimensions'
+ *                         ' at position {}'.format(
+ */
+          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 761, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 761, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":759
+ *                 nest_level -= 1
+ * 
+ *                 if (prev_stride_len[nest_level] != 0 and             # <<<<<<<<<<<<<<
+ *                         stride_len[nest_level] != prev_stride_len[nest_level]):
+ *                     raise ValueError(
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":766
+ *                             ptr - array_text + 1))
+ * 
+ *                 prev_stride_len[nest_level] = stride_len[nest_level]             # <<<<<<<<<<<<<<
+ *                 stride_len[nest_level] = 1
+ *                 if nest_level == 0:
+ */
+        (__pyx_v_prev_stride_len[__pyx_v_nest_level]) = (__pyx_v_stride_len[__pyx_v_nest_level]);
+
+        /* "asyncpg/protocol/codecs/array.pyx":767
+ * 
+ *                 prev_stride_len[nest_level] = stride_len[nest_level]
+ *                 stride_len[nest_level] = 1             # <<<<<<<<<<<<<<
+ *                 if nest_level == 0:
+ *                     end_of_array = end_of_item = True
+ */
+        (__pyx_v_stride_len[__pyx_v_nest_level]) = 1;
+
+        /* "asyncpg/protocol/codecs/array.pyx":768
+ *                 prev_stride_len[nest_level] = stride_len[nest_level]
+ *                 stride_len[nest_level] = 1
+ *                 if nest_level == 0:             # <<<<<<<<<<<<<<
+ *                     end_of_array = end_of_item = True
+ *                 else:
+ */
+        __pyx_t_2 = ((__pyx_v_nest_level == 0) != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":769
+ *                 stride_len[nest_level] = 1
+ *                 if nest_level == 0:
+ *                     end_of_array = end_of_item = True             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     dims[nest_level - 1] += 1
+ */
+          __pyx_v_end_of_array = 1;
+          __pyx_v_end_of_item = 1;
+
+          /* "asyncpg/protocol/codecs/array.pyx":768
+ *                 prev_stride_len[nest_level] = stride_len[nest_level]
+ *                 stride_len[nest_level] = 1
+ *                 if nest_level == 0:             # <<<<<<<<<<<<<<
+ *                     end_of_array = end_of_item = True
+ *                 else:
+ */
+          goto __pyx_L30;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":771
+ *                     end_of_array = end_of_item = True
+ *                 else:
+ *                     dims[nest_level - 1] += 1             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == typdelim:
+ */
+        /*else*/ {
+          __pyx_t_10 = (__pyx_v_nest_level - 1);
+          (__pyx_v_dims[__pyx_t_10]) = ((__pyx_v_dims[__pyx_t_10]) + 1);
+        }
+        __pyx_L30:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":746
+ *                     ndims[0] = nest_level
+ * 
+ *             elif ptr[0] == '}':             # <<<<<<<<<<<<<<
+ *                 if (parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE) and
+ *                         not (nest_level == 1 and
+ */
+        goto __pyx_L9;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":773
+ *                     dims[nest_level - 1] += 1
+ * 
+ *             elif ptr[0] == typdelim:             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+      __pyx_t_2 = (((__pyx_v_ptr[0]) == __pyx_v_typdelim) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":774
+ * 
+ *             elif ptr[0] == typdelim:
+ *                 if parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE):             # <<<<<<<<<<<<<<
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+        switch (__pyx_v_parse_state) {
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED:
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DONE:
+          __pyx_t_2 = 0;
+          break;
+          default:
+          __pyx_t_2 = 1;
+          break;
+        }
+        __pyx_t_4 = (__pyx_t_2 != 0);
+        if (unlikely(__pyx_t_4)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":775
+ *             elif ptr[0] == typdelim:
+ *                 if parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE):
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 if parse_state == APS_STRIDE_DONE:
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 775, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 775, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":774
+ * 
+ *             elif ptr[0] == typdelim:
+ *                 if parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE):             # <<<<<<<<<<<<<<
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":777
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 if parse_state == APS_STRIDE_DONE:             # <<<<<<<<<<<<<<
+ *                     parse_state = APS_STRIDE_DELIMITED
+ *                 else:
+ */
+        __pyx_t_4 = ((__pyx_v_parse_state == __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DONE) != 0);
+        if (__pyx_t_4) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":778
+ * 
+ *                 if parse_state == APS_STRIDE_DONE:
+ *                     parse_state = APS_STRIDE_DELIMITED             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     parse_state = APS_ELEM_DELIMITED
+ */
+          __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_DELIMITED;
+
+          /* "asyncpg/protocol/codecs/array.pyx":777
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 if parse_state == APS_STRIDE_DONE:             # <<<<<<<<<<<<<<
+ *                     parse_state = APS_STRIDE_DELIMITED
+ *                 else:
+ */
+          goto __pyx_L32;
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":780
+ *                     parse_state = APS_STRIDE_DELIMITED
+ *                 else:
+ *                     parse_state = APS_ELEM_DELIMITED             # <<<<<<<<<<<<<<
+ *                 end_of_item = True
+ *                 stride_len[nest_level - 1] += 1
+ */
+        /*else*/ {
+          __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_DELIMITED;
+        }
+        __pyx_L32:;
+
+        /* "asyncpg/protocol/codecs/array.pyx":781
+ *                 else:
+ *                     parse_state = APS_ELEM_DELIMITED
+ *                 end_of_item = True             # <<<<<<<<<<<<<<
+ *                 stride_len[nest_level - 1] += 1
+ * 
+ */
+        __pyx_v_end_of_item = 1;
+
+        /* "asyncpg/protocol/codecs/array.pyx":782
+ *                     parse_state = APS_ELEM_DELIMITED
+ *                 end_of_item = True
+ *                 stride_len[nest_level - 1] += 1             # <<<<<<<<<<<<<<
+ * 
+ *             elif not apg_ascii_isspace(ptr[0]):
+ */
+        __pyx_t_10 = (__pyx_v_nest_level - 1);
+        (__pyx_v_stride_len[__pyx_t_10]) = ((__pyx_v_stride_len[__pyx_t_10]) + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":773
+ *                     dims[nest_level - 1] += 1
+ * 
+ *             elif ptr[0] == typdelim:             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_ELEM_STARTED, APS_STRIDE_DONE):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+        goto __pyx_L9;
+      }
+
+      /* "asyncpg/protocol/codecs/array.pyx":784
+ *                 stride_len[nest_level - 1] += 1
+ * 
+ *             elif not apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_STRIDE_STARTED,
+ *                                        APS_ELEM_STARTED,
+ */
+      __pyx_t_4 = ((!(__pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace((__pyx_v_ptr[0])) != 0)) != 0);
+      if (__pyx_t_4) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":785
+ * 
+ *             elif not apg_ascii_isspace(ptr[0]):
+ *                 if parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ */
+        switch (__pyx_v_parse_state) {
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_STRIDE_STARTED:
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":786
+ *             elif not apg_ascii_isspace(ptr[0]):
+ *                 if parse_state not in (APS_STRIDE_STARTED,
+ *                                        APS_ELEM_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_DELIMITED):
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ */
+          case __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_DELIMITED:
+
+          /* "asyncpg/protocol/codecs/array.pyx":785
+ * 
+ *             elif not apg_ascii_isspace(ptr[0]):
+ *                 if parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ */
+          __pyx_t_4 = 0;
+          break;
+          default:
+          __pyx_t_4 = 1;
+          break;
+        }
+        __pyx_t_2 = (__pyx_t_4 != 0);
+        if (unlikely(__pyx_t_2)) {
+
+          /* "asyncpg/protocol/codecs/array.pyx":788
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ *                     raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *                 parse_state = APS_ELEM_STARTED
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 788, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __PYX_ERR(4, 788, __pyx_L1_error)
+
+          /* "asyncpg/protocol/codecs/array.pyx":785
+ * 
+ *             elif not apg_ascii_isspace(ptr[0]):
+ *                 if parse_state not in (APS_STRIDE_STARTED,             # <<<<<<<<<<<<<<
+ *                                        APS_ELEM_STARTED,
+ *                                        APS_ELEM_DELIMITED):
+ */
+        }
+
+        /* "asyncpg/protocol/codecs/array.pyx":790
+ *                     raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *                 parse_state = APS_ELEM_STARTED             # <<<<<<<<<<<<<<
+ *                 array_is_empty = False
+ * 
+ */
+        __pyx_v_parse_state = __pyx_e_7asyncpg_8protocol_8protocol_APS_ELEM_STARTED;
+
+        /* "asyncpg/protocol/codecs/array.pyx":791
+ * 
+ *                 parse_state = APS_ELEM_STARTED
+ *                 array_is_empty = False             # <<<<<<<<<<<<<<
+ * 
+ *             if not end_of_item:
+ */
+        __pyx_v_array_is_empty = 0;
+
+        /* "asyncpg/protocol/codecs/array.pyx":784
+ *                 stride_len[nest_level - 1] += 1
+ * 
+ *             elif not apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *                 if parse_state not in (APS_STRIDE_STARTED,
+ *                                        APS_ELEM_STARTED,
+ */
+      }
+      __pyx_L9:;
+
+      /* "asyncpg/protocol/codecs/array.pyx":793
+ *                 array_is_empty = False
+ * 
+ *             if not end_of_item:             # <<<<<<<<<<<<<<
+ *                 ptr += 1
+ * 
+ */
+      __pyx_t_2 = ((!(__pyx_v_end_of_item != 0)) != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/codecs/array.pyx":794
+ * 
+ *             if not end_of_item:
+ *                 ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *         if not array_is_empty:
+ */
+        __pyx_v_ptr = (__pyx_v_ptr + 1);
+
+        /* "asyncpg/protocol/codecs/array.pyx":793
+ *                 array_is_empty = False
+ * 
+ *             if not end_of_item:             # <<<<<<<<<<<<<<
+ *                 ptr += 1
+ * 
+ */
+      }
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":796
+ *                 ptr += 1
+ * 
+ *         if not array_is_empty:             # <<<<<<<<<<<<<<
+ *             dims[ndims[0] - 1] += 1
+ * 
+ */
+    __pyx_t_2 = ((!(__pyx_v_array_is_empty != 0)) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":797
+ * 
+ *         if not array_is_empty:
+ *             dims[ndims[0] - 1] += 1             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1
+ */
+      __pyx_t_10 = ((__pyx_v_ndims[0]) - 1);
+      (__pyx_v_dims[__pyx_t_10]) = ((__pyx_v_dims[__pyx_t_10]) + 1);
+
+      /* "asyncpg/protocol/codecs/array.pyx":796
+ *                 ptr += 1
+ * 
+ *         if not array_is_empty:             # <<<<<<<<<<<<<<
+ *             dims[ndims[0] - 1] += 1
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":799
+ *             dims[ndims[0] - 1] += 1
+ * 
+ *         ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *     # only whitespace is allowed after the closing brace
+ */
+    __pyx_v_ptr = (__pyx_v_ptr + 1);
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":802
+ * 
+ *     # only whitespace is allowed after the closing brace
+ *     while ptr[0] != '\0':             # <<<<<<<<<<<<<<
+ *         if not apg_ascii_isspace(ptr[0]):
+ *             raise _UnexpectedCharacter(array_text, ptr)
+ */
+  while (1) {
+    __pyx_t_2 = (((__pyx_v_ptr[0]) != 0) != 0);
+    if (!__pyx_t_2) break;
+
+    /* "asyncpg/protocol/codecs/array.pyx":803
+ *     # only whitespace is allowed after the closing brace
+ *     while ptr[0] != '\0':
+ *         if not apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *             raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+    __pyx_t_2 = ((!(__pyx_f_7asyncpg_8protocol_8protocol_apg_ascii_isspace((__pyx_v_ptr[0])) != 0)) != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/codecs/array.pyx":804
+ *     while ptr[0] != '\0':
+ *         if not apg_ascii_isspace(ptr[0]):
+ *             raise _UnexpectedCharacter(array_text, ptr)             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1
+ */
+      __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol__UnexpectedCharacter(__pyx_v_array_text, __pyx_v_ptr); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 804, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(4, 804, __pyx_L1_error)
+
+      /* "asyncpg/protocol/codecs/array.pyx":803
+ *     # only whitespace is allowed after the closing brace
+ *     while ptr[0] != '\0':
+ *         if not apg_ascii_isspace(ptr[0]):             # <<<<<<<<<<<<<<
+ *             raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/codecs/array.pyx":806
+ *             raise _UnexpectedCharacter(array_text, ptr)
+ * 
+ *         ptr += 1             # <<<<<<<<<<<<<<
+ * 
+ *     if array_is_empty:
+ */
+    __pyx_v_ptr = (__pyx_v_ptr + 1);
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":808
+ *         ptr += 1
+ * 
+ *     if array_is_empty:             # <<<<<<<<<<<<<<
+ *         ndims[0] = 0
+ * 
+ */
+  __pyx_t_2 = (__pyx_v_array_is_empty != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/array.pyx":809
+ * 
+ *     if array_is_empty:
+ *         ndims[0] = 0             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+    (__pyx_v_ndims[0]) = 0;
+
+    /* "asyncpg/protocol/codecs/array.pyx":808
+ *         ptr += 1
+ * 
+ *     if array_is_empty:             # <<<<<<<<<<<<<<
+ *         ndims[0] = 0
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/array.pyx":672
+ * 
+ * 
+ * cdef _infer_array_dims(const Py_UCS4 *array_text,             # <<<<<<<<<<<<<<
+ *                        Py_UCS4 typdelim,
+ *                        int32_t *dims,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._infer_array_dims", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":812
+ * 
+ * 
+ * cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,             # <<<<<<<<<<<<<<
+ *                      const void *arg):
+ *     return pgproto.uint4_encode(settings, buf, obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_uint4_encode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj, CYTHON_UNUSED void const *__pyx_v_arg) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("uint4_encode_ex", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":814
+ * cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,
+ *                      const void *arg):
+ *     return pgproto.uint4_encode(settings, buf, obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_uint4_encode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf, __pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 814, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":812
+ * 
+ * 
+ * cdef uint4_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,             # <<<<<<<<<<<<<<
+ *                      const void *arg):
+ *     return pgproto.uint4_encode(settings, buf, obj)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.uint4_encode_ex", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":817
+ * 
+ * 
+ * cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                      const void *arg):
+ *     return pgproto.uint4_decode(settings, buf)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_uint4_decode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, CYTHON_UNUSED void const *__pyx_v_arg) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("uint4_decode_ex", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":819
+ * cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf,
+ *                      const void *arg):
+ *     return pgproto.uint4_decode(settings, buf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_uint4_decode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 819, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":817
+ * 
+ * 
+ * cdef uint4_decode_ex(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                      const void *arg):
+ *     return pgproto.uint4_decode(settings, buf)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.uint4_decode_ex", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":822
+ * 
+ * 
+ * cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items):             # <<<<<<<<<<<<<<
+ *     array_encode(settings, buf, items, OIDOID,
+ *                  <encode_func_ex>&uint4_encode_ex, NULL)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arrayoid_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_items) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("arrayoid_encode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":823
+ * 
+ * cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items):
+ *     array_encode(settings, buf, items, OIDOID,             # <<<<<<<<<<<<<<
+ *                  <encode_func_ex>&uint4_encode_ex, NULL)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_array_encode(__pyx_v_settings, __pyx_v_buf, __pyx_v_items, 26, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex)(&__pyx_f_7asyncpg_8protocol_8protocol_uint4_encode_ex)), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 823, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":822
+ * 
+ * 
+ * cdef arrayoid_encode(ConnectionSettings settings, WriteBuffer buf, items):             # <<<<<<<<<<<<<<
+ *     array_encode(settings, buf, items, OIDOID,
+ *                  <encode_func_ex>&uint4_encode_ex, NULL)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.arrayoid_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":827
+ * 
+ * 
+ * cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return array_decode(settings, buf, <decode_func_ex>&uint4_decode_ex, NULL)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arrayoid_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("arrayoid_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":828
+ * 
+ * cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf):
+ *     return array_decode(settings, buf, <decode_func_ex>&uint4_decode_ex, NULL)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_array_decode(__pyx_v_settings, __pyx_v_buf, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex)(&__pyx_f_7asyncpg_8protocol_8protocol_uint4_decode_ex)), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 828, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":827
+ * 
+ * 
+ * cdef arrayoid_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return array_decode(settings, buf, <decode_func_ex>&uint4_decode_ex, NULL)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.arrayoid_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":831
+ * 
+ * 
+ * cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,             # <<<<<<<<<<<<<<
+ *                     const void *arg):
+ *     return pgproto.text_encode(settings, buf, obj)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_text_encode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj, CYTHON_UNUSED void const *__pyx_v_arg) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("text_encode_ex", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":833
+ * cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,
+ *                     const void *arg):
+ *     return pgproto.text_encode(settings, buf, obj)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_encode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf, __pyx_v_obj); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 833, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":831
+ * 
+ * 
+ * cdef text_encode_ex(ConnectionSettings settings, WriteBuffer buf, object obj,             # <<<<<<<<<<<<<<
+ *                     const void *arg):
+ *     return pgproto.text_encode(settings, buf, obj)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.text_encode_ex", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":836
+ * 
+ * 
+ * cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                     const void *arg):
+ *     return pgproto.text_decode(settings, buf)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_text_decode_ex(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, CYTHON_UNUSED void const *__pyx_v_arg) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("text_decode_ex", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":838
+ * cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf,
+ *                     const void *arg):
+ *     return pgproto.text_decode(settings, buf)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_text_decode(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *)__pyx_v_settings), __pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 838, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":836
+ * 
+ * 
+ * cdef text_decode_ex(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                     const void *arg):
+ *     return pgproto.text_decode(settings, buf)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.text_decode_ex", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":841
+ * 
+ * 
+ * cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items):             # <<<<<<<<<<<<<<
+ *     array_encode(settings, buf, items, TEXTOID,
+ *                  <encode_func_ex>&text_encode_ex, NULL)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arraytext_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_items) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("arraytext_encode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":842
+ * 
+ * cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items):
+ *     array_encode(settings, buf, items, TEXTOID,             # <<<<<<<<<<<<<<
+ *                  <encode_func_ex>&text_encode_ex, NULL)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_array_encode(__pyx_v_settings, __pyx_v_buf, __pyx_v_items, 25, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex)(&__pyx_f_7asyncpg_8protocol_8protocol_text_encode_ex)), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 842, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":841
+ * 
+ * 
+ * cdef arraytext_encode(ConnectionSettings settings, WriteBuffer buf, items):             # <<<<<<<<<<<<<<
+ *     array_encode(settings, buf, items, TEXTOID,
+ *                  <encode_func_ex>&text_encode_ex, NULL)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.arraytext_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":846
+ * 
+ * 
+ * cdef arraytext_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return array_decode(settings, buf, <decode_func_ex>&text_decode_ex, NULL)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_arraytext_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("arraytext_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":847
+ * 
+ * cdef arraytext_decode(ConnectionSettings settings, FRBuffer *buf):
+ *     return array_decode(settings, buf, <decode_func_ex>&text_decode_ex, NULL)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_array_decode(__pyx_v_settings, __pyx_v_buf, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex)(&__pyx_f_7asyncpg_8protocol_8protocol_text_decode_ex)), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 847, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":846
+ * 
+ * 
+ * cdef arraytext_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     return array_decode(settings, buf, <decode_func_ex>&text_decode_ex, NULL)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.arraytext_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":850
+ * 
+ * 
+ * cdef anyarray_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     # Instances of anyarray (or any other polymorphic pseudotype) are
+ *     # never supposed to be returned from actual queries.
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_anyarray_decode(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, CYTHON_UNUSED struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("anyarray_decode", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":853
+ *     # Instances of anyarray (or any other polymorphic pseudotype) are
+ *     # never supposed to be returned from actual queries.
+ *     raise exceptions.ProtocolError(             # <<<<<<<<<<<<<<
+ *         'unexpected instance of \'anyarray\' type')
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 853, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_3)) __PYX_ERR(4, 853, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_unexpected_instance_of_anyarray) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_unexpected_instance_of_anyarray);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 853, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(4, 853, __pyx_L1_error)
+
+  /* "asyncpg/protocol/codecs/array.pyx":850
+ * 
+ * 
+ * cdef anyarray_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     # Instances of anyarray (or any other polymorphic pseudotype) are
+ *     # never supposed to be returned from actual queries.
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.anyarray_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/array.pyx":857
+ * 
+ * 
+ * cdef init_array_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(ANYARRAYOID,
+ *                         NULL,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_array_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_array_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/array.pyx":858
+ * 
+ * cdef init_array_codecs():
+ *     register_core_codec(ANYARRAYOID,             # <<<<<<<<<<<<<<
+ *                         NULL,
+ *                         <decode_func>&anyarray_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x8E5, NULL, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_anyarray_decode)), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 858, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":866
+ *     # to make type introspection query work
+ *     #
+ *     register_core_codec(_OIDOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>&arrayoid_encode,
+ *                         <decode_func>&arrayoid_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x404, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_arrayoid_encode)), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_arrayoid_decode)), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 866, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":871
+ *                         PG_FORMAT_BINARY)
+ * 
+ *     register_core_codec(_TEXTOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>&arraytext_encode,
+ *                         <decode_func>&arraytext_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x3F1, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_arraytext_encode)), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)(&__pyx_f_7asyncpg_8protocol_8protocol_arraytext_decode)), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 871, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":857
+ * 
+ * 
+ * cdef init_array_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(ANYARRAYOID,
+ *                         NULL,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_array_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/range.pyx":24
+ * 
+ * 
+ * cdef inline bint _range_has_lbound(uint8_t flags):             # <<<<<<<<<<<<<<
+ *     return not (flags & (RANGE_EMPTY | RANGE_LB_INF))
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol__range_has_lbound(uint8_t __pyx_v_flags) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_range_has_lbound", 0);
+
+  /* "asyncpg/protocol/codecs/range.pyx":25
+ * 
+ * cdef inline bint _range_has_lbound(uint8_t flags):
+ *     return not (flags & (RANGE_EMPTY | RANGE_LB_INF))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_r = (!((__pyx_v_flags & 9) != 0));
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":24
+ * 
+ * 
+ * cdef inline bint _range_has_lbound(uint8_t flags):             # <<<<<<<<<<<<<<
+ *     return not (flags & (RANGE_EMPTY | RANGE_LB_INF))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/range.pyx":28
+ * 
+ * 
+ * cdef inline bint _range_has_ubound(uint8_t flags):             # <<<<<<<<<<<<<<
+ *     return not (flags & (RANGE_EMPTY | RANGE_UB_INF))
+ * 
+ */
+
+static CYTHON_INLINE int __pyx_f_7asyncpg_8protocol_8protocol__range_has_ubound(uint8_t __pyx_v_flags) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_range_has_ubound", 0);
+
+  /* "asyncpg/protocol/codecs/range.pyx":29
+ * 
+ * cdef inline bint _range_has_ubound(uint8_t flags):
+ *     return not (flags & (RANGE_EMPTY | RANGE_UB_INF))             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_r = (!((__pyx_v_flags & 17) != 0));
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":28
+ * 
+ * 
+ * cdef inline bint _range_has_ubound(uint8_t flags):             # <<<<<<<<<<<<<<
+ *     return not (flags & (RANGE_EMPTY | RANGE_UB_INF))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/range.pyx":32
+ * 
+ * 
+ * cdef inline _RangeArgumentType _range_type(object obj):             # <<<<<<<<<<<<<<
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):
+ *         return _RANGE_ARGUMENT_TUPLE
+ */
+
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol__RangeArgumentType __pyx_f_7asyncpg_8protocol_8protocol__range_type(PyObject *__pyx_v_obj) {
+  enum __pyx_t_7asyncpg_8protocol_8protocol__RangeArgumentType __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_range_type", 0);
+
+  /* "asyncpg/protocol/codecs/range.pyx":33
+ * 
+ * cdef inline _RangeArgumentType _range_type(object obj):
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):             # <<<<<<<<<<<<<<
+ *         return _RANGE_ARGUMENT_TUPLE
+ *     elif isinstance(obj, apg_types.Range):
+ */
+  __pyx_t_2 = (PyTuple_Check(__pyx_v_obj) != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = (PyList_Check(__pyx_v_obj) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/codecs/range.pyx":34
+ * cdef inline _RangeArgumentType _range_type(object obj):
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):
+ *         return _RANGE_ARGUMENT_TUPLE             # <<<<<<<<<<<<<<
+ *     elif isinstance(obj, apg_types.Range):
+ *         return _RANGE_ARGUMENT_RANGE
+ */
+    __pyx_r = __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_TUPLE;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/range.pyx":33
+ * 
+ * cdef inline _RangeArgumentType _range_type(object obj):
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):             # <<<<<<<<<<<<<<
+ *         return _RANGE_ARGUMENT_TUPLE
+ *     elif isinstance(obj, apg_types.Range):
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":35
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):
+ *         return _RANGE_ARGUMENT_TUPLE
+ *     elif isinstance(obj, apg_types.Range):             # <<<<<<<<<<<<<<
+ *         return _RANGE_ARGUMENT_RANGE
+ *     else:
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(9, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Range); if (unlikely(!__pyx_t_4)) __PYX_ERR(9, 35, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_1 = PyObject_IsInstance(__pyx_v_obj, __pyx_t_4); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(9, 35, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/range.pyx":36
+ *         return _RANGE_ARGUMENT_TUPLE
+ *     elif isinstance(obj, apg_types.Range):
+ *         return _RANGE_ARGUMENT_RANGE             # <<<<<<<<<<<<<<
+ *     else:
+ *         return _RANGE_ARGUMENT_INVALID
+ */
+    __pyx_r = __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_RANGE;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/codecs/range.pyx":35
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):
+ *         return _RANGE_ARGUMENT_TUPLE
+ *     elif isinstance(obj, apg_types.Range):             # <<<<<<<<<<<<<<
+ *         return _RANGE_ARGUMENT_RANGE
+ *     else:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":38
+ *         return _RANGE_ARGUMENT_RANGE
+ *     else:
+ *         return _RANGE_ARGUMENT_INVALID             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  /*else*/ {
+    __pyx_r = __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_INVALID;
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":32
+ * 
+ * 
+ * cdef inline _RangeArgumentType _range_type(object obj):             # <<<<<<<<<<<<<<
+ *     if cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj):
+ *         return _RANGE_ARGUMENT_TUPLE
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_WriteUnraisable("asyncpg.protocol.protocol._range_type", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
+  __pyx_r = (enum __pyx_t_7asyncpg_8protocol_8protocol__RangeArgumentType) 0;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/range.pyx":41
+ * 
+ * 
+ * cdef range_encode(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                   object obj, uint32_t elem_oid,
+ *                   encode_func_ex encoder, const void *encoder_arg):
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_range_encode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, PyObject *__pyx_v_obj, CYTHON_UNUSED uint32_t __pyx_v_elem_oid, __pyx_t_7asyncpg_8protocol_8protocol_encode_func_ex __pyx_v_encoder, void const *__pyx_v_encoder_arg) {
+  Py_ssize_t __pyx_v_obj_len;
+  uint8_t __pyx_v_flags;
+  PyObject *__pyx_v_lower = 0;
+  PyObject *__pyx_v_upper = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bounds_data = 0;
+  enum __pyx_t_7asyncpg_8protocol_8protocol__RangeArgumentType __pyx_v_arg_type;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  Py_ssize_t __pyx_t_4;
+  int __pyx_t_5;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  int32_t __pyx_t_8;
+  __Pyx_RefNannySetupContext("range_encode", 0);
+
+  /* "asyncpg/protocol/codecs/range.pyx":46
+ *     cdef:
+ *         ssize_t obj_len
+ *         uint8_t flags = 0             # <<<<<<<<<<<<<<
+ *         object lower = None
+ *         object upper = None
+ */
+  __pyx_v_flags = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":47
+ *         ssize_t obj_len
+ *         uint8_t flags = 0
+ *         object lower = None             # <<<<<<<<<<<<<<
+ *         object upper = None
+ *         WriteBuffer bounds_data = WriteBuffer.new()
+ */
+  __Pyx_INCREF(Py_None);
+  __pyx_v_lower = Py_None;
+
+  /* "asyncpg/protocol/codecs/range.pyx":48
+ *         uint8_t flags = 0
+ *         object lower = None
+ *         object upper = None             # <<<<<<<<<<<<<<
+ *         WriteBuffer bounds_data = WriteBuffer.new()
+ *         _RangeArgumentType arg_type = _range_type(obj)
+ */
+  __Pyx_INCREF(Py_None);
+  __pyx_v_upper = Py_None;
+
+  /* "asyncpg/protocol/codecs/range.pyx":49
+ *         object lower = None
+ *         object upper = None
+ *         WriteBuffer bounds_data = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ *         _RangeArgumentType arg_type = _range_type(obj)
+ * 
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 49, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_bounds_data = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":50
+ *         object upper = None
+ *         WriteBuffer bounds_data = WriteBuffer.new()
+ *         _RangeArgumentType arg_type = _range_type(obj)             # <<<<<<<<<<<<<<
+ * 
+ *     if arg_type == _RANGE_ARGUMENT_INVALID:
+ */
+  __pyx_v_arg_type = __pyx_f_7asyncpg_8protocol_8protocol__range_type(__pyx_v_obj);
+
+  /* "asyncpg/protocol/codecs/range.pyx":52
+ *         _RangeArgumentType arg_type = _range_type(obj)
+ * 
+ *     if arg_type == _RANGE_ARGUMENT_INVALID:             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'list, tuple or Range object expected (got type {})'.format(
+ */
+  switch (__pyx_v_arg_type) {
+    case __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_INVALID:
+
+    /* "asyncpg/protocol/codecs/range.pyx":54
+ *     if arg_type == _RANGE_ARGUMENT_INVALID:
+ *         raise TypeError(
+ *             'list, tuple or Range object expected (got type {})'.format(             # <<<<<<<<<<<<<<
+ *                 type(obj)))
+ * 
+ */
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_list_tuple_or_Range_object_expec, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 54, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+
+    /* "asyncpg/protocol/codecs/range.pyx":55
+ *         raise TypeError(
+ *             'list, tuple or Range object expected (got type {})'.format(
+ *                 type(obj)))             # <<<<<<<<<<<<<<
+ * 
+ *     elif arg_type == _RANGE_ARGUMENT_TUPLE:
+ */
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, ((PyObject *)Py_TYPE(__pyx_v_obj))) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)Py_TYPE(__pyx_v_obj)));
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 54, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/codecs/range.pyx":53
+ * 
+ *     if arg_type == _RANGE_ARGUMENT_INVALID:
+ *         raise TypeError(             # <<<<<<<<<<<<<<
+ *             'list, tuple or Range object expected (got type {})'.format(
+ *                 type(obj)))
+ */
+    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 53, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(9, 53, __pyx_L1_error)
+
+    /* "asyncpg/protocol/codecs/range.pyx":52
+ *         _RangeArgumentType arg_type = _range_type(obj)
+ * 
+ *     if arg_type == _RANGE_ARGUMENT_INVALID:             # <<<<<<<<<<<<<<
+ *         raise TypeError(
+ *             'list, tuple or Range object expected (got type {})'.format(
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol__RANGE_ARGUMENT_TUPLE:
+
+    /* "asyncpg/protocol/codecs/range.pyx":58
+ * 
+ *     elif arg_type == _RANGE_ARGUMENT_TUPLE:
+ *         obj_len = len(obj)             # <<<<<<<<<<<<<<
+ *         if obj_len == 2:
+ *             lower = obj[0]
+ */
+    __pyx_t_4 = PyObject_Length(__pyx_v_obj); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(9, 58, __pyx_L1_error)
+    __pyx_v_obj_len = __pyx_t_4;
+
+    /* "asyncpg/protocol/codecs/range.pyx":59
+ *     elif arg_type == _RANGE_ARGUMENT_TUPLE:
+ *         obj_len = len(obj)
+ *         if obj_len == 2:             # <<<<<<<<<<<<<<
+ *             lower = obj[0]
+ *             upper = obj[1]
+ */
+    switch (__pyx_v_obj_len) {
+      case 2:
+
+      /* "asyncpg/protocol/codecs/range.pyx":60
+ *         obj_len = len(obj)
+ *         if obj_len == 2:
+ *             lower = obj[0]             # <<<<<<<<<<<<<<
+ *             upper = obj[1]
+ * 
+ */
+      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 60, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF_SET(__pyx_v_lower, __pyx_t_2);
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/range.pyx":61
+ *         if obj_len == 2:
+ *             lower = obj[0]
+ *             upper = obj[1]             # <<<<<<<<<<<<<<
+ * 
+ *             if lower is None:
+ */
+      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_obj, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 61, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF_SET(__pyx_v_upper, __pyx_t_2);
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/range.pyx":63
+ *             upper = obj[1]
+ * 
+ *             if lower is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_LB_INF
+ * 
+ */
+      __pyx_t_5 = (__pyx_v_lower == Py_None);
+      __pyx_t_6 = (__pyx_t_5 != 0);
+      if (__pyx_t_6) {
+
+        /* "asyncpg/protocol/codecs/range.pyx":64
+ * 
+ *             if lower is None:
+ *                 flags |= RANGE_LB_INF             # <<<<<<<<<<<<<<
+ * 
+ *             if upper is None:
+ */
+        __pyx_v_flags = (__pyx_v_flags | 8);
+
+        /* "asyncpg/protocol/codecs/range.pyx":63
+ *             upper = obj[1]
+ * 
+ *             if lower is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_LB_INF
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/range.pyx":66
+ *                 flags |= RANGE_LB_INF
+ * 
+ *             if upper is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_UB_INF
+ * 
+ */
+      __pyx_t_6 = (__pyx_v_upper == Py_None);
+      __pyx_t_5 = (__pyx_t_6 != 0);
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/range.pyx":67
+ * 
+ *             if upper is None:
+ *                 flags |= RANGE_UB_INF             # <<<<<<<<<<<<<<
+ * 
+ *             flags |= RANGE_LB_INC | RANGE_UB_INC
+ */
+        __pyx_v_flags = (__pyx_v_flags | 16);
+
+        /* "asyncpg/protocol/codecs/range.pyx":66
+ *                 flags |= RANGE_LB_INF
+ * 
+ *             if upper is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_UB_INF
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/range.pyx":69
+ *                 flags |= RANGE_UB_INF
+ * 
+ *             flags |= RANGE_LB_INC | RANGE_UB_INC             # <<<<<<<<<<<<<<
+ * 
+ *         elif obj_len == 1:
+ */
+      __pyx_v_flags = (__pyx_v_flags | 6);
+
+      /* "asyncpg/protocol/codecs/range.pyx":59
+ *     elif arg_type == _RANGE_ARGUMENT_TUPLE:
+ *         obj_len = len(obj)
+ *         if obj_len == 2:             # <<<<<<<<<<<<<<
+ *             lower = obj[0]
+ *             upper = obj[1]
+ */
+      break;
+      case 1:
+
+      /* "asyncpg/protocol/codecs/range.pyx":72
+ * 
+ *         elif obj_len == 1:
+ *             lower = obj[0]             # <<<<<<<<<<<<<<
+ *             flags |= RANGE_LB_INC | RANGE_UB_INF
+ * 
+ */
+      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_obj, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 72, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF_SET(__pyx_v_lower, __pyx_t_2);
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/range.pyx":73
+ *         elif obj_len == 1:
+ *             lower = obj[0]
+ *             flags |= RANGE_LB_INC | RANGE_UB_INF             # <<<<<<<<<<<<<<
+ * 
+ *         elif obj_len == 0:
+ */
+      __pyx_v_flags = (__pyx_v_flags | 18);
+
+      /* "asyncpg/protocol/codecs/range.pyx":71
+ *             flags |= RANGE_LB_INC | RANGE_UB_INC
+ * 
+ *         elif obj_len == 1:             # <<<<<<<<<<<<<<
+ *             lower = obj[0]
+ *             flags |= RANGE_LB_INC | RANGE_UB_INF
+ */
+      break;
+      case 0:
+
+      /* "asyncpg/protocol/codecs/range.pyx":76
+ * 
+ *         elif obj_len == 0:
+ *             flags |= RANGE_EMPTY             # <<<<<<<<<<<<<<
+ * 
+ *         else:
+ */
+      __pyx_v_flags = (__pyx_v_flags | 1);
+
+      /* "asyncpg/protocol/codecs/range.pyx":75
+ *             flags |= RANGE_LB_INC | RANGE_UB_INF
+ * 
+ *         elif obj_len == 0:             # <<<<<<<<<<<<<<
+ *             flags |= RANGE_EMPTY
+ * 
+ */
+      break;
+      default:
+
+      /* "asyncpg/protocol/codecs/range.pyx":80
+ *         else:
+ *             raise ValueError(
+ *                 'expected 0, 1 or 2 elements in range (got {})'.format(             # <<<<<<<<<<<<<<
+ *                     obj_len))
+ * 
+ */
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_expected_0_1_or_2_elements_in_ra, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 80, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+
+      /* "asyncpg/protocol/codecs/range.pyx":81
+ *             raise ValueError(
+ *                 'expected 0, 1 or 2 elements in range (got {})'.format(
+ *                     obj_len))             # <<<<<<<<<<<<<<
+ * 
+ *     else:
+ */
+      __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_obj_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(9, 81, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_7 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
+        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
+        if (likely(__pyx_t_7)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
+          __Pyx_INCREF(__pyx_t_7);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_1, function);
+        }
+      }
+      __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3);
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 80, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/range.pyx":79
+ * 
+ *         else:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                 'expected 0, 1 or 2 elements in range (got {})'.format(
+ *                     obj_len))
+ */
+      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 79, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(9, 79, __pyx_L1_error)
+      break;
+    }
+
+    /* "asyncpg/protocol/codecs/range.pyx":57
+ *                 type(obj)))
+ * 
+ *     elif arg_type == _RANGE_ARGUMENT_TUPLE:             # <<<<<<<<<<<<<<
+ *         obj_len = len(obj)
+ *         if obj_len == 2:
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/codecs/range.pyx":84
+ * 
+ *     else:
+ *         if obj.isempty:             # <<<<<<<<<<<<<<
+ *             flags |= RANGE_EMPTY
+ *         else:
+ */
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_isempty); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 84, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(9, 84, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    if (__pyx_t_5) {
+
+      /* "asyncpg/protocol/codecs/range.pyx":85
+ *     else:
+ *         if obj.isempty:
+ *             flags |= RANGE_EMPTY             # <<<<<<<<<<<<<<
+ *         else:
+ *             lower = obj.lower
+ */
+      __pyx_v_flags = (__pyx_v_flags | 1);
+
+      /* "asyncpg/protocol/codecs/range.pyx":84
+ * 
+ *     else:
+ *         if obj.isempty:             # <<<<<<<<<<<<<<
+ *             flags |= RANGE_EMPTY
+ *         else:
+ */
+      goto __pyx_L5;
+    }
+
+    /* "asyncpg/protocol/codecs/range.pyx":87
+ *             flags |= RANGE_EMPTY
+ *         else:
+ *             lower = obj.lower             # <<<<<<<<<<<<<<
+ *             upper = obj.upper
+ * 
+ */
+    /*else*/ {
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_lower); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 87, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF_SET(__pyx_v_lower, __pyx_t_1);
+      __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/range.pyx":88
+ *         else:
+ *             lower = obj.lower
+ *             upper = obj.upper             # <<<<<<<<<<<<<<
+ * 
+ *             if obj.lower_inc:
+ */
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_upper); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 88, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF_SET(__pyx_v_upper, __pyx_t_1);
+      __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/codecs/range.pyx":90
+ *             upper = obj.upper
+ * 
+ *             if obj.lower_inc:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_LB_INC
+ *             elif lower is None:
+ */
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_lower_inc); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 90, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(9, 90, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/range.pyx":91
+ * 
+ *             if obj.lower_inc:
+ *                 flags |= RANGE_LB_INC             # <<<<<<<<<<<<<<
+ *             elif lower is None:
+ *                 flags |= RANGE_LB_INF
+ */
+        __pyx_v_flags = (__pyx_v_flags | 2);
+
+        /* "asyncpg/protocol/codecs/range.pyx":90
+ *             upper = obj.upper
+ * 
+ *             if obj.lower_inc:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_LB_INC
+ *             elif lower is None:
+ */
+        goto __pyx_L6;
+      }
+
+      /* "asyncpg/protocol/codecs/range.pyx":92
+ *             if obj.lower_inc:
+ *                 flags |= RANGE_LB_INC
+ *             elif lower is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_LB_INF
+ * 
+ */
+      __pyx_t_5 = (__pyx_v_lower == Py_None);
+      __pyx_t_6 = (__pyx_t_5 != 0);
+      if (__pyx_t_6) {
+
+        /* "asyncpg/protocol/codecs/range.pyx":93
+ *                 flags |= RANGE_LB_INC
+ *             elif lower is None:
+ *                 flags |= RANGE_LB_INF             # <<<<<<<<<<<<<<
+ * 
+ *             if obj.upper_inc:
+ */
+        __pyx_v_flags = (__pyx_v_flags | 8);
+
+        /* "asyncpg/protocol/codecs/range.pyx":92
+ *             if obj.lower_inc:
+ *                 flags |= RANGE_LB_INC
+ *             elif lower is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_LB_INF
+ * 
+ */
+      }
+      __pyx_L6:;
+
+      /* "asyncpg/protocol/codecs/range.pyx":95
+ *                 flags |= RANGE_LB_INF
+ * 
+ *             if obj.upper_inc:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_UB_INC
+ *             elif upper is None:
+ */
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_upper_inc); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 95, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(9, 95, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      if (__pyx_t_6) {
+
+        /* "asyncpg/protocol/codecs/range.pyx":96
+ * 
+ *             if obj.upper_inc:
+ *                 flags |= RANGE_UB_INC             # <<<<<<<<<<<<<<
+ *             elif upper is None:
+ *                 flags |= RANGE_UB_INF
+ */
+        __pyx_v_flags = (__pyx_v_flags | 4);
+
+        /* "asyncpg/protocol/codecs/range.pyx":95
+ *                 flags |= RANGE_LB_INF
+ * 
+ *             if obj.upper_inc:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_UB_INC
+ *             elif upper is None:
+ */
+        goto __pyx_L7;
+      }
+
+      /* "asyncpg/protocol/codecs/range.pyx":97
+ *             if obj.upper_inc:
+ *                 flags |= RANGE_UB_INC
+ *             elif upper is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_UB_INF
+ * 
+ */
+      __pyx_t_6 = (__pyx_v_upper == Py_None);
+      __pyx_t_5 = (__pyx_t_6 != 0);
+      if (__pyx_t_5) {
+
+        /* "asyncpg/protocol/codecs/range.pyx":98
+ *                 flags |= RANGE_UB_INC
+ *             elif upper is None:
+ *                 flags |= RANGE_UB_INF             # <<<<<<<<<<<<<<
+ * 
+ *     if _range_has_lbound(flags):
+ */
+        __pyx_v_flags = (__pyx_v_flags | 16);
+
+        /* "asyncpg/protocol/codecs/range.pyx":97
+ *             if obj.upper_inc:
+ *                 flags |= RANGE_UB_INC
+ *             elif upper is None:             # <<<<<<<<<<<<<<
+ *                 flags |= RANGE_UB_INF
+ * 
+ */
+      }
+      __pyx_L7:;
+    }
+    __pyx_L5:;
+    break;
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":100
+ *                 flags |= RANGE_UB_INF
+ * 
+ *     if _range_has_lbound(flags):             # <<<<<<<<<<<<<<
+ *         encoder(settings, bounds_data, lower, encoder_arg)
+ * 
+ */
+  __pyx_t_5 = (__pyx_f_7asyncpg_8protocol_8protocol__range_has_lbound(__pyx_v_flags) != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/protocol/codecs/range.pyx":101
+ * 
+ *     if _range_has_lbound(flags):
+ *         encoder(settings, bounds_data, lower, encoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *     if _range_has_ubound(flags):
+ */
+    __pyx_t_1 = __pyx_v_encoder(__pyx_v_settings, __pyx_v_bounds_data, __pyx_v_lower, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 101, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/range.pyx":100
+ *                 flags |= RANGE_UB_INF
+ * 
+ *     if _range_has_lbound(flags):             # <<<<<<<<<<<<<<
+ *         encoder(settings, bounds_data, lower, encoder_arg)
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":103
+ *         encoder(settings, bounds_data, lower, encoder_arg)
+ * 
+ *     if _range_has_ubound(flags):             # <<<<<<<<<<<<<<
+ *         encoder(settings, bounds_data, upper, encoder_arg)
+ * 
+ */
+  __pyx_t_5 = (__pyx_f_7asyncpg_8protocol_8protocol__range_has_ubound(__pyx_v_flags) != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/protocol/codecs/range.pyx":104
+ * 
+ *     if _range_has_ubound(flags):
+ *         encoder(settings, bounds_data, upper, encoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *     buf.write_int32(1 + bounds_data.len())
+ */
+    __pyx_t_1 = __pyx_v_encoder(__pyx_v_settings, __pyx_v_bounds_data, __pyx_v_upper, __pyx_v_encoder_arg); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 104, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/codecs/range.pyx":103
+ *         encoder(settings, bounds_data, lower, encoder_arg)
+ * 
+ *     if _range_has_ubound(flags):             # <<<<<<<<<<<<<<
+ *         encoder(settings, bounds_data, upper, encoder_arg)
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":106
+ *         encoder(settings, bounds_data, upper, encoder_arg)
+ * 
+ *     buf.write_int32(1 + bounds_data.len())             # <<<<<<<<<<<<<<
+ *     buf.write_byte(<int8_t>flags)
+ *     buf.write_buffer(bounds_data)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_bounds_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 106, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyInt_AddCObj(__pyx_int_1, __pyx_t_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 106, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_8 = __Pyx_PyInt_As_int32_t(__pyx_t_2); if (unlikely((__pyx_t_8 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(9, 106, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 106, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":107
+ * 
+ *     buf.write_int32(1 + bounds_data.len())
+ *     buf.write_byte(<int8_t>flags)             # <<<<<<<<<<<<<<
+ *     buf.write_buffer(bounds_data)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_byte(__pyx_v_buf, ((int8_t)__pyx_v_flags)); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 107, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":108
+ *     buf.write_int32(1 + bounds_data.len())
+ *     buf.write_byte(<int8_t>flags)
+ *     buf.write_buffer(bounds_data)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_buffer(__pyx_v_buf, __pyx_v_bounds_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 108, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":41
+ * 
+ * 
+ * cdef range_encode(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                   object obj, uint32_t elem_oid,
+ *                   encode_func_ex encoder, const void *encoder_arg):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.range_encode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_lower);
+  __Pyx_XDECREF(__pyx_v_upper);
+  __Pyx_XDECREF((PyObject *)__pyx_v_bounds_data);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/range.pyx":111
+ * 
+ * 
+ * cdef range_decode(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                   decode_func_ex decoder, const void *decoder_arg):
+ *     cdef:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_range_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf, __pyx_t_7asyncpg_8protocol_8protocol_decode_func_ex __pyx_v_decoder, void const *__pyx_v_decoder_arg) {
+  uint8_t __pyx_v_flags;
+  int32_t __pyx_v_bound_len;
+  PyObject *__pyx_v_lower = 0;
+  PyObject *__pyx_v_upper = 0;
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer __pyx_v_bound_buf;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("range_decode", 0);
+
+  /* "asyncpg/protocol/codecs/range.pyx":114
+ *                   decode_func_ex decoder, const void *decoder_arg):
+ *     cdef:
+ *         uint8_t flags = <uint8_t>frb_read(buf, 1)[0]             # <<<<<<<<<<<<<<
+ *         int32_t bound_len
+ *         object lower = None
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 1); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(9, 114, __pyx_L1_error)
+  __pyx_v_flags = ((uint8_t)(__pyx_t_1[0]));
+
+  /* "asyncpg/protocol/codecs/range.pyx":116
+ *         uint8_t flags = <uint8_t>frb_read(buf, 1)[0]
+ *         int32_t bound_len
+ *         object lower = None             # <<<<<<<<<<<<<<
+ *         object upper = None
+ *         FRBuffer bound_buf
+ */
+  __Pyx_INCREF(Py_None);
+  __pyx_v_lower = Py_None;
+
+  /* "asyncpg/protocol/codecs/range.pyx":117
+ *         int32_t bound_len
+ *         object lower = None
+ *         object upper = None             # <<<<<<<<<<<<<<
+ *         FRBuffer bound_buf
+ * 
+ */
+  __Pyx_INCREF(Py_None);
+  __pyx_v_upper = Py_None;
+
+  /* "asyncpg/protocol/codecs/range.pyx":120
+ *         FRBuffer bound_buf
+ * 
+ *     if _range_has_lbound(flags):             # <<<<<<<<<<<<<<
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:
+ */
+  __pyx_t_2 = (__pyx_f_7asyncpg_8protocol_8protocol__range_has_lbound(__pyx_v_flags) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/range.pyx":121
+ * 
+ *     if _range_has_lbound(flags):
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         if bound_len == -1:
+ *             lower = None
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(9, 121, __pyx_L1_error)
+    __pyx_v_bound_len = unpack_int32(__pyx_t_1);
+
+    /* "asyncpg/protocol/codecs/range.pyx":122
+ *     if _range_has_lbound(flags):
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:             # <<<<<<<<<<<<<<
+ *             lower = None
+ *         else:
+ */
+    __pyx_t_2 = ((__pyx_v_bound_len == -1L) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/range.pyx":123
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:
+ *             lower = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             frb_slice_from(&bound_buf, buf, bound_len)
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_DECREF_SET(__pyx_v_lower, Py_None);
+
+      /* "asyncpg/protocol/codecs/range.pyx":122
+ *     if _range_has_lbound(flags):
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:             # <<<<<<<<<<<<<<
+ *             lower = None
+ *         else:
+ */
+      goto __pyx_L4;
+    }
+
+    /* "asyncpg/protocol/codecs/range.pyx":125
+ *             lower = None
+ *         else:
+ *             frb_slice_from(&bound_buf, buf, bound_len)             # <<<<<<<<<<<<<<
+ *             lower = decoder(settings, &bound_buf, decoder_arg)
+ * 
+ */
+    /*else*/ {
+      (void)(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from((&__pyx_v_bound_buf), __pyx_v_buf, __pyx_v_bound_len));
+
+      /* "asyncpg/protocol/codecs/range.pyx":126
+ *         else:
+ *             frb_slice_from(&bound_buf, buf, bound_len)
+ *             lower = decoder(settings, &bound_buf, decoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *     if _range_has_ubound(flags):
+ */
+      __pyx_t_3 = __pyx_v_decoder(__pyx_v_settings, (&__pyx_v_bound_buf), __pyx_v_decoder_arg); if (unlikely(!__pyx_t_3)) __PYX_ERR(9, 126, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF_SET(__pyx_v_lower, __pyx_t_3);
+      __pyx_t_3 = 0;
+    }
+    __pyx_L4:;
+
+    /* "asyncpg/protocol/codecs/range.pyx":120
+ *         FRBuffer bound_buf
+ * 
+ *     if _range_has_lbound(flags):             # <<<<<<<<<<<<<<
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":128
+ *             lower = decoder(settings, &bound_buf, decoder_arg)
+ * 
+ *     if _range_has_ubound(flags):             # <<<<<<<<<<<<<<
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:
+ */
+  __pyx_t_2 = (__pyx_f_7asyncpg_8protocol_8protocol__range_has_ubound(__pyx_v_flags) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/codecs/range.pyx":129
+ * 
+ *     if _range_has_ubound(flags):
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         if bound_len == -1:
+ *             upper = None
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(9, 129, __pyx_L1_error)
+    __pyx_v_bound_len = unpack_int32(__pyx_t_1);
+
+    /* "asyncpg/protocol/codecs/range.pyx":130
+ *     if _range_has_ubound(flags):
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:             # <<<<<<<<<<<<<<
+ *             upper = None
+ *         else:
+ */
+    __pyx_t_2 = ((__pyx_v_bound_len == -1L) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/codecs/range.pyx":131
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:
+ *             upper = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             frb_slice_from(&bound_buf, buf, bound_len)
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_DECREF_SET(__pyx_v_upper, Py_None);
+
+      /* "asyncpg/protocol/codecs/range.pyx":130
+ *     if _range_has_ubound(flags):
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:             # <<<<<<<<<<<<<<
+ *             upper = None
+ *         else:
+ */
+      goto __pyx_L6;
+    }
+
+    /* "asyncpg/protocol/codecs/range.pyx":133
+ *             upper = None
+ *         else:
+ *             frb_slice_from(&bound_buf, buf, bound_len)             # <<<<<<<<<<<<<<
+ *             upper = decoder(settings, &bound_buf, decoder_arg)
+ * 
+ */
+    /*else*/ {
+      (void)(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from((&__pyx_v_bound_buf), __pyx_v_buf, __pyx_v_bound_len));
+
+      /* "asyncpg/protocol/codecs/range.pyx":134
+ *         else:
+ *             frb_slice_from(&bound_buf, buf, bound_len)
+ *             upper = decoder(settings, &bound_buf, decoder_arg)             # <<<<<<<<<<<<<<
+ * 
+ *     return apg_types.Range(lower=lower, upper=upper,
+ */
+      __pyx_t_3 = __pyx_v_decoder(__pyx_v_settings, (&__pyx_v_bound_buf), __pyx_v_decoder_arg); if (unlikely(!__pyx_t_3)) __PYX_ERR(9, 134, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF_SET(__pyx_v_upper, __pyx_t_3);
+      __pyx_t_3 = 0;
+    }
+    __pyx_L6:;
+
+    /* "asyncpg/protocol/codecs/range.pyx":128
+ *             lower = decoder(settings, &bound_buf, decoder_arg)
+ * 
+ *     if _range_has_ubound(flags):             # <<<<<<<<<<<<<<
+ *         bound_len = hton.unpack_int32(frb_read(buf, 4))
+ *         if bound_len == -1:
+ */
+  }
+
+  /* "asyncpg/protocol/codecs/range.pyx":136
+ *             upper = decoder(settings, &bound_buf, decoder_arg)
+ * 
+ *     return apg_types.Range(lower=lower, upper=upper,             # <<<<<<<<<<<<<<
+ *                            lower_inc=(flags & RANGE_LB_INC) != 0,
+ *                            upper_inc=(flags & RANGE_UB_INC) != 0,
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Range); if (unlikely(!__pyx_t_4)) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_lower, __pyx_v_lower) < 0) __PYX_ERR(9, 136, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_upper, __pyx_v_upper) < 0) __PYX_ERR(9, 136, __pyx_L1_error)
+
+  /* "asyncpg/protocol/codecs/range.pyx":137
+ * 
+ *     return apg_types.Range(lower=lower, upper=upper,
+ *                            lower_inc=(flags & RANGE_LB_INC) != 0,             # <<<<<<<<<<<<<<
+ *                            upper_inc=(flags & RANGE_UB_INC) != 0,
+ *                            empty=(flags & RANGE_EMPTY) != 0)
+ */
+  __pyx_t_5 = __Pyx_PyBool_FromLong(((__pyx_v_flags & 2) != 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(9, 137, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_lower_inc, __pyx_t_5) < 0) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":138
+ *     return apg_types.Range(lower=lower, upper=upper,
+ *                            lower_inc=(flags & RANGE_LB_INC) != 0,
+ *                            upper_inc=(flags & RANGE_UB_INC) != 0,             # <<<<<<<<<<<<<<
+ *                            empty=(flags & RANGE_EMPTY) != 0)
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyBool_FromLong(((__pyx_v_flags & 4) != 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(9, 138, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_upper_inc, __pyx_t_5) < 0) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":139
+ *                            lower_inc=(flags & RANGE_LB_INC) != 0,
+ *                            upper_inc=(flags & RANGE_UB_INC) != 0,
+ *                            empty=(flags & RANGE_EMPTY) != 0)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyBool_FromLong(((__pyx_v_flags & 1) != 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(9, 139, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_empty, __pyx_t_5) < 0) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":136
+ *             upper = decoder(settings, &bound_buf, decoder_arg)
+ * 
+ *     return apg_types.Range(lower=lower, upper=upper,             # <<<<<<<<<<<<<<
+ *                            lower_inc=(flags & RANGE_LB_INC) != 0,
+ *                            upper_inc=(flags & RANGE_UB_INC) != 0,
+ */
+  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(9, 136, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_5;
+  __pyx_t_5 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":111
+ * 
+ * 
+ * cdef range_decode(ConnectionSettings settings, FRBuffer *buf,             # <<<<<<<<<<<<<<
+ *                   decode_func_ex decoder, const void *decoder_arg):
+ *     cdef:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.range_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_lower);
+  __Pyx_XDECREF(__pyx_v_upper);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/range.pyx":142
+ * 
+ * 
+ * cdef init_range_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(ANYRANGEOID,
+ *                         NULL,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_range_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_range_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/range.pyx":143
+ * 
+ * cdef init_range_codecs():
+ *     register_core_codec(ANYRANGEOID,             # <<<<<<<<<<<<<<
+ *                         NULL,
+ *                         <decode_func>pgproto.text_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0xEF7, NULL, ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_TEXT, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 143, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":142
+ * 
+ * 
+ * cdef init_range_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(ANYRANGEOID,
+ *                         NULL,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_range_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/record.pyx":11
+ * 
+ * 
+ * cdef inline record_encode_frame(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                                 WriteBuffer elem_data, int32_t elem_count):
+ *     buf.write_int32(4 + elem_data.len())
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_record_encode_frame(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_elem_data, int32_t __pyx_v_elem_count) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  int32_t __pyx_t_3;
+  __Pyx_RefNannySetupContext("record_encode_frame", 0);
+
+  /* "asyncpg/protocol/codecs/record.pyx":13
+ * cdef inline record_encode_frame(ConnectionSettings settings, WriteBuffer buf,
+ *                                 WriteBuffer elem_data, int32_t elem_count):
+ *     buf.write_int32(4 + elem_data.len())             # <<<<<<<<<<<<<<
+ *     # attribute count
+ *     buf.write_int32(elem_count)
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_elem_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyInt_AddCObj(__pyx_int_4, __pyx_t_1, 4, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = __Pyx_PyInt_As_int32_t(__pyx_t_2); if (unlikely((__pyx_t_3 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(10, 13, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":15
+ *     buf.write_int32(4 + elem_data.len())
+ *     # attribute count
+ *     buf.write_int32(elem_count)             # <<<<<<<<<<<<<<
+ *     # encoded attribute data
+ *     buf.write_buffer(elem_data)
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_v_elem_count); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":17
+ *     buf.write_int32(elem_count)
+ *     # encoded attribute data
+ *     buf.write_buffer(elem_data)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_buffer(__pyx_v_buf, __pyx_v_elem_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":11
+ * 
+ * 
+ * cdef inline record_encode_frame(ConnectionSettings settings, WriteBuffer buf,             # <<<<<<<<<<<<<<
+ *                                 WriteBuffer elem_data, int32_t elem_count):
+ *     buf.write_int32(4 + elem_data.len())
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.record_encode_frame", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/record.pyx":20
+ * 
+ * 
+ * cdef anonymous_record_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         tuple result
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_anonymous_record_decode(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_buf) {
+  PyObject *__pyx_v_result = 0;
+  Py_ssize_t __pyx_v_elem_count;
+  Py_ssize_t __pyx_v_i;
+  int32_t __pyx_v_elem_len;
+  uint32_t __pyx_v_elem_typ;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_elem_codec = 0;
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer __pyx_v_elem_buf;
+  PyObject *__pyx_v_elem = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  Py_ssize_t __pyx_t_4;
+  Py_ssize_t __pyx_t_5;
+  int __pyx_t_6;
+  int __pyx_t_7;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  int __pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  __Pyx_RefNannySetupContext("anonymous_record_decode", 0);
+
+  /* "asyncpg/protocol/codecs/record.pyx":30
+ *         FRBuffer elem_buf
+ * 
+ *     elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *     result = cpython.PyTuple_New(elem_count)
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(10, 30, __pyx_L1_error)
+  __pyx_v_elem_count = ((Py_ssize_t)((uint32_t)unpack_int32(__pyx_t_1)));
+
+  /* "asyncpg/protocol/codecs/record.pyx":31
+ * 
+ *     elem_count = <ssize_t><uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *     result = cpython.PyTuple_New(elem_count)             # <<<<<<<<<<<<<<
+ * 
+ *     for i in range(elem_count):
+ */
+  __pyx_t_2 = PyTuple_New(__pyx_v_elem_count); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 31, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_result = ((PyObject*)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":33
+ *     result = cpython.PyTuple_New(elem_count)
+ * 
+ *     for i in range(elem_count):             # <<<<<<<<<<<<<<
+ *         elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ */
+  __pyx_t_3 = __pyx_v_elem_count;
+  __pyx_t_4 = __pyx_t_3;
+  for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
+    __pyx_v_i = __pyx_t_5;
+
+    /* "asyncpg/protocol/codecs/record.pyx":34
+ * 
+ *     for i in range(elem_count):
+ *         elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(10, 34, __pyx_L1_error)
+    __pyx_v_elem_typ = ((uint32_t)unpack_int32(__pyx_t_1));
+
+    /* "asyncpg/protocol/codecs/record.pyx":35
+ *     for i in range(elem_count):
+ *         elem_typ = <uint32_t>hton.unpack_int32(frb_read(buf, 4))
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *         if elem_len == -1:
+ */
+    __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_buf, 4); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(10, 35, __pyx_L1_error)
+    __pyx_v_elem_len = unpack_int32(__pyx_t_1);
+
+    /* "asyncpg/protocol/codecs/record.pyx":37
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *         if elem_len == -1:             # <<<<<<<<<<<<<<
+ *             elem = None
+ *         else:
+ */
+    __pyx_t_6 = ((__pyx_v_elem_len == -1L) != 0);
+    if (__pyx_t_6) {
+
+      /* "asyncpg/protocol/codecs/record.pyx":38
+ * 
+ *         if elem_len == -1:
+ *             elem = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             elem_codec = settings.get_data_codec(elem_typ)
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_elem, Py_None);
+
+      /* "asyncpg/protocol/codecs/record.pyx":37
+ *         elem_len = hton.unpack_int32(frb_read(buf, 4))
+ * 
+ *         if elem_len == -1:             # <<<<<<<<<<<<<<
+ *             elem = None
+ *         else:
+ */
+      goto __pyx_L5;
+    }
+
+    /* "asyncpg/protocol/codecs/record.pyx":40
+ *             elem = None
+ *         else:
+ *             elem_codec = settings.get_data_codec(elem_typ)             # <<<<<<<<<<<<<<
+ *             if elem_codec is None or not elem_codec.has_decoder():
+ *                 raise exceptions.InternalClientError(
+ */
+    /*else*/ {
+      __pyx_t_2 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_settings, __pyx_v_elem_typ, 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 40, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_XDECREF_SET(__pyx_v_elem_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_2));
+      __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/codecs/record.pyx":41
+ *         else:
+ *             elem_codec = settings.get_data_codec(elem_typ)
+ *             if elem_codec is None or not elem_codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for composite type element in '
+ */
+      __pyx_t_7 = (((PyObject *)__pyx_v_elem_codec) == Py_None);
+      __pyx_t_8 = (__pyx_t_7 != 0);
+      if (!__pyx_t_8) {
+      } else {
+        __pyx_t_6 = __pyx_t_8;
+        goto __pyx_L7_bool_binop_done;
+      }
+      __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(__pyx_v_elem_codec); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 41, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(10, 41, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __pyx_t_7 = ((!__pyx_t_8) != 0);
+      __pyx_t_6 = __pyx_t_7;
+      __pyx_L7_bool_binop_done:;
+      if (unlikely(__pyx_t_6)) {
+
+        /* "asyncpg/protocol/codecs/record.pyx":42
+ *             elem_codec = settings.get_data_codec(elem_typ)
+ *             if elem_codec is None or not elem_codec.has_decoder():
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'no decoder for composite type element in '
+ *                     'position {} of type OID {}'.format(i, elem_typ))
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_9)) __PYX_ERR(10, 42, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_10)) __PYX_ERR(10, 42, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_10);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+        /* "asyncpg/protocol/codecs/record.pyx":44
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for composite type element in '
+ *                     'position {} of type OID {}'.format(i, elem_typ))             # <<<<<<<<<<<<<<
+ *             elem = elem_codec.decode(settings,
+ *                                      frb_slice_from(&elem_buf, buf, elem_len))
+ */
+        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_no_decoder_for_composite_type_el, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(10, 44, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __pyx_t_12 = PyInt_FromSsize_t(__pyx_v_i); if (unlikely(!__pyx_t_12)) __PYX_ERR(10, 44, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_12);
+        __pyx_t_13 = __Pyx_PyInt_From_uint32_t(__pyx_v_elem_typ); if (unlikely(!__pyx_t_13)) __PYX_ERR(10, 44, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_13);
+        __pyx_t_14 = NULL;
+        __pyx_t_15 = 0;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_11);
+          if (likely(__pyx_t_14)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+            __Pyx_INCREF(__pyx_t_14);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_11, function);
+            __pyx_t_15 = 1;
+          }
+        }
+        #if CYTHON_FAST_PYCALL
+        if (PyFunction_Check(__pyx_t_11)) {
+          PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_t_12, __pyx_t_13};
+          __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(10, 44, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+        } else
+        #endif
+        #if CYTHON_FAST_PYCCALL
+        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
+          PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_t_12, __pyx_t_13};
+          __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(10, 44, __pyx_L1_error)
+          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+        } else
+        #endif
+        {
+          __pyx_t_16 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_16)) __PYX_ERR(10, 44, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_16);
+          if (__pyx_t_14) {
+            __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL;
+          }
+          __Pyx_GIVEREF(__pyx_t_12);
+          PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_15, __pyx_t_12);
+          __Pyx_GIVEREF(__pyx_t_13);
+          PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_15, __pyx_t_13);
+          __pyx_t_12 = 0;
+          __pyx_t_13 = 0;
+          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_16, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(10, 44, __pyx_L1_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+        }
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __pyx_t_11 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
+          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10);
+          if (likely(__pyx_t_11)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
+            __Pyx_INCREF(__pyx_t_11);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_10, function);
+          }
+        }
+        __pyx_t_2 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_9);
+        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 42, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+        __PYX_ERR(10, 42, __pyx_L1_error)
+
+        /* "asyncpg/protocol/codecs/record.pyx":41
+ *         else:
+ *             elem_codec = settings.get_data_codec(elem_typ)
+ *             if elem_codec is None or not elem_codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for composite type element in '
+ */
+      }
+
+      /* "asyncpg/protocol/codecs/record.pyx":45
+ *                     'no decoder for composite type element in '
+ *                     'position {} of type OID {}'.format(i, elem_typ))
+ *             elem = elem_codec.decode(settings,             # <<<<<<<<<<<<<<
+ *                                      frb_slice_from(&elem_buf, buf, elem_len))
+ * 
+ */
+      __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(__pyx_v_elem_codec, __pyx_v_settings, __pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from((&__pyx_v_elem_buf), __pyx_v_buf, __pyx_v_elem_len)); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 45, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_XDECREF_SET(__pyx_v_elem, __pyx_t_2);
+      __pyx_t_2 = 0;
+    }
+    __pyx_L5:;
+
+    /* "asyncpg/protocol/codecs/record.pyx":48
+ *                                      frb_slice_from(&elem_buf, buf, elem_len))
+ * 
+ *         cpython.Py_INCREF(elem)             # <<<<<<<<<<<<<<
+ *         cpython.PyTuple_SET_ITEM(result, i, elem)
+ * 
+ */
+    Py_INCREF(__pyx_v_elem);
+
+    /* "asyncpg/protocol/codecs/record.pyx":49
+ * 
+ *         cpython.Py_INCREF(elem)
+ *         cpython.PyTuple_SET_ITEM(result, i, elem)             # <<<<<<<<<<<<<<
+ * 
+ *     return result
+ */
+    PyTuple_SET_ITEM(__pyx_v_result, __pyx_v_i, __pyx_v_elem);
+  }
+
+  /* "asyncpg/protocol/codecs/record.pyx":51
+ *         cpython.PyTuple_SET_ITEM(result, i, elem)
+ * 
+ *     return result             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":20
+ * 
+ * 
+ * cdef anonymous_record_decode(ConnectionSettings settings, FRBuffer *buf):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         tuple result
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.anonymous_record_decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF((PyObject *)__pyx_v_elem_codec);
+  __Pyx_XDECREF(__pyx_v_elem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/codecs/record.pyx":54
+ * 
+ * 
+ * cdef init_record_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(RECORDOID,
+ *                         <encode_func>NULL,
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_init_record_codecs(void) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("init_record_codecs", 0);
+
+  /* "asyncpg/protocol/codecs/record.pyx":55
+ * 
+ * cdef init_record_codecs():
+ *     register_core_codec(RECORDOID,             # <<<<<<<<<<<<<<
+ *                         <encode_func>NULL,
+ *                         <decode_func>anonymous_record_decode,
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_register_core_codec(0x8C9, ((__pyx_t_7asyncpg_8protocol_8protocol_encode_func)NULL), ((__pyx_t_7asyncpg_8protocol_8protocol_decode_func)__pyx_f_7asyncpg_8protocol_8protocol_anonymous_record_decode), __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 55, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":54
+ * 
+ * 
+ * cdef init_record_codecs():             # <<<<<<<<<<<<<<
+ *     register_core_codec(RECORDOID,
+ *                         <encode_func>NULL,
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.init_record_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":13
+ * cdef class CoreProtocol:
+ * 
+ *     def __init__(self, con_params):             # <<<<<<<<<<<<<<
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         self.buffer = ReadBuffer()
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_con_params = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_con_params,0};
+    PyObject* values[1] = {0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_con_params)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(5, 13, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+    }
+    __pyx_v_con_params = values[0];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(5, 13, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol___init__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self), __pyx_v_con_params);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol___init__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_con_params) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__init__", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":15
+ *     def __init__(self, con_params):
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         self.buffer = ReadBuffer()             # <<<<<<<<<<<<<<
+ *         self.user = con_params.user
+ *         self.password = con_params.password
+ */
+  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->buffer);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->buffer));
+  __pyx_v_self->buffer = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":16
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         self.buffer = ReadBuffer()
+ *         self.user = con_params.user             # <<<<<<<<<<<<<<
+ *         self.password = con_params.password
+ *         self.auth_msg = None
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_con_params, __pyx_n_s_user); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 16, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_user, __pyx_t_1) < 0) __PYX_ERR(5, 16, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":17
+ *         self.buffer = ReadBuffer()
+ *         self.user = con_params.user
+ *         self.password = con_params.password             # <<<<<<<<<<<<<<
+ *         self.auth_msg = None
+ *         self.con_params = con_params
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_con_params, __pyx_n_s_password); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_password, __pyx_t_1) < 0) __PYX_ERR(5, 17, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":18
+ *         self.user = con_params.user
+ *         self.password = con_params.password
+ *         self.auth_msg = None             # <<<<<<<<<<<<<<
+ *         self.con_params = con_params
+ *         self.con_status = CONNECTION_BAD
+ */
+  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_auth_msg, Py_None) < 0) __PYX_ERR(5, 18, __pyx_L1_error)
+
+  /* "asyncpg/protocol/coreproto.pyx":19
+ *         self.password = con_params.password
+ *         self.auth_msg = None
+ *         self.con_params = con_params             # <<<<<<<<<<<<<<
+ *         self.con_status = CONNECTION_BAD
+ *         self.state = PROTOCOL_IDLE
+ */
+  __Pyx_INCREF(__pyx_v_con_params);
+  __Pyx_GIVEREF(__pyx_v_con_params);
+  __Pyx_GOTREF(__pyx_v_self->con_params);
+  __Pyx_DECREF(__pyx_v_self->con_params);
+  __pyx_v_self->con_params = __pyx_v_con_params;
+
+  /* "asyncpg/protocol/coreproto.pyx":20
+ *         self.auth_msg = None
+ *         self.con_params = con_params
+ *         self.con_status = CONNECTION_BAD             # <<<<<<<<<<<<<<
+ *         self.state = PROTOCOL_IDLE
+ *         self.xact_status = PQTRANS_IDLE
+ */
+  __pyx_v_self->con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD;
+
+  /* "asyncpg/protocol/coreproto.pyx":21
+ *         self.con_params = con_params
+ *         self.con_status = CONNECTION_BAD
+ *         self.state = PROTOCOL_IDLE             # <<<<<<<<<<<<<<
+ *         self.xact_status = PQTRANS_IDLE
+ *         self.encoding = 'utf-8'
+ */
+  __pyx_v_self->state = __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE;
+
+  /* "asyncpg/protocol/coreproto.pyx":22
+ *         self.con_status = CONNECTION_BAD
+ *         self.state = PROTOCOL_IDLE
+ *         self.xact_status = PQTRANS_IDLE             # <<<<<<<<<<<<<<
+ *         self.encoding = 'utf-8'
+ * 
+ */
+  __pyx_v_self->xact_status = __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_IDLE;
+
+  /* "asyncpg/protocol/coreproto.pyx":23
+ *         self.state = PROTOCOL_IDLE
+ *         self.xact_status = PQTRANS_IDLE
+ *         self.encoding = 'utf-8'             # <<<<<<<<<<<<<<
+ * 
+ *         # executemany support data
+ */
+  __Pyx_INCREF(__pyx_kp_u_utf_8);
+  __Pyx_GIVEREF(__pyx_kp_u_utf_8);
+  __Pyx_GOTREF(__pyx_v_self->encoding);
+  __Pyx_DECREF(__pyx_v_self->encoding);
+  __pyx_v_self->encoding = __pyx_kp_u_utf_8;
+
+  /* "asyncpg/protocol/coreproto.pyx":26
+ * 
+ *         # executemany support data
+ *         self._execute_iter = None             # <<<<<<<<<<<<<<
+ *         self._execute_portal_name = None
+ *         self._execute_stmt_name = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_execute_iter);
+  __Pyx_DECREF(__pyx_v_self->_execute_iter);
+  __pyx_v_self->_execute_iter = Py_None;
+
+  /* "asyncpg/protocol/coreproto.pyx":27
+ *         # executemany support data
+ *         self._execute_iter = None
+ *         self._execute_portal_name = None             # <<<<<<<<<<<<<<
+ *         self._execute_stmt_name = None
+ * 
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_execute_portal_name);
+  __Pyx_DECREF(__pyx_v_self->_execute_portal_name);
+  __pyx_v_self->_execute_portal_name = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/coreproto.pyx":28
+ *         self._execute_iter = None
+ *         self._execute_portal_name = None
+ *         self._execute_stmt_name = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._reset_result()
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_execute_stmt_name);
+  __Pyx_DECREF(__pyx_v_self->_execute_stmt_name);
+  __pyx_v_self->_execute_stmt_name = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/coreproto.pyx":30
+ *         self._execute_stmt_name = None
+ * 
+ *         self._reset_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _read_server_messages(self):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_reset_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 30, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":13
+ * cdef class CoreProtocol:
+ * 
+ *     def __init__(self, con_params):             # <<<<<<<<<<<<<<
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         self.buffer = ReadBuffer()
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":32
+ *         self._reset_result()
+ * 
+ *     cdef _read_server_messages(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             char mtype
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__read_server_messages(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  char __pyx_v_mtype;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __pyx_v_state;
+  __pyx_t_7asyncpg_7pgproto_7pgproto_take_message_method __pyx_v_take_message;
+  __pyx_t_7asyncpg_7pgproto_7pgproto_get_message_type_method __pyx_v_get_message_type;
+  PyObject *__pyx_v_ex = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int32_t __pyx_t_2;
+  int __pyx_t_3;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  Py_ssize_t __pyx_t_10;
+  Py_UCS4 __pyx_t_11;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  int __pyx_t_14;
+  int __pyx_t_15;
+  char const *__pyx_t_16;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  PyObject *__pyx_t_21 = NULL;
+  PyObject *__pyx_t_22 = NULL;
+  char const *__pyx_t_23;
+  __Pyx_RefNannySetupContext("_read_server_messages", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":37
+ *             ProtocolState state
+ *             pgproto.take_message_method take_message = \
+ *                 <pgproto.take_message_method>self.buffer.take_message             # <<<<<<<<<<<<<<
+ *             pgproto.get_message_type_method get_message_type= \
+ *                 <pgproto.get_message_type_method>self.buffer.get_message_type
+ */
+  __pyx_v_take_message = ((__pyx_t_7asyncpg_7pgproto_7pgproto_take_message_method)((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->take_message);
+
+  /* "asyncpg/protocol/coreproto.pyx":39
+ *                 <pgproto.take_message_method>self.buffer.take_message
+ *             pgproto.get_message_type_method get_message_type= \
+ *                 <pgproto.get_message_type_method>self.buffer.get_message_type             # <<<<<<<<<<<<<<
+ * 
+ *         while take_message(self.buffer) == 1:
+ */
+  __pyx_v_get_message_type = ((__pyx_t_7asyncpg_7pgproto_7pgproto_get_message_type_method)__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type);
+
+  /* "asyncpg/protocol/coreproto.pyx":41
+ *                 <pgproto.get_message_type_method>self.buffer.get_message_type
+ * 
+ *         while take_message(self.buffer) == 1:             # <<<<<<<<<<<<<<
+ *             mtype = get_message_type(self.buffer)
+ *             state = self.state
+ */
+  while (1) {
+    __pyx_t_1 = ((PyObject *)__pyx_v_self->buffer);
+    __Pyx_INCREF(__pyx_t_1);
+    __pyx_t_2 = __pyx_v_take_message(__pyx_t_1); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(5, 41, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_3 = ((__pyx_t_2 == 1) != 0);
+    if (!__pyx_t_3) break;
+
+    /* "asyncpg/protocol/coreproto.pyx":42
+ * 
+ *         while take_message(self.buffer) == 1:
+ *             mtype = get_message_type(self.buffer)             # <<<<<<<<<<<<<<
+ *             state = self.state
+ * 
+ */
+    __pyx_t_1 = ((PyObject *)__pyx_v_self->buffer);
+    __Pyx_INCREF(__pyx_t_1);
+    __pyx_v_mtype = __pyx_v_get_message_type(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":43
+ *         while take_message(self.buffer) == 1:
+ *             mtype = get_message_type(self.buffer)
+ *             state = self.state             # <<<<<<<<<<<<<<
+ * 
+ *             try:
+ */
+    __pyx_t_4 = __pyx_v_self->state;
+    __pyx_v_state = __pyx_t_4;
+
+    /* "asyncpg/protocol/coreproto.pyx":45
+ *             state = self.state
+ * 
+ *             try:             # <<<<<<<<<<<<<<
+ *                 if mtype == b'S':
+ *                     # ParameterStatus
+ */
+    /*try:*/ {
+      {
+        __Pyx_PyThreadState_declare
+        __Pyx_PyThreadState_assign
+        __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
+        __Pyx_XGOTREF(__pyx_t_5);
+        __Pyx_XGOTREF(__pyx_t_6);
+        __Pyx_XGOTREF(__pyx_t_7);
+        /*try:*/ {
+
+          /* "asyncpg/protocol/coreproto.pyx":46
+ * 
+ *             try:
+ *                 if mtype == b'S':             # <<<<<<<<<<<<<<
+ *                     # ParameterStatus
+ *                     self._parse_msg_parameter_status()
+ */
+          __pyx_t_3 = ((__pyx_v_mtype == 'S') != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":48
+ *                 if mtype == b'S':
+ *                     # ParameterStatus
+ *                     self._parse_msg_parameter_status()             # <<<<<<<<<<<<<<
+ * 
+ *                 elif mtype == b'A':
+ */
+            __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_parameter_status(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 48, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_1);
+            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":46
+ * 
+ *             try:
+ *                 if mtype == b'S':             # <<<<<<<<<<<<<<
+ *                     # ParameterStatus
+ *                     self._parse_msg_parameter_status()
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":50
+ *                     self._parse_msg_parameter_status()
+ * 
+ *                 elif mtype == b'A':             # <<<<<<<<<<<<<<
+ *                     # NotificationResponse
+ *                     self._parse_msg_notification()
+ */
+          __pyx_t_3 = ((__pyx_v_mtype == 'A') != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":52
+ *                 elif mtype == b'A':
+ *                     # NotificationResponse
+ *                     self._parse_msg_notification()             # <<<<<<<<<<<<<<
+ * 
+ *                 elif mtype == b'N':
+ */
+            __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_notification(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 52, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_1);
+            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":50
+ *                     self._parse_msg_parameter_status()
+ * 
+ *                 elif mtype == b'A':             # <<<<<<<<<<<<<<
+ *                     # NotificationResponse
+ *                     self._parse_msg_notification()
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":54
+ *                     self._parse_msg_notification()
+ * 
+ *                 elif mtype == b'N':             # <<<<<<<<<<<<<<
+ *                     # 'N' - NoticeResponse
+ *                     self._on_notice(self._parse_msg_error_response(False))
+ */
+          __pyx_t_3 = ((__pyx_v_mtype == 'N') != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":56
+ *                 elif mtype == b'N':
+ *                     # 'N' - NoticeResponse
+ *                     self._on_notice(self._parse_msg_error_response(False))             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_AUTH:
+ */
+            __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_False); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 56, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_1);
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_on_notice(__pyx_v_self, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 56, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":54
+ *                     self._parse_msg_notification()
+ * 
+ *                 elif mtype == b'N':             # <<<<<<<<<<<<<<
+ *                     # 'N' - NoticeResponse
+ *                     self._on_notice(self._parse_msg_error_response(False))
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":58
+ *                     self._on_notice(self._parse_msg_error_response(False))
+ * 
+ *                 elif state == PROTOCOL_AUTH:             # <<<<<<<<<<<<<<
+ *                     self._process__auth(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_AUTH) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":59
+ * 
+ *                 elif state == PROTOCOL_AUTH:
+ *                     self._process__auth(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_PREPARE:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__auth(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 59, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":58
+ *                     self._on_notice(self._parse_msg_error_response(False))
+ * 
+ *                 elif state == PROTOCOL_AUTH:             # <<<<<<<<<<<<<<
+ *                     self._process__auth(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":61
+ *                     self._process__auth(mtype)
+ * 
+ *                 elif state == PROTOCOL_PREPARE:             # <<<<<<<<<<<<<<
+ *                     self._process__prepare(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_PREPARE) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":62
+ * 
+ *                 elif state == PROTOCOL_PREPARE:
+ *                     self._process__prepare(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__prepare(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 62, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":61
+ *                     self._process__auth(mtype)
+ * 
+ *                 elif state == PROTOCOL_PREPARE:             # <<<<<<<<<<<<<<
+ *                     self._process__prepare(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":64
+ *                     self._process__prepare(mtype)
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE:             # <<<<<<<<<<<<<<
+ *                     self._process__bind_execute(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":65
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE:
+ *                     self._process__bind_execute(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE_MANY:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__bind_execute(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 65, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":64
+ *                     self._process__prepare(mtype)
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE:             # <<<<<<<<<<<<<<
+ *                     self._process__bind_execute(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":67
+ *                     self._process__bind_execute(mtype)
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE_MANY:             # <<<<<<<<<<<<<<
+ *                     self._process__bind_execute_many(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE_MANY) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":68
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE_MANY:
+ *                     self._process__bind_execute_many(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_EXECUTE:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__bind_execute_many(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 68, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":67
+ *                     self._process__bind_execute(mtype)
+ * 
+ *                 elif state == PROTOCOL_BIND_EXECUTE_MANY:             # <<<<<<<<<<<<<<
+ *                     self._process__bind_execute_many(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":70
+ *                     self._process__bind_execute_many(mtype)
+ * 
+ *                 elif state == PROTOCOL_EXECUTE:             # <<<<<<<<<<<<<<
+ *                     self._process__bind_execute(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_EXECUTE) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":71
+ * 
+ *                 elif state == PROTOCOL_EXECUTE:
+ *                     self._process__bind_execute(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_BIND:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__bind_execute(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 71, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":70
+ *                     self._process__bind_execute_many(mtype)
+ * 
+ *                 elif state == PROTOCOL_EXECUTE:             # <<<<<<<<<<<<<<
+ *                     self._process__bind_execute(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":73
+ *                     self._process__bind_execute(mtype)
+ * 
+ *                 elif state == PROTOCOL_BIND:             # <<<<<<<<<<<<<<
+ *                     self._process__bind(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":74
+ * 
+ *                 elif state == PROTOCOL_BIND:
+ *                     self._process__bind(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_CLOSE_STMT_PORTAL:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__bind(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 74, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":73
+ *                     self._process__bind_execute(mtype)
+ * 
+ *                 elif state == PROTOCOL_BIND:             # <<<<<<<<<<<<<<
+ *                     self._process__bind(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":76
+ *                     self._process__bind(mtype)
+ * 
+ *                 elif state == PROTOCOL_CLOSE_STMT_PORTAL:             # <<<<<<<<<<<<<<
+ *                     self._process__close_stmt_portal(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CLOSE_STMT_PORTAL) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":77
+ * 
+ *                 elif state == PROTOCOL_CLOSE_STMT_PORTAL:
+ *                     self._process__close_stmt_portal(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_SIMPLE_QUERY:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__close_stmt_portal(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 77, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":76
+ *                     self._process__bind(mtype)
+ * 
+ *                 elif state == PROTOCOL_CLOSE_STMT_PORTAL:             # <<<<<<<<<<<<<<
+ *                     self._process__close_stmt_portal(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":79
+ *                     self._process__close_stmt_portal(mtype)
+ * 
+ *                 elif state == PROTOCOL_SIMPLE_QUERY:             # <<<<<<<<<<<<<<
+ *                     self._process__simple_query(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_SIMPLE_QUERY) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":80
+ * 
+ *                 elif state == PROTOCOL_SIMPLE_QUERY:
+ *                     self._process__simple_query(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_COPY_OUT:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__simple_query(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 80, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":79
+ *                     self._process__close_stmt_portal(mtype)
+ * 
+ *                 elif state == PROTOCOL_SIMPLE_QUERY:             # <<<<<<<<<<<<<<
+ *                     self._process__simple_query(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":82
+ *                     self._process__simple_query(mtype)
+ * 
+ *                 elif state == PROTOCOL_COPY_OUT:             # <<<<<<<<<<<<<<
+ *                     self._process__copy_out(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":83
+ * 
+ *                 elif state == PROTOCOL_COPY_OUT:
+ *                     self._process__copy_out(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif (state == PROTOCOL_COPY_OUT_DATA or
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__copy_out(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 83, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":82
+ *                     self._process__simple_query(mtype)
+ * 
+ *                 elif state == PROTOCOL_COPY_OUT:             # <<<<<<<<<<<<<<
+ *                     self._process__copy_out(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":85
+ *                     self._process__copy_out(mtype)
+ * 
+ *                 elif (state == PROTOCOL_COPY_OUT_DATA or             # <<<<<<<<<<<<<<
+ *                         state == PROTOCOL_COPY_OUT_DONE):
+ *                     self._process__copy_out_data(mtype)
+ */
+          switch (__pyx_v_state) {
+            case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DATA:
+            case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DONE:
+
+            /* "asyncpg/protocol/coreproto.pyx":86
+ * 
+ *                 elif (state == PROTOCOL_COPY_OUT_DATA or
+ *                         state == PROTOCOL_COPY_OUT_DONE):             # <<<<<<<<<<<<<<
+ *                     self._process__copy_out_data(mtype)
+ * 
+ */
+            __pyx_t_3 = 1;
+
+            /* "asyncpg/protocol/coreproto.pyx":85
+ *                     self._process__copy_out(mtype)
+ * 
+ *                 elif (state == PROTOCOL_COPY_OUT_DATA or             # <<<<<<<<<<<<<<
+ *                         state == PROTOCOL_COPY_OUT_DONE):
+ *                     self._process__copy_out_data(mtype)
+ */
+            break;
+            default:
+            __pyx_t_3 = 0;
+            break;
+          }
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":87
+ *                 elif (state == PROTOCOL_COPY_OUT_DATA or
+ *                         state == PROTOCOL_COPY_OUT_DONE):
+ *                     self._process__copy_out_data(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_COPY_IN:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__copy_out_data(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 87, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":85
+ *                     self._process__copy_out(mtype)
+ * 
+ *                 elif (state == PROTOCOL_COPY_OUT_DATA or             # <<<<<<<<<<<<<<
+ *                         state == PROTOCOL_COPY_OUT_DONE):
+ *                     self._process__copy_out_data(mtype)
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":89
+ *                     self._process__copy_out_data(mtype)
+ * 
+ *                 elif state == PROTOCOL_COPY_IN:             # <<<<<<<<<<<<<<
+ *                     self._process__copy_in(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":90
+ * 
+ *                 elif state == PROTOCOL_COPY_IN:
+ *                     self._process__copy_in(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_COPY_IN_DATA:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__copy_in(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 90, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":89
+ *                     self._process__copy_out_data(mtype)
+ * 
+ *                 elif state == PROTOCOL_COPY_IN:             # <<<<<<<<<<<<<<
+ *                     self._process__copy_in(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":92
+ *                     self._process__copy_in(mtype)
+ * 
+ *                 elif state == PROTOCOL_COPY_IN_DATA:             # <<<<<<<<<<<<<<
+ *                     self._process__copy_in_data(mtype)
+ * 
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN_DATA) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":93
+ * 
+ *                 elif state == PROTOCOL_COPY_IN_DATA:
+ *                     self._process__copy_in_data(mtype)             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_CANCELLED:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_process__copy_in_data(__pyx_v_self, __pyx_v_mtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 93, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":92
+ *                     self._process__copy_in(mtype)
+ * 
+ *                 elif state == PROTOCOL_COPY_IN_DATA:             # <<<<<<<<<<<<<<
+ *                     self._process__copy_in_data(mtype)
+ * 
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":95
+ *                     self._process__copy_in_data(mtype)
+ * 
+ *                 elif state == PROTOCOL_CANCELLED:             # <<<<<<<<<<<<<<
+ *                     # discard all messages until the sync message
+ *                     if mtype == b'E':
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CANCELLED) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":97
+ *                 elif state == PROTOCOL_CANCELLED:
+ *                     # discard all messages until the sync message
+ *                     if mtype == b'E':             # <<<<<<<<<<<<<<
+ *                         self._parse_msg_error_response(True)
+ *                     elif mtype == b'Z':
+ */
+            switch (__pyx_v_mtype) {
+              case 'E':
+
+              /* "asyncpg/protocol/coreproto.pyx":98
+ *                     # discard all messages until the sync message
+ *                     if mtype == b'E':
+ *                         self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ *                     elif mtype == b'Z':
+ *                         self._parse_msg_ready_for_query()
+ */
+              __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 98, __pyx_L10_error)
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+              /* "asyncpg/protocol/coreproto.pyx":97
+ *                 elif state == PROTOCOL_CANCELLED:
+ *                     # discard all messages until the sync message
+ *                     if mtype == b'E':             # <<<<<<<<<<<<<<
+ *                         self._parse_msg_error_response(True)
+ *                     elif mtype == b'Z':
+ */
+              break;
+              case 'Z':
+
+              /* "asyncpg/protocol/coreproto.pyx":100
+ *                         self._parse_msg_error_response(True)
+ *                     elif mtype == b'Z':
+ *                         self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *                         self._push_result()
+ *                     else:
+ */
+              __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 100, __pyx_L10_error)
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+              /* "asyncpg/protocol/coreproto.pyx":101
+ *                     elif mtype == b'Z':
+ *                         self._parse_msg_ready_for_query()
+ *                         self._push_result()             # <<<<<<<<<<<<<<
+ *                     else:
+ *                         self.buffer.discard_message()
+ */
+              __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 101, __pyx_L10_error)
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+              /* "asyncpg/protocol/coreproto.pyx":99
+ *                     if mtype == b'E':
+ *                         self._parse_msg_error_response(True)
+ *                     elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *                         self._parse_msg_ready_for_query()
+ *                         self._push_result()
+ */
+              break;
+              default:
+
+              /* "asyncpg/protocol/coreproto.pyx":103
+ *                         self._push_result()
+ *                     else:
+ *                         self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_ERROR_CONSUME:
+ */
+              __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 103, __pyx_L10_error)
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+              break;
+            }
+
+            /* "asyncpg/protocol/coreproto.pyx":95
+ *                     self._process__copy_in_data(mtype)
+ * 
+ *                 elif state == PROTOCOL_CANCELLED:             # <<<<<<<<<<<<<<
+ *                     # discard all messages until the sync message
+ *                     if mtype == b'E':
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":105
+ *                         self.buffer.discard_message()
+ * 
+ *                 elif state == PROTOCOL_ERROR_CONSUME:             # <<<<<<<<<<<<<<
+ *                     # Error in protocol (on asyncpg side);
+ *                     # discard all messages until sync message
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_ERROR_CONSUME) != 0);
+          if (__pyx_t_3) {
+
+            /* "asyncpg/protocol/coreproto.pyx":109
+ *                     # discard all messages until sync message
+ * 
+ *                     if mtype == b'Z':             # <<<<<<<<<<<<<<
+ *                         # Sync point, self to push the result
+ *                         if self.result_type != RESULT_FAILED:
+ */
+            __pyx_t_3 = ((__pyx_v_mtype == 'Z') != 0);
+            if (__pyx_t_3) {
+
+              /* "asyncpg/protocol/coreproto.pyx":111
+ *                     if mtype == b'Z':
+ *                         # Sync point, self to push the result
+ *                         if self.result_type != RESULT_FAILED:             # <<<<<<<<<<<<<<
+ *                             self.result_type = RESULT_FAILED
+ *                             self.result = apg_exc.InternalClientError(
+ */
+              __pyx_t_3 = ((__pyx_v_self->result_type != __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED) != 0);
+              if (__pyx_t_3) {
+
+                /* "asyncpg/protocol/coreproto.pyx":112
+ *                         # Sync point, self to push the result
+ *                         if self.result_type != RESULT_FAILED:
+ *                             self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *                             self.result = apg_exc.InternalClientError(
+ *                                 'unknown error in protocol implementation')
+ */
+                __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+                /* "asyncpg/protocol/coreproto.pyx":113
+ *                         if self.result_type != RESULT_FAILED:
+ *                             self.result_type = RESULT_FAILED
+ *                             self.result = apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                                 'unknown error in protocol implementation')
+ * 
+ */
+                __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 113, __pyx_L10_error)
+                __Pyx_GOTREF(__pyx_t_1);
+                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 113, __pyx_L10_error)
+                __Pyx_GOTREF(__pyx_t_9);
+                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+                __pyx_t_1 = NULL;
+                if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
+                  __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9);
+                  if (likely(__pyx_t_1)) {
+                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+                    __Pyx_INCREF(__pyx_t_1);
+                    __Pyx_INCREF(function);
+                    __Pyx_DECREF_SET(__pyx_t_9, function);
+                  }
+                }
+                __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_1, __pyx_kp_u_unknown_error_in_protocol_implem) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_kp_u_unknown_error_in_protocol_implem);
+                __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+                if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 113, __pyx_L10_error)
+                __Pyx_GOTREF(__pyx_t_8);
+                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+                __Pyx_GIVEREF(__pyx_t_8);
+                __Pyx_GOTREF(__pyx_v_self->result);
+                __Pyx_DECREF(__pyx_v_self->result);
+                __pyx_v_self->result = __pyx_t_8;
+                __pyx_t_8 = 0;
+
+                /* "asyncpg/protocol/coreproto.pyx":111
+ *                     if mtype == b'Z':
+ *                         # Sync point, self to push the result
+ *                         if self.result_type != RESULT_FAILED:             # <<<<<<<<<<<<<<
+ *                             self.result_type = RESULT_FAILED
+ *                             self.result = apg_exc.InternalClientError(
+ */
+              }
+
+              /* "asyncpg/protocol/coreproto.pyx":116
+ *                                 'unknown error in protocol implementation')
+ * 
+ *                         self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *                     else:
+ */
+              __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 116, __pyx_L10_error)
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+              /* "asyncpg/protocol/coreproto.pyx":109
+ *                     # discard all messages until sync message
+ * 
+ *                     if mtype == b'Z':             # <<<<<<<<<<<<<<
+ *                         # Sync point, self to push the result
+ *                         if self.result_type != RESULT_FAILED:
+ */
+              goto __pyx_L19;
+            }
+
+            /* "asyncpg/protocol/coreproto.pyx":119
+ * 
+ *                     else:
+ *                         self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *                 elif state == PROTOCOL_TERMINATING:
+ */
+            /*else*/ {
+              __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 119, __pyx_L10_error)
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+            }
+            __pyx_L19:;
+
+            /* "asyncpg/protocol/coreproto.pyx":105
+ *                         self.buffer.discard_message()
+ * 
+ *                 elif state == PROTOCOL_ERROR_CONSUME:             # <<<<<<<<<<<<<<
+ *                     # Error in protocol (on asyncpg side);
+ *                     # discard all messages until sync message
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":121
+ *                         self.buffer.discard_message()
+ * 
+ *                 elif state == PROTOCOL_TERMINATING:             # <<<<<<<<<<<<<<
+ *                     # The connection is being terminated.
+ *                     # discard all messages until connection
+ */
+          __pyx_t_3 = ((__pyx_v_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_TERMINATING) != 0);
+          if (likely(__pyx_t_3)) {
+
+            /* "asyncpg/protocol/coreproto.pyx":125
+ *                     # discard all messages until connection
+ *                     # termination.
+ *                     self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *                 else:
+ */
+            __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 125, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":121
+ *                         self.buffer.discard_message()
+ * 
+ *                 elif state == PROTOCOL_TERMINATING:             # <<<<<<<<<<<<<<
+ *                     # The connection is being terminated.
+ *                     # discard all messages until connection
+ */
+            goto __pyx_L18;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":128
+ * 
+ *                 else:
+ *                     raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                         f'cannot process message {chr(mtype)!r}: '
+ *                         f'protocol is in an unexpected state {state!r}.')
+ */
+          /*else*/ {
+            __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 128, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_9);
+            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 128, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_1);
+            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+            /* "asyncpg/protocol/coreproto.pyx":129
+ *                 else:
+ *                     raise apg_exc.InternalClientError(
+ *                         f'cannot process message {chr(mtype)!r}: '             # <<<<<<<<<<<<<<
+ *                         f'protocol is in an unexpected state {state!r}.')
+ * 
+ */
+            __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 129, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_9);
+            __pyx_t_10 = 0;
+            __pyx_t_11 = 127;
+            __Pyx_INCREF(__pyx_kp_u_cannot_process_message);
+            __pyx_t_10 += 23;
+            __Pyx_GIVEREF(__pyx_kp_u_cannot_process_message);
+            PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_kp_u_cannot_process_message);
+            __pyx_t_12 = __Pyx_PyInt_From_char(__pyx_v_mtype); if (unlikely(!__pyx_t_12)) __PYX_ERR(5, 129, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_12);
+            __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(5, 129, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_13);
+            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __pyx_t_12 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_t_13), __pyx_empty_unicode); if (unlikely(!__pyx_t_12)) __PYX_ERR(5, 129, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_12);
+            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+            __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) : __pyx_t_11;
+            __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12);
+            __Pyx_GIVEREF(__pyx_t_12);
+            PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_12);
+            __pyx_t_12 = 0;
+            __Pyx_INCREF(__pyx_kp_u_protocol_is_in_an_unexpected_st);
+            __pyx_t_10 += 37;
+            __Pyx_GIVEREF(__pyx_kp_u_protocol_is_in_an_unexpected_st);
+            PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_kp_u_protocol_is_in_an_unexpected_st);
+
+            /* "asyncpg/protocol/coreproto.pyx":130
+ *                     raise apg_exc.InternalClientError(
+ *                         f'cannot process message {chr(mtype)!r}: '
+ *                         f'protocol is in an unexpected state {state!r}.')             # <<<<<<<<<<<<<<
+ * 
+ *             except Exception as ex:
+ */
+            __pyx_t_12 = __Pyx_PyUnicode_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_state, 0, ' ', 'd'); if (unlikely(!__pyx_t_12)) __PYX_ERR(5, 130, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_12);
+            __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) : __pyx_t_11;
+            __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12);
+            __Pyx_GIVEREF(__pyx_t_12);
+            PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_12);
+            __pyx_t_12 = 0;
+            __Pyx_INCREF(__pyx_kp_u__24);
+            __pyx_t_10 += 1;
+            __Pyx_GIVEREF(__pyx_kp_u__24);
+            PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_kp_u__24);
+
+            /* "asyncpg/protocol/coreproto.pyx":129
+ *                 else:
+ *                     raise apg_exc.InternalClientError(
+ *                         f'cannot process message {chr(mtype)!r}: '             # <<<<<<<<<<<<<<
+ *                         f'protocol is in an unexpected state {state!r}.')
+ * 
+ */
+            __pyx_t_12 = __Pyx_PyUnicode_Join(__pyx_t_9, 5, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(5, 129, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_12);
+            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+            __pyx_t_9 = NULL;
+            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
+              __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
+              if (likely(__pyx_t_9)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
+                __Pyx_INCREF(__pyx_t_9);
+                __Pyx_INCREF(function);
+                __Pyx_DECREF_SET(__pyx_t_1, function);
+              }
+            }
+            __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_12);
+            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+            if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 128, __pyx_L10_error)
+            __Pyx_GOTREF(__pyx_t_8);
+            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+            __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __PYX_ERR(5, 128, __pyx_L10_error)
+          }
+          __pyx_L18:;
+
+          /* "asyncpg/protocol/coreproto.pyx":45
+ *             state = self.state
+ * 
+ *             try:             # <<<<<<<<<<<<<<
+ *                 if mtype == b'S':
+ *                     # ParameterStatus
+ */
+        }
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        goto __pyx_L17_try_end;
+        __pyx_L10_error:;
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/coreproto.pyx":132
+ *                         f'protocol is in an unexpected state {state!r}.')
+ * 
+ *             except Exception as ex:             # <<<<<<<<<<<<<<
+ *                 self.result_type = RESULT_FAILED
+ *                 self.result = ex
+ */
+        __pyx_t_14 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+        if (__pyx_t_14) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._read_server_messages", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_1, &__pyx_t_12) < 0) __PYX_ERR(5, 132, __pyx_L12_except_error)
+          __Pyx_GOTREF(__pyx_t_8);
+          __Pyx_GOTREF(__pyx_t_1);
+          __Pyx_GOTREF(__pyx_t_12);
+          __Pyx_INCREF(__pyx_t_1);
+          __pyx_v_ex = __pyx_t_1;
+          /*try:*/ {
+
+            /* "asyncpg/protocol/coreproto.pyx":133
+ * 
+ *             except Exception as ex:
+ *                 self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *                 self.result = ex
+ * 
+ */
+            __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+            /* "asyncpg/protocol/coreproto.pyx":134
+ *             except Exception as ex:
+ *                 self.result_type = RESULT_FAILED
+ *                 self.result = ex             # <<<<<<<<<<<<<<
+ * 
+ *                 if mtype == b'Z':
+ */
+            __Pyx_INCREF(__pyx_v_ex);
+            __Pyx_GIVEREF(__pyx_v_ex);
+            __Pyx_GOTREF(__pyx_v_self->result);
+            __Pyx_DECREF(__pyx_v_self->result);
+            __pyx_v_self->result = __pyx_v_ex;
+
+            /* "asyncpg/protocol/coreproto.pyx":136
+ *                 self.result = ex
+ * 
+ *                 if mtype == b'Z':             # <<<<<<<<<<<<<<
+ *                     self._push_result()
+ *                 else:
+ */
+            __pyx_t_3 = ((__pyx_v_mtype == 'Z') != 0);
+            if (__pyx_t_3) {
+
+              /* "asyncpg/protocol/coreproto.pyx":137
+ * 
+ *                 if mtype == b'Z':
+ *                     self._push_result()             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     self.state = PROTOCOL_ERROR_CONSUME
+ */
+              __pyx_t_9 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 137, __pyx_L26_error)
+              __Pyx_GOTREF(__pyx_t_9);
+              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+              /* "asyncpg/protocol/coreproto.pyx":136
+ *                 self.result = ex
+ * 
+ *                 if mtype == b'Z':             # <<<<<<<<<<<<<<
+ *                     self._push_result()
+ *                 else:
+ */
+              goto __pyx_L28;
+            }
+
+            /* "asyncpg/protocol/coreproto.pyx":139
+ *                     self._push_result()
+ *                 else:
+ *                     self.state = PROTOCOL_ERROR_CONSUME             # <<<<<<<<<<<<<<
+ * 
+ *             finally:
+ */
+            /*else*/ {
+              __pyx_v_self->state = __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_ERROR_CONSUME;
+            }
+            __pyx_L28:;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":132
+ *                         f'protocol is in an unexpected state {state!r}.')
+ * 
+ *             except Exception as ex:             # <<<<<<<<<<<<<<
+ *                 self.result_type = RESULT_FAILED
+ *                 self.result = ex
+ */
+          /*finally:*/ {
+            /*normal exit:*/{
+              __Pyx_DECREF(__pyx_v_ex);
+              __pyx_v_ex = NULL;
+              goto __pyx_L27;
+            }
+            __pyx_L26_error:;
+            /*exception exit:*/{
+              __Pyx_PyThreadState_declare
+              __Pyx_PyThreadState_assign
+              __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;
+              __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+              if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_21, &__pyx_t_22);
+              if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19) < 0)) __Pyx_ErrFetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
+              __Pyx_XGOTREF(__pyx_t_17);
+              __Pyx_XGOTREF(__pyx_t_18);
+              __Pyx_XGOTREF(__pyx_t_19);
+              __Pyx_XGOTREF(__pyx_t_20);
+              __Pyx_XGOTREF(__pyx_t_21);
+              __Pyx_XGOTREF(__pyx_t_22);
+              __pyx_t_14 = __pyx_lineno; __pyx_t_15 = __pyx_clineno; __pyx_t_16 = __pyx_filename;
+              {
+                __Pyx_DECREF(__pyx_v_ex);
+                __pyx_v_ex = NULL;
+              }
+              if (PY_MAJOR_VERSION >= 3) {
+                __Pyx_XGIVEREF(__pyx_t_20);
+                __Pyx_XGIVEREF(__pyx_t_21);
+                __Pyx_XGIVEREF(__pyx_t_22);
+                __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_21, __pyx_t_22);
+              }
+              __Pyx_XGIVEREF(__pyx_t_17);
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_ErrRestore(__pyx_t_17, __pyx_t_18, __pyx_t_19);
+              __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;
+              __pyx_lineno = __pyx_t_14; __pyx_clineno = __pyx_t_15; __pyx_filename = __pyx_t_16;
+              goto __pyx_L12_except_error;
+            }
+            __pyx_L27:;
+          }
+          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          goto __pyx_L11_exception_handled;
+        }
+        goto __pyx_L12_except_error;
+        __pyx_L12_except_error:;
+
+        /* "asyncpg/protocol/coreproto.pyx":45
+ *             state = self.state
+ * 
+ *             try:             # <<<<<<<<<<<<<<
+ *                 if mtype == b'S':
+ *                     # ParameterStatus
+ */
+        __Pyx_XGIVEREF(__pyx_t_5);
+        __Pyx_XGIVEREF(__pyx_t_6);
+        __Pyx_XGIVEREF(__pyx_t_7);
+        __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
+        goto __pyx_L8_error;
+        __pyx_L11_exception_handled:;
+        __Pyx_XGIVEREF(__pyx_t_5);
+        __Pyx_XGIVEREF(__pyx_t_6);
+        __Pyx_XGIVEREF(__pyx_t_7);
+        __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
+        __pyx_L17_try_end:;
+      }
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":142
+ * 
+ *             finally:
+ *                 self.buffer.finish_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__auth(self, char mtype):
+ */
+    /*finally:*/ {
+      /*normal exit:*/{
+        __pyx_t_12 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->finish_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_12)) __PYX_ERR(5, 142, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_12);
+        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+        goto __pyx_L9;
+      }
+      __pyx_L8_error:;
+      /*exception exit:*/{
+        __Pyx_PyThreadState_declare
+        __Pyx_PyThreadState_assign
+        __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_22 = 0; __pyx_t_21 = 0; __pyx_t_20 = 0;
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_22, &__pyx_t_21, &__pyx_t_20);
+        if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5);
+        __Pyx_XGOTREF(__pyx_t_7);
+        __Pyx_XGOTREF(__pyx_t_6);
+        __Pyx_XGOTREF(__pyx_t_5);
+        __Pyx_XGOTREF(__pyx_t_22);
+        __Pyx_XGOTREF(__pyx_t_21);
+        __Pyx_XGOTREF(__pyx_t_20);
+        __pyx_t_15 = __pyx_lineno; __pyx_t_14 = __pyx_clineno; __pyx_t_23 = __pyx_filename;
+        {
+          __pyx_t_12 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->finish_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_12)) __PYX_ERR(5, 142, __pyx_L36_error)
+          __Pyx_GOTREF(__pyx_t_12);
+          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+        }
+        if (PY_MAJOR_VERSION >= 3) {
+          __Pyx_XGIVEREF(__pyx_t_22);
+          __Pyx_XGIVEREF(__pyx_t_21);
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_21, __pyx_t_20);
+        }
+        __Pyx_XGIVEREF(__pyx_t_7);
+        __Pyx_XGIVEREF(__pyx_t_6);
+        __Pyx_XGIVEREF(__pyx_t_5);
+        __Pyx_ErrRestore(__pyx_t_7, __pyx_t_6, __pyx_t_5);
+        __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_22 = 0; __pyx_t_21 = 0; __pyx_t_20 = 0;
+        __pyx_lineno = __pyx_t_15; __pyx_clineno = __pyx_t_14; __pyx_filename = __pyx_t_23;
+        goto __pyx_L1_error;
+        __pyx_L36_error:;
+        if (PY_MAJOR_VERSION >= 3) {
+          __Pyx_XGIVEREF(__pyx_t_22);
+          __Pyx_XGIVEREF(__pyx_t_21);
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_21, __pyx_t_20);
+        }
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __pyx_t_22 = 0; __pyx_t_21 = 0; __pyx_t_20 = 0;
+        goto __pyx_L1_error;
+      }
+      __pyx_L9:;
+    }
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":32
+ *         self._reset_result()
+ * 
+ *     cdef _read_server_messages(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             char mtype
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._read_server_messages", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_ex);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":144
+ *                 self.buffer.finish_message()
+ * 
+ *     cdef _process__auth(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'R':
+ *             # Authentication...
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__auth(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_process__auth", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":145
+ * 
+ *     cdef _process__auth(self, char mtype):
+ *         if mtype == b'R':             # <<<<<<<<<<<<<<
+ *             # Authentication...
+ *             self._parse_msg_authentication()
+ */
+  switch (__pyx_v_mtype) {
+    case 'R':
+
+    /* "asyncpg/protocol/coreproto.pyx":147
+ *         if mtype == b'R':
+ *             # Authentication...
+ *             self._parse_msg_authentication()             # <<<<<<<<<<<<<<
+ *             if self.result_type != RESULT_OK:
+ *                 self.con_status = CONNECTION_BAD
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_authentication(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 147, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":148
+ *             # Authentication...
+ *             self._parse_msg_authentication()
+ *             if self.result_type != RESULT_OK:             # <<<<<<<<<<<<<<
+ *                 self.con_status = CONNECTION_BAD
+ *                 self._push_result()
+ */
+    __pyx_t_2 = ((__pyx_v_self->result_type != __pyx_e_7asyncpg_8protocol_8protocol_RESULT_OK) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/coreproto.pyx":149
+ *             self._parse_msg_authentication()
+ *             if self.result_type != RESULT_OK:
+ *                 self.con_status = CONNECTION_BAD             # <<<<<<<<<<<<<<
+ *                 self._push_result()
+ * 
+ */
+      __pyx_v_self->con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD;
+
+      /* "asyncpg/protocol/coreproto.pyx":150
+ *             if self.result_type != RESULT_OK:
+ *                 self.con_status = CONNECTION_BAD
+ *                 self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.auth_msg is not None:
+ */
+      __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 150, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":148
+ *             # Authentication...
+ *             self._parse_msg_authentication()
+ *             if self.result_type != RESULT_OK:             # <<<<<<<<<<<<<<
+ *                 self.con_status = CONNECTION_BAD
+ *                 self._push_result()
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":152
+ *                 self._push_result()
+ * 
+ *             elif self.auth_msg is not None:             # <<<<<<<<<<<<<<
+ *                 # Server wants us to send auth data, so do that.
+ *                 self._write(self.auth_msg)
+ */
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_auth_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 152, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_2 = (__pyx_t_1 != Py_None);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_3 = (__pyx_t_2 != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/protocol/coreproto.pyx":154
+ *             elif self.auth_msg is not None:
+ *                 # Server wants us to send auth data, so do that.
+ *                 self._write(self.auth_msg)             # <<<<<<<<<<<<<<
+ *                 self.auth_msg = None
+ * 
+ */
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_auth_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 154, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 154, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":155
+ *                 # Server wants us to send auth data, so do that.
+ *                 self._write(self.auth_msg)
+ *                 self.auth_msg = None             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'K':
+ */
+      if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_auth_msg, Py_None) < 0) __PYX_ERR(5, 155, __pyx_L1_error)
+
+      /* "asyncpg/protocol/coreproto.pyx":152
+ *                 self._push_result()
+ * 
+ *             elif self.auth_msg is not None:             # <<<<<<<<<<<<<<
+ *                 # Server wants us to send auth data, so do that.
+ *                 self._write(self.auth_msg)
+ */
+    }
+    __pyx_L3:;
+
+    /* "asyncpg/protocol/coreproto.pyx":145
+ * 
+ *     cdef _process__auth(self, char mtype):
+ *         if mtype == b'R':             # <<<<<<<<<<<<<<
+ *             # Authentication...
+ *             self._parse_msg_authentication()
+ */
+    break;
+    case 'K':
+
+    /* "asyncpg/protocol/coreproto.pyx":159
+ *         elif mtype == b'K':
+ *             # BackendKeyData
+ *             self._parse_msg_backend_key_data()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'E':
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_backend_key_data(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 159, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":157
+ *                 self.auth_msg = None
+ * 
+ *         elif mtype == b'K':             # <<<<<<<<<<<<<<
+ *             # BackendKeyData
+ *             self._parse_msg_backend_key_data()
+ */
+    break;
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":163
+ *         elif mtype == b'E':
+ *             # ErrorResponse
+ *             self.con_status = CONNECTION_BAD             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ *             self._push_result()
+ */
+    __pyx_v_self->con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD;
+
+    /* "asyncpg/protocol/coreproto.pyx":164
+ *             # ErrorResponse
+ *             self.con_status = CONNECTION_BAD
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 164, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":165
+ *             self.con_status = CONNECTION_BAD
+ *             self._parse_msg_error_response(True)
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 165, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":161
+ *             self._parse_msg_backend_key_data()
+ * 
+ *         elif mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self.con_status = CONNECTION_BAD
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":169
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self.con_status = CONNECTION_OK
+ *             self._push_result()
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 169, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":170
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self.con_status = CONNECTION_OK             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_v_self->con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_OK;
+
+    /* "asyncpg/protocol/coreproto.pyx":171
+ *             self._parse_msg_ready_for_query()
+ *             self.con_status = CONNECTION_OK
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__prepare(self, char mtype):
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 171, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":167
+ *             self._push_result()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":144
+ *                 self.buffer.finish_message()
+ * 
+ *     cdef _process__auth(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'R':
+ *             # Authentication...
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__auth", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":173
+ *             self._push_result()
+ * 
+ *     cdef _process__prepare(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b't':
+ *             # Parameters description
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__prepare", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":174
+ * 
+ *     cdef _process__prepare(self, char mtype):
+ *         if mtype == b't':             # <<<<<<<<<<<<<<
+ *             # Parameters description
+ *             self.result_param_desc = self.buffer.consume_message()
+ */
+  switch (__pyx_v_mtype) {
+    case 't':
+
+    /* "asyncpg/protocol/coreproto.pyx":176
+ *         if mtype == b't':
+ *             # Parameters description
+ *             self.result_param_desc = self.buffer.consume_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'1':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->consume_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 176, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_GIVEREF(__pyx_t_1);
+    __Pyx_GOTREF(__pyx_v_self->result_param_desc);
+    __Pyx_DECREF(__pyx_v_self->result_param_desc);
+    __pyx_v_self->result_param_desc = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":174
+ * 
+ *     cdef _process__prepare(self, char mtype):
+ *         if mtype == b't':             # <<<<<<<<<<<<<<
+ *             # Parameters description
+ *             self.result_param_desc = self.buffer.consume_message()
+ */
+    break;
+    case '1':
+
+    /* "asyncpg/protocol/coreproto.pyx":180
+ *         elif mtype == b'1':
+ *             # ParseComplete
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'T':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 180, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":178
+ *             self.result_param_desc = self.buffer.consume_message()
+ * 
+ *         elif mtype == b'1':             # <<<<<<<<<<<<<<
+ *             # ParseComplete
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'T':
+
+    /* "asyncpg/protocol/coreproto.pyx":184
+ *         elif mtype == b'T':
+ *             # Row description
+ *             self.result_row_desc = self.buffer.consume_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'E':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->consume_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 184, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_GIVEREF(__pyx_t_1);
+    __Pyx_GOTREF(__pyx_v_self->result_row_desc);
+    __Pyx_DECREF(__pyx_v_self->result_row_desc);
+    __pyx_v_self->result_row_desc = ((PyObject*)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":182
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'T':             # <<<<<<<<<<<<<<
+ *             # Row description
+ *             self.result_row_desc = self.buffer.consume_message()
+ */
+    break;
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":188
+ *         elif mtype == b'E':
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 188, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":186
+ *             self.result_row_desc = self.buffer.consume_message()
+ * 
+ *         elif mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":192
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 192, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":193
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'n':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 193, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":190
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    case 'n':
+
+    /* "asyncpg/protocol/coreproto.pyx":197
+ *         elif mtype == b'n':
+ *             # NoData
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__bind_execute(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 197, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":195
+ *             self._push_result()
+ * 
+ *         elif mtype == b'n':             # <<<<<<<<<<<<<<
+ *             # NoData
+ *             self.buffer.discard_message()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":173
+ *             self._push_result()
+ * 
+ *     cdef _process__prepare(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b't':
+ *             # Parameters description
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":199
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__bind_execute(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'D':
+ *             # DataRow
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind_execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__bind_execute", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":200
+ * 
+ *     cdef _process__bind_execute(self, char mtype):
+ *         if mtype == b'D':             # <<<<<<<<<<<<<<
+ *             # DataRow
+ *             self._parse_data_msgs()
+ */
+  switch (__pyx_v_mtype) {
+    case 'D':
+
+    /* "asyncpg/protocol/coreproto.pyx":202
+ *         if mtype == b'D':
+ *             # DataRow
+ *             self._parse_data_msgs()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b's':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_data_msgs(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 202, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":200
+ * 
+ *     cdef _process__bind_execute(self, char mtype):
+ *         if mtype == b'D':             # <<<<<<<<<<<<<<
+ *             # DataRow
+ *             self._parse_data_msgs()
+ */
+    break;
+    case 's':
+
+    /* "asyncpg/protocol/coreproto.pyx":206
+ *         elif mtype == b's':
+ *             # PortalSuspended
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'C':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 206, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":204
+ *             self._parse_data_msgs()
+ * 
+ *         elif mtype == b's':             # <<<<<<<<<<<<<<
+ *             # PortalSuspended
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'C':
+
+    /* "asyncpg/protocol/coreproto.pyx":210
+ *         elif mtype == b'C':
+ *             # CommandComplete
+ *             self.result_execute_completed = True             # <<<<<<<<<<<<<<
+ *             self._parse_msg_command_complete()
+ * 
+ */
+    __pyx_v_self->result_execute_completed = 1;
+
+    /* "asyncpg/protocol/coreproto.pyx":211
+ *             # CommandComplete
+ *             self.result_execute_completed = True
+ *             self._parse_msg_command_complete()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'E':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_command_complete(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 211, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":208
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'C':             # <<<<<<<<<<<<<<
+ *             # CommandComplete
+ *             self.result_execute_completed = True
+ */
+    break;
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":215
+ *         elif mtype == b'E':
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'2':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 215, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":213
+ *             self._parse_msg_command_complete()
+ * 
+ *         elif mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+    break;
+    case '2':
+
+    /* "asyncpg/protocol/coreproto.pyx":219
+ *         elif mtype == b'2':
+ *             # BindComplete
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 219, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":217
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'2':             # <<<<<<<<<<<<<<
+ *             # BindComplete
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":223
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 223, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":224
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'I':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 224, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":221
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    case 'I':
+
+    /* "asyncpg/protocol/coreproto.pyx":228
+ *         elif mtype == b'I':
+ *             # EmptyQueryResponse
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__bind_execute_many(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 228, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":226
+ *             self._push_result()
+ * 
+ *         elif mtype == b'I':             # <<<<<<<<<<<<<<
+ *             # EmptyQueryResponse
+ *             self.buffer.discard_message()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":199
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__bind_execute(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'D':
+ *             # DataRow
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__bind_execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":230
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__bind_execute_many(self, char mtype):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind_execute_many(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  char const *__pyx_t_11;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  __Pyx_RefNannySetupContext("_process__bind_execute_many", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":233
+ *         cdef WriteBuffer buf
+ * 
+ *         if mtype == b'D':             # <<<<<<<<<<<<<<
+ *             # DataRow
+ *             self._parse_data_msgs()
+ */
+  switch (__pyx_v_mtype) {
+    case 'D':
+
+    /* "asyncpg/protocol/coreproto.pyx":235
+ *         if mtype == b'D':
+ *             # DataRow
+ *             self._parse_data_msgs()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b's':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_data_msgs(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 235, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":233
+ *         cdef WriteBuffer buf
+ * 
+ *         if mtype == b'D':             # <<<<<<<<<<<<<<
+ *             # DataRow
+ *             self._parse_data_msgs()
+ */
+    break;
+    case 's':
+
+    /* "asyncpg/protocol/coreproto.pyx":239
+ *         elif mtype == b's':
+ *             # PortalSuspended
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'C':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 239, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":237
+ *             self._parse_data_msgs()
+ * 
+ *         elif mtype == b's':             # <<<<<<<<<<<<<<
+ *             # PortalSuspended
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'C':
+
+    /* "asyncpg/protocol/coreproto.pyx":243
+ *         elif mtype == b'C':
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'E':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_command_complete(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 243, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":241
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'C':             # <<<<<<<<<<<<<<
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()
+ */
+    break;
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":247
+ *         elif mtype == b'E':
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'2':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 247, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":245
+ *             self._parse_msg_command_complete()
+ * 
+ *         elif mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+    break;
+    case '2':
+
+    /* "asyncpg/protocol/coreproto.pyx":251
+ *         elif mtype == b'2':
+ *             # BindComplete
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 251, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":249
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'2':             # <<<<<<<<<<<<<<
+ *             # BindComplete
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":255
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             if self.result_type == RESULT_FAILED:
+ *                 self._push_result()
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 255, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":256
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             if self.result_type == RESULT_FAILED:             # <<<<<<<<<<<<<<
+ *                 self._push_result()
+ *             else:
+ */
+    __pyx_t_2 = ((__pyx_v_self->result_type == __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/coreproto.pyx":257
+ *             self._parse_msg_ready_for_query()
+ *             if self.result_type == RESULT_FAILED:
+ *                 self._push_result()             # <<<<<<<<<<<<<<
+ *             else:
+ *                 try:
+ */
+      __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 257, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":256
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             if self.result_type == RESULT_FAILED:             # <<<<<<<<<<<<<<
+ *                 self._push_result()
+ *             else:
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":259
+ *                 self._push_result()
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     buf = <WriteBuffer>next(self._execute_iter)
+ *                 except StopIteration:
+ */
+    /*else*/ {
+      {
+        __Pyx_PyThreadState_declare
+        __Pyx_PyThreadState_assign
+        __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
+        __Pyx_XGOTREF(__pyx_t_3);
+        __Pyx_XGOTREF(__pyx_t_4);
+        __Pyx_XGOTREF(__pyx_t_5);
+        /*try:*/ {
+
+          /* "asyncpg/protocol/coreproto.pyx":260
+ *             else:
+ *                 try:
+ *                     buf = <WriteBuffer>next(self._execute_iter)             # <<<<<<<<<<<<<<
+ *                 except StopIteration:
+ *                     self._push_result()
+ */
+          __pyx_t_1 = __pyx_v_self->_execute_iter;
+          __Pyx_INCREF(__pyx_t_1);
+          __pyx_t_6 = __Pyx_PyIter_Next(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(5, 260, __pyx_L4_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+          __pyx_t_1 = __pyx_t_6;
+          __Pyx_INCREF(__pyx_t_1);
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+          __pyx_t_1 = 0;
+
+          /* "asyncpg/protocol/coreproto.pyx":259
+ *                 self._push_result()
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     buf = <WriteBuffer>next(self._execute_iter)
+ *                 except StopIteration:
+ */
+        }
+
+        /* "asyncpg/protocol/coreproto.pyx":269
+ *                 else:
+ *                     # Next iteration over the executemany() arg sequence
+ *                     self._send_bind_message(             # <<<<<<<<<<<<<<
+ *                         self._execute_portal_name, self._execute_stmt_name,
+ *                         buf, 0)
+ */
+        /*else:*/ {
+
+          /* "asyncpg/protocol/coreproto.pyx":270
+ *                     # Next iteration over the executemany() arg sequence
+ *                     self._send_bind_message(
+ *                         self._execute_portal_name, self._execute_stmt_name,             # <<<<<<<<<<<<<<
+ *                         buf, 0)
+ * 
+ */
+          __pyx_t_1 = __pyx_v_self->_execute_portal_name;
+          __Pyx_INCREF(__pyx_t_1);
+          __pyx_t_6 = __pyx_v_self->_execute_stmt_name;
+          __Pyx_INCREF(__pyx_t_6);
+
+          /* "asyncpg/protocol/coreproto.pyx":269
+ *                 else:
+ *                     # Next iteration over the executemany() arg sequence
+ *                     self._send_bind_message(             # <<<<<<<<<<<<<<
+ *                         self._execute_portal_name, self._execute_stmt_name,
+ *                         buf, 0)
+ */
+          __pyx_t_7 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_send_bind_message(__pyx_v_self, ((PyObject*)__pyx_t_1), ((PyObject*)__pyx_t_6), __pyx_v_buf, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 269, __pyx_L6_except_error)
+          __Pyx_GOTREF(__pyx_t_7);
+          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        }
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        goto __pyx_L9_try_end;
+        __pyx_L4_error:;
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+        /* "asyncpg/protocol/coreproto.pyx":261
+ *                 try:
+ *                     buf = <WriteBuffer>next(self._execute_iter)
+ *                 except StopIteration:             # <<<<<<<<<<<<<<
+ *                     self._push_result()
+ *                 except Exception as e:
+ */
+        __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_StopIteration);
+        if (__pyx_t_8) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_1) < 0) __PYX_ERR(5, 261, __pyx_L6_except_error)
+          __Pyx_GOTREF(__pyx_t_7);
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_GOTREF(__pyx_t_1);
+
+          /* "asyncpg/protocol/coreproto.pyx":262
+ *                     buf = <WriteBuffer>next(self._execute_iter)
+ *                 except StopIteration:
+ *                     self._push_result()             # <<<<<<<<<<<<<<
+ *                 except Exception as e:
+ *                     self.result_type = RESULT_FAILED
+ */
+          __pyx_t_9 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 262, __pyx_L6_except_error)
+          __Pyx_GOTREF(__pyx_t_9);
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+          goto __pyx_L5_exception_handled;
+        }
+
+        /* "asyncpg/protocol/coreproto.pyx":263
+ *                 except StopIteration:
+ *                     self._push_result()
+ *                 except Exception as e:             # <<<<<<<<<<<<<<
+ *                     self.result_type = RESULT_FAILED
+ *                     self.result = e
+ */
+        __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+        if (__pyx_t_8) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(5, 263, __pyx_L6_except_error)
+          __Pyx_GOTREF(__pyx_t_1);
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_GOTREF(__pyx_t_7);
+          __Pyx_INCREF(__pyx_t_6);
+          __pyx_v_e = __pyx_t_6;
+          /*try:*/ {
+
+            /* "asyncpg/protocol/coreproto.pyx":264
+ *                     self._push_result()
+ *                 except Exception as e:
+ *                     self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *                     self.result = e
+ *                     self._push_result()
+ */
+            __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+            /* "asyncpg/protocol/coreproto.pyx":265
+ *                 except Exception as e:
+ *                     self.result_type = RESULT_FAILED
+ *                     self.result = e             # <<<<<<<<<<<<<<
+ *                     self._push_result()
+ *                 else:
+ */
+            __Pyx_INCREF(__pyx_v_e);
+            __Pyx_GIVEREF(__pyx_v_e);
+            __Pyx_GOTREF(__pyx_v_self->result);
+            __Pyx_DECREF(__pyx_v_self->result);
+            __pyx_v_self->result = __pyx_v_e;
+
+            /* "asyncpg/protocol/coreproto.pyx":266
+ *                     self.result_type = RESULT_FAILED
+ *                     self.result = e
+ *                     self._push_result()             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     # Next iteration over the executemany() arg sequence
+ */
+            __pyx_t_9 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 266, __pyx_L17_error)
+            __Pyx_GOTREF(__pyx_t_9);
+            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          }
+
+          /* "asyncpg/protocol/coreproto.pyx":263
+ *                 except StopIteration:
+ *                     self._push_result()
+ *                 except Exception as e:             # <<<<<<<<<<<<<<
+ *                     self.result_type = RESULT_FAILED
+ *                     self.result = e
+ */
+          /*finally:*/ {
+            /*normal exit:*/{
+              __Pyx_DECREF(__pyx_v_e);
+              __pyx_v_e = NULL;
+              goto __pyx_L18;
+            }
+            __pyx_L17_error:;
+            /*exception exit:*/{
+              __Pyx_PyThreadState_declare
+              __Pyx_PyThreadState_assign
+              __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0;
+              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+              if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+              if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14) < 0)) __Pyx_ErrFetch(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
+              __Pyx_XGOTREF(__pyx_t_12);
+              __Pyx_XGOTREF(__pyx_t_13);
+              __Pyx_XGOTREF(__pyx_t_14);
+              __Pyx_XGOTREF(__pyx_t_15);
+              __Pyx_XGOTREF(__pyx_t_16);
+              __Pyx_XGOTREF(__pyx_t_17);
+              __pyx_t_8 = __pyx_lineno; __pyx_t_10 = __pyx_clineno; __pyx_t_11 = __pyx_filename;
+              {
+                __Pyx_DECREF(__pyx_v_e);
+                __pyx_v_e = NULL;
+              }
+              if (PY_MAJOR_VERSION >= 3) {
+                __Pyx_XGIVEREF(__pyx_t_15);
+                __Pyx_XGIVEREF(__pyx_t_16);
+                __Pyx_XGIVEREF(__pyx_t_17);
+                __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+              }
+              __Pyx_XGIVEREF(__pyx_t_12);
+              __Pyx_XGIVEREF(__pyx_t_13);
+              __Pyx_XGIVEREF(__pyx_t_14);
+              __Pyx_ErrRestore(__pyx_t_12, __pyx_t_13, __pyx_t_14);
+              __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0;
+              __pyx_lineno = __pyx_t_8; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_11;
+              goto __pyx_L6_except_error;
+            }
+            __pyx_L18:;
+          }
+          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+          goto __pyx_L5_exception_handled;
+        }
+        goto __pyx_L6_except_error;
+        __pyx_L6_except_error:;
+
+        /* "asyncpg/protocol/coreproto.pyx":259
+ *                 self._push_result()
+ *             else:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     buf = <WriteBuffer>next(self._execute_iter)
+ *                 except StopIteration:
+ */
+        __Pyx_XGIVEREF(__pyx_t_3);
+        __Pyx_XGIVEREF(__pyx_t_4);
+        __Pyx_XGIVEREF(__pyx_t_5);
+        __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+        goto __pyx_L1_error;
+        __pyx_L5_exception_handled:;
+        __Pyx_XGIVEREF(__pyx_t_3);
+        __Pyx_XGIVEREF(__pyx_t_4);
+        __Pyx_XGIVEREF(__pyx_t_5);
+        __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+        __pyx_L9_try_end:;
+      }
+    }
+    __pyx_L3:;
+
+    /* "asyncpg/protocol/coreproto.pyx":253
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    case 'I':
+
+    /* "asyncpg/protocol/coreproto.pyx":275
+ *         elif mtype == b'I':
+ *             # EmptyQueryResponse
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__bind(self, char mtype):
+ */
+    __pyx_t_7 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 275, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":273
+ *                         buf, 0)
+ * 
+ *         elif mtype == b'I':             # <<<<<<<<<<<<<<
+ *             # EmptyQueryResponse
+ *             self.buffer.discard_message()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":230
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__bind_execute_many(self, char mtype):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":277
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__bind(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             # ErrorResponse
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__bind", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":278
+ * 
+ *     cdef _process__bind(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+  switch (__pyx_v_mtype) {
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":280
+ *         if mtype == b'E':
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'2':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 280, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":278
+ * 
+ *     cdef _process__bind(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+    break;
+    case '2':
+
+    /* "asyncpg/protocol/coreproto.pyx":284
+ *         elif mtype == b'2':
+ *             # BindComplete
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 284, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":282
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'2':             # <<<<<<<<<<<<<<
+ *             # BindComplete
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":288
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 288, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":289
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__close_stmt_portal(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 289, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":286
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":277
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__bind(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             # ErrorResponse
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":291
+ *             self._push_result()
+ * 
+ *     cdef _process__close_stmt_portal(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             # ErrorResponse
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__close_stmt_portal(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__close_stmt_portal", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":292
+ * 
+ *     cdef _process__close_stmt_portal(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+  switch (__pyx_v_mtype) {
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":294
+ *         if mtype == b'E':
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'3':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 294, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":292
+ * 
+ *     cdef _process__close_stmt_portal(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+    break;
+    case '3':
+
+    /* "asyncpg/protocol/coreproto.pyx":298
+ *         elif mtype == b'3':
+ *             # CloseComplete
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 298, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":296
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'3':             # <<<<<<<<<<<<<<
+ *             # CloseComplete
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":302
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 302, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":303
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__simple_query(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 303, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":300
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":291
+ *             self._push_result()
+ * 
+ *     cdef _process__close_stmt_portal(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             # ErrorResponse
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__close_stmt_portal", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":305
+ *             self._push_result()
+ * 
+ *     cdef _process__simple_query(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype in {b'D', b'I', b'T'}:
+ *             # 'D' - DataRow
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__simple_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__simple_query", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":306
+ * 
+ *     cdef _process__simple_query(self, char mtype):
+ *         if mtype in {b'D', b'I', b'T'}:             # <<<<<<<<<<<<<<
+ *             # 'D' - DataRow
+ *             # 'I' - EmptyQueryResponse
+ */
+  switch (__pyx_v_mtype) {
+    case 'D':
+    case 'I':
+    case 'T':
+
+    /* "asyncpg/protocol/coreproto.pyx":310
+ *             # 'I' - EmptyQueryResponse
+ *             # 'T' - RowDescription
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'E':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 310, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":306
+ * 
+ *     cdef _process__simple_query(self, char mtype):
+ *         if mtype in {b'D', b'I', b'T'}:             # <<<<<<<<<<<<<<
+ *             # 'D' - DataRow
+ *             # 'I' - EmptyQueryResponse
+ */
+    break;
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":314
+ *         elif mtype == b'E':
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 314, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":312
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'E':             # <<<<<<<<<<<<<<
+ *             # ErrorResponse
+ *             self._parse_msg_error_response(True)
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":318
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 318, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":319
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'C':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 319, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":316
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    case 'C':
+
+    /* "asyncpg/protocol/coreproto.pyx":323
+ *         elif mtype == b'C':
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()             # <<<<<<<<<<<<<<
+ * 
+ *         else:
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_command_complete(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 323, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":321
+ *             self._push_result()
+ * 
+ *         elif mtype == b'C':             # <<<<<<<<<<<<<<
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/coreproto.pyx":327
+ *         else:
+ *             # We don't really care about COPY IN etc
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__copy_out(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 327, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":305
+ *             self._push_result()
+ * 
+ *     cdef _process__simple_query(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype in {b'D', b'I', b'T'}:
+ *             # 'D' - DataRow
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__simple_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":329
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__copy_out(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__copy_out", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":330
+ * 
+ *     cdef _process__copy_out(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+  switch (__pyx_v_mtype) {
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":331
+ *     cdef _process__copy_out(self, char mtype):
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'H':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 331, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":330
+ * 
+ *     cdef _process__copy_out(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+    break;
+    case 'H':
+
+    /* "asyncpg/protocol/coreproto.pyx":335
+ *         elif mtype == b'H':
+ *             # CopyOutResponse
+ *             self._set_state(PROTOCOL_COPY_OUT_DATA)             # <<<<<<<<<<<<<<
+ *             self.buffer.discard_message()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DATA); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 335, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":336
+ *             # CopyOutResponse
+ *             self._set_state(PROTOCOL_COPY_OUT_DATA)
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 336, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":333
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'H':             # <<<<<<<<<<<<<<
+ *             # CopyOutResponse
+ *             self._set_state(PROTOCOL_COPY_OUT_DATA)
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":340
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 340, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":341
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__copy_out_data(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 341, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":338
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":329
+ *             self.buffer.discard_message()
+ * 
+ *     cdef _process__copy_out(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":343
+ *             self._push_result()
+ * 
+ *     cdef _process__copy_out_data(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_out_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__copy_out_data", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":344
+ * 
+ *     cdef _process__copy_out_data(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+  switch (__pyx_v_mtype) {
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":345
+ *     cdef _process__copy_out_data(self, char mtype):
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'd':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 345, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":344
+ * 
+ *     cdef _process__copy_out_data(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+    break;
+    case 'd':
+
+    /* "asyncpg/protocol/coreproto.pyx":349
+ *         elif mtype == b'd':
+ *             # CopyData
+ *             self._parse_copy_data_msgs()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'c':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_copy_data_msgs(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 349, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":347
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'd':             # <<<<<<<<<<<<<<
+ *             # CopyData
+ *             self._parse_copy_data_msgs()
+ */
+    break;
+    case 'c':
+
+    /* "asyncpg/protocol/coreproto.pyx":353
+ *         elif mtype == b'c':
+ *             # CopyDone
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ *             self._set_state(PROTOCOL_COPY_OUT_DONE)
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 353, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":354
+ *             # CopyDone
+ *             self.buffer.discard_message()
+ *             self._set_state(PROTOCOL_COPY_OUT_DONE)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'C':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DONE); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 354, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":351
+ *             self._parse_copy_data_msgs()
+ * 
+ *         elif mtype == b'c':             # <<<<<<<<<<<<<<
+ *             # CopyDone
+ *             self.buffer.discard_message()
+ */
+    break;
+    case 'C':
+
+    /* "asyncpg/protocol/coreproto.pyx":358
+ *         elif mtype == b'C':
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_command_complete(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 358, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":356
+ *             self._set_state(PROTOCOL_COPY_OUT_DONE)
+ * 
+ *         elif mtype == b'C':             # <<<<<<<<<<<<<<
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":362
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 362, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":363
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__copy_in(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 363, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":360
+ *             self._parse_msg_command_complete()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":343
+ *             self._push_result()
+ * 
+ *     cdef _process__copy_out_data(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__copy_out_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":365
+ *             self._push_result()
+ * 
+ *     cdef _process__copy_in(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__copy_in", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":366
+ * 
+ *     cdef _process__copy_in(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+  switch (__pyx_v_mtype) {
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":367
+ *     cdef _process__copy_in(self, char mtype):
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'G':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 367, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":366
+ * 
+ *     cdef _process__copy_in(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+    break;
+    case 'G':
+
+    /* "asyncpg/protocol/coreproto.pyx":371
+ *         elif mtype == b'G':
+ *             # CopyInResponse
+ *             self._set_state(PROTOCOL_COPY_IN_DATA)             # <<<<<<<<<<<<<<
+ *             self.buffer.discard_message()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN_DATA); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 371, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":372
+ *             # CopyInResponse
+ *             self._set_state(PROTOCOL_COPY_IN_DATA)
+ *             self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 372, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":369
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'G':             # <<<<<<<<<<<<<<
+ *             # CopyInResponse
+ *             self._set_state(PROTOCOL_COPY_IN_DATA)
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":376
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 376, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":377
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _process__copy_in_data(self, char mtype):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 377, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":374
+ *             self.buffer.discard_message()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":365
+ *             self._push_result()
+ * 
+ *     cdef _process__copy_in(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":379
+ *             self._push_result()
+ * 
+ *     cdef _process__copy_in_data(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_in_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, char __pyx_v_mtype) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_process__copy_in_data", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":380
+ * 
+ *     cdef _process__copy_in_data(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+  switch (__pyx_v_mtype) {
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":381
+ *     cdef _process__copy_in_data(self, char mtype):
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'C':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_error_response(__pyx_v_self, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 381, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":380
+ * 
+ *     cdef _process__copy_in_data(self, char mtype):
+ *         if mtype == b'E':             # <<<<<<<<<<<<<<
+ *             self._parse_msg_error_response(True)
+ * 
+ */
+    break;
+    case 'C':
+
+    /* "asyncpg/protocol/coreproto.pyx":385
+ *         elif mtype == b'C':
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()             # <<<<<<<<<<<<<<
+ * 
+ *         elif mtype == b'Z':
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_command_complete(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 385, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":383
+ *             self._parse_msg_error_response(True)
+ * 
+ *         elif mtype == b'C':             # <<<<<<<<<<<<<<
+ *             # CommandComplete
+ *             self._parse_msg_command_complete()
+ */
+    break;
+    case 'Z':
+
+    /* "asyncpg/protocol/coreproto.pyx":389
+ *         elif mtype == b'Z':
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ * 
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_parse_msg_ready_for_query(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 389, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":390
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_command_complete(self):
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 390, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":387
+ *             self._parse_msg_command_complete()
+ * 
+ *         elif mtype == b'Z':             # <<<<<<<<<<<<<<
+ *             # ReadyForQuery
+ *             self._parse_msg_ready_for_query()
+ */
+    break;
+    default: break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":379
+ *             self._push_result()
+ * 
+ *     cdef _process__copy_in_data(self, char mtype):             # <<<<<<<<<<<<<<
+ *         if mtype == b'E':
+ *             self._parse_msg_error_response(True)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._process__copy_in_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":392
+ *             self._push_result()
+ * 
+ *     cdef _parse_msg_command_complete(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             const char* cbuf
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_command_complete(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  char const *__pyx_v_cbuf;
+  Py_ssize_t __pyx_v_cbuf_len;
+  PyObject *__pyx_v_msg = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_parse_msg_command_complete", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":397
+ *             ssize_t cbuf_len
+ * 
+ *         cbuf = self.buffer.try_consume_message(&cbuf_len)             # <<<<<<<<<<<<<<
+ *         if cbuf != NULL and cbuf_len > 0:
+ *             msg = cpython.PyBytes_FromStringAndSize(cbuf, cbuf_len - 1)
+ */
+  __pyx_v_cbuf = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->try_consume_message(__pyx_v_self->buffer, (&__pyx_v_cbuf_len));
+
+  /* "asyncpg/protocol/coreproto.pyx":398
+ * 
+ *         cbuf = self.buffer.try_consume_message(&cbuf_len)
+ *         if cbuf != NULL and cbuf_len > 0:             # <<<<<<<<<<<<<<
+ *             msg = cpython.PyBytes_FromStringAndSize(cbuf, cbuf_len - 1)
+ *         else:
+ */
+  __pyx_t_2 = ((__pyx_v_cbuf != NULL) != 0);
+  if (__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_2 = ((__pyx_v_cbuf_len > 0) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/coreproto.pyx":399
+ *         cbuf = self.buffer.try_consume_message(&cbuf_len)
+ *         if cbuf != NULL and cbuf_len > 0:
+ *             msg = cpython.PyBytes_FromStringAndSize(cbuf, cbuf_len - 1)             # <<<<<<<<<<<<<<
+ *         else:
+ *             msg = self.buffer.read_cstr()
+ */
+    __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_cbuf, (__pyx_v_cbuf_len - 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 399, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_v_msg = __pyx_t_3;
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":398
+ * 
+ *         cbuf = self.buffer.try_consume_message(&cbuf_len)
+ *         if cbuf != NULL and cbuf_len > 0:             # <<<<<<<<<<<<<<
+ *             msg = cpython.PyBytes_FromStringAndSize(cbuf, cbuf_len - 1)
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":401
+ *             msg = cpython.PyBytes_FromStringAndSize(cbuf, cbuf_len - 1)
+ *         else:
+ *             msg = self.buffer.read_cstr()             # <<<<<<<<<<<<<<
+ *         self.result_status_msg = msg
+ * 
+ */
+  /*else*/ {
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_cstr(__pyx_v_self->buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 401, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_v_msg = __pyx_t_3;
+    __pyx_t_3 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/coreproto.pyx":402
+ *         else:
+ *             msg = self.buffer.read_cstr()
+ *         self.result_status_msg = msg             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_copy_data_msgs(self):
+ */
+  if (!(likely(PyBytes_CheckExact(__pyx_v_msg))||((__pyx_v_msg) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_msg)->tp_name), 0))) __PYX_ERR(5, 402, __pyx_L1_error)
+  __pyx_t_3 = __pyx_v_msg;
+  __Pyx_INCREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_v_self->result_status_msg);
+  __Pyx_DECREF(__pyx_v_self->result_status_msg);
+  __pyx_v_self->result_status_msg = ((PyObject*)__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":392
+ *             self._push_result()
+ * 
+ *     cdef _parse_msg_command_complete(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             const char* cbuf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_command_complete", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_msg);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":404
+ *         self.result_status_msg = msg
+ * 
+ *     cdef _parse_copy_data_msgs(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ReadBuffer buf = self.buffer
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_copy_data_msgs(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int32_t __pyx_t_2;
+  int __pyx_t_3;
+  __Pyx_RefNannySetupContext("_parse_copy_data_msgs", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":406
+ *     cdef _parse_copy_data_msgs(self):
+ *         cdef:
+ *             ReadBuffer buf = self.buffer             # <<<<<<<<<<<<<<
+ * 
+ *         self.result = buf.consume_messages(b'd')
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_v_self->buffer);
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":408
+ *             ReadBuffer buf = self.buffer
+ * 
+ *         self.result = buf.consume_messages(b'd')             # <<<<<<<<<<<<<<
+ * 
+ *         # By this point we have consumed all CopyData messages
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->consume_messages(__pyx_v_buf, 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 408, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->result);
+  __Pyx_DECREF(__pyx_v_self->result);
+  __pyx_v_self->result = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":417
+ *         # we must not push the result here and let the
+ *         # _process__copy_out_data subprotocol do the job.
+ *         if not buf.take_message():             # <<<<<<<<<<<<<<
+ *             self._on_result()
+ *             self.result = None
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->take_message(__pyx_v_buf); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(5, 417, __pyx_L1_error)
+  __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/coreproto.pyx":418
+ *         # _process__copy_out_data subprotocol do the job.
+ *         if not buf.take_message():
+ *             self._on_result()             # <<<<<<<<<<<<<<
+ *             self.result = None
+ *         else:
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_on_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 418, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":419
+ *         if not buf.take_message():
+ *             self._on_result()
+ *             self.result = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             # If there is a message in the buffer, put it back to
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_v_self->result);
+    __Pyx_DECREF(__pyx_v_self->result);
+    __pyx_v_self->result = Py_None;
+
+    /* "asyncpg/protocol/coreproto.pyx":417
+ *         # we must not push the result here and let the
+ *         # _process__copy_out_data subprotocol do the job.
+ *         if not buf.take_message():             # <<<<<<<<<<<<<<
+ *             self._on_result()
+ *             self.result = None
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":423
+ *             # If there is a message in the buffer, put it back to
+ *             # be processed by the next protocol iteration.
+ *             buf.put_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _write_copy_data_msg(self, object data):
+ */
+  /*else*/ {
+    __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->put_message(__pyx_v_buf); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(5, 423, __pyx_L1_error)
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/coreproto.pyx":404
+ *         self.result_status_msg = msg
+ * 
+ *     cdef _parse_copy_data_msgs(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ReadBuffer buf = self.buffer
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_copy_data_msgs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":425
+ *             buf.put_message()
+ * 
+ *     cdef _write_copy_data_msg(self, object data):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_data_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_data) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_v_mview = 0;
+  Py_buffer *__pyx_v_pybuf;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  char const *__pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  __Pyx_RefNannySetupContext("_write_copy_data_msg", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":431
+ *             Py_buffer *pybuf
+ * 
+ *         mview = cpythonx.PyMemoryView_GetContiguous(             # <<<<<<<<<<<<<<
+ *             data, cpython.PyBUF_SIMPLE, b'C')
+ * 
+ */
+  __pyx_t_1 = PyMemoryView_GetContiguous(__pyx_v_data, PyBUF_SIMPLE, 'C'); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 431, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_mview = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":434
+ *             data, cpython.PyBUF_SIMPLE, b'C')
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             pybuf = cpythonx.PyMemoryView_GET_BUFFER(mview)
+ * 
+ */
+  /*try:*/ {
+
+    /* "asyncpg/protocol/coreproto.pyx":435
+ * 
+ *         try:
+ *             pybuf = cpythonx.PyMemoryView_GET_BUFFER(mview)             # <<<<<<<<<<<<<<
+ * 
+ *             buf = WriteBuffer.new_message(b'd')
+ */
+    __pyx_v_pybuf = PyMemoryView_GET_BUFFER(__pyx_v_mview);
+
+    /* "asyncpg/protocol/coreproto.pyx":437
+ *             pybuf = cpythonx.PyMemoryView_GET_BUFFER(mview)
+ * 
+ *             buf = WriteBuffer.new_message(b'd')             # <<<<<<<<<<<<<<
+ *             buf.write_cstr(<const char *>pybuf.buf, pybuf.len)
+ *             buf.end_message()
+ */
+    __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('d')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 437, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":438
+ * 
+ *             buf = WriteBuffer.new_message(b'd')
+ *             buf.write_cstr(<const char *>pybuf.buf, pybuf.len)             # <<<<<<<<<<<<<<
+ *             buf.end_message()
+ *         finally:
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_cstr(__pyx_v_buf, ((char const *)__pyx_v_pybuf->buf), __pyx_v_pybuf->len); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 438, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":439
+ *             buf = WriteBuffer.new_message(b'd')
+ *             buf.write_cstr(<const char *>pybuf.buf, pybuf.len)
+ *             buf.end_message()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             mview.release()
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 439, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":441
+ *             buf.end_message()
+ *         finally:
+ *             mview.release()             # <<<<<<<<<<<<<<
+ * 
+ *         self._write(buf)
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_mview, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 441, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_3 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+        if (likely(__pyx_t_3)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+          __Pyx_INCREF(__pyx_t_3);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_2, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 441, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      goto __pyx_L5;
+    }
+    __pyx_L4_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __Pyx_XGOTREF(__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_12);
+      __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename;
+      {
+        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_mview, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 441, __pyx_L7_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __pyx_t_3 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+          if (likely(__pyx_t_3)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+            __Pyx_INCREF(__pyx_t_3);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_2, function);
+          }
+        }
+        __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 441, __pyx_L7_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_XGIVEREF(__pyx_t_11);
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+      }
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_XGIVEREF(__pyx_t_9);
+      __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+      __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+      __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6;
+      goto __pyx_L1_error;
+      __pyx_L7_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_XGIVEREF(__pyx_t_11);
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+      }
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+      goto __pyx_L1_error;
+    }
+    __pyx_L5:;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":443
+ *             mview.release()
+ * 
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _write_copy_done_msg(self):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 443, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":425
+ *             buf.put_message()
+ * 
+ *     cdef _write_copy_data_msg(self, object data):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._write_copy_data_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XDECREF(__pyx_v_mview);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":445
+ *         self._write(buf)
+ * 
+ *     cdef _write_copy_done_msg(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_done_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_write_copy_done_msg", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":449
+ *             WriteBuffer buf
+ * 
+ *         buf = WriteBuffer.new_message(b'c')             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         self._write(buf)
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('c')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 449, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":450
+ * 
+ *         buf = WriteBuffer.new_message(b'c')
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         self._write(buf)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 450, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":451
+ *         buf = WriteBuffer.new_message(b'c')
+ *         buf.end_message()
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _write_copy_fail_msg(self, str cause):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 451, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":445
+ *         self._write(buf)
+ * 
+ *     cdef _write_copy_done_msg(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._write_copy_done_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":453
+ *         self._write(buf)
+ * 
+ *     cdef _write_copy_fail_msg(self, str cause):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_fail_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_cause) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_write_copy_fail_msg", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":457
+ *             WriteBuffer buf
+ * 
+ *         buf = WriteBuffer.new_message(b'f')             # <<<<<<<<<<<<<<
+ *         buf.write_str(cause or '', self.encoding)
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('f')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 457, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":458
+ * 
+ *         buf = WriteBuffer.new_message(b'f')
+ *         buf.write_str(cause or '', self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         self._write(buf)
+ */
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_cause); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(5, 458, __pyx_L1_error)
+  if (!__pyx_t_2) {
+  } else {
+    __Pyx_INCREF(__pyx_v_cause);
+    __pyx_t_1 = __pyx_v_cause;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __Pyx_INCREF(__pyx_kp_u__25);
+  __pyx_t_1 = __pyx_kp_u__25;
+  __pyx_L3_bool_binop_done:;
+  __pyx_t_3 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_3);
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, ((PyObject*)__pyx_t_1), ((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 458, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":459
+ *         buf = WriteBuffer.new_message(b'f')
+ *         buf.write_str(cause or '', self.encoding)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         self._write(buf)
+ * 
+ */
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 459, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":460
+ *         buf.write_str(cause or '', self.encoding)
+ *         buf.end_message()
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_data_msgs(self):
+ */
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 460, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":453
+ *         self._write(buf)
+ * 
+ *     cdef _write_copy_fail_msg(self, str cause):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._write_copy_fail_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":462
+ *         self._write(buf)
+ * 
+ *     cdef _parse_data_msgs(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ReadBuffer buf = self.buffer
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_data_msgs(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_v_rows = 0;
+  __pyx_t_7asyncpg_8protocol_8protocol_decode_row_method __pyx_v_decoder;
+  __pyx_t_7asyncpg_7pgproto_7pgproto_try_consume_message_method __pyx_v_try_consume_message;
+  __pyx_t_7asyncpg_7pgproto_7pgproto_take_message_type_method __pyx_v_take_message_type;
+  char const *__pyx_v_cbuf;
+  Py_ssize_t __pyx_v_cbuf_len;
+  PyObject *__pyx_v_row = 0;
+  PyObject *__pyx_v_mem = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  int32_t __pyx_t_5;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  __Pyx_RefNannySetupContext("_parse_data_msgs", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":464
+ *     cdef _parse_data_msgs(self):
+ *         cdef:
+ *             ReadBuffer buf = self.buffer             # <<<<<<<<<<<<<<
+ *             list rows
+ * 
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_v_self->buffer);
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":467
+ *             list rows
+ * 
+ *             decode_row_method decoder = <decode_row_method>self._decode_row             # <<<<<<<<<<<<<<
+ *             pgproto.try_consume_message_method try_consume_message = \
+ *                 <pgproto.try_consume_message_method>buf.try_consume_message
+ */
+  __pyx_v_decoder = ((__pyx_t_7asyncpg_8protocol_8protocol_decode_row_method)((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_decode_row);
+
+  /* "asyncpg/protocol/coreproto.pyx":469
+ *             decode_row_method decoder = <decode_row_method>self._decode_row
+ *             pgproto.try_consume_message_method try_consume_message = \
+ *                 <pgproto.try_consume_message_method>buf.try_consume_message             # <<<<<<<<<<<<<<
+ *             pgproto.take_message_type_method take_message_type = \
+ *                 <pgproto.take_message_type_method>buf.take_message_type
+ */
+  __pyx_v_try_consume_message = ((__pyx_t_7asyncpg_7pgproto_7pgproto_try_consume_message_method)((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->try_consume_message);
+
+  /* "asyncpg/protocol/coreproto.pyx":471
+ *                 <pgproto.try_consume_message_method>buf.try_consume_message
+ *             pgproto.take_message_type_method take_message_type = \
+ *                 <pgproto.take_message_type_method>buf.take_message_type             # <<<<<<<<<<<<<<
+ * 
+ *             const char* cbuf
+ */
+  __pyx_v_take_message_type = ((__pyx_t_7asyncpg_7pgproto_7pgproto_take_message_type_method)((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->take_message_type);
+
+  /* "asyncpg/protocol/coreproto.pyx":478
+ *             bytes mem
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if buf.get_message_type() != b'D':
+ *                 raise apg_exc.InternalClientError(
+ */
+  __pyx_t_2 = (PG_DEBUG != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/coreproto.pyx":479
+ * 
+ *         if PG_DEBUG:
+ *             if buf.get_message_type() != b'D':             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_parse_data_msgs: first message is not "D"')
+ */
+    __pyx_t_2 = ((__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(__pyx_v_buf) != 'D') != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/coreproto.pyx":480
+ *         if PG_DEBUG:
+ *             if buf.get_message_type() != b'D':
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     '_parse_data_msgs: first message is not "D"')
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 480, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 480, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __pyx_t_3 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_3)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_3);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_parse_data_msgs_first_message_i) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_parse_data_msgs_first_message_i);
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 480, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(5, 480, __pyx_L1_error)
+
+      /* "asyncpg/protocol/coreproto.pyx":479
+ * 
+ *         if PG_DEBUG:
+ *             if buf.get_message_type() != b'D':             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_parse_data_msgs: first message is not "D"')
+ */
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":478
+ *             bytes mem
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if buf.get_message_type() != b'D':
+ *                 raise apg_exc.InternalClientError(
+ */
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":483
+ *                     '_parse_data_msgs: first message is not "D"')
+ * 
+ *         if self._discard_data:             # <<<<<<<<<<<<<<
+ *             while take_message_type(buf, b'D'):
+ *                 buf.discard_message()
+ */
+  __pyx_t_2 = (__pyx_v_self->_discard_data != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/coreproto.pyx":484
+ * 
+ *         if self._discard_data:
+ *             while take_message_type(buf, b'D'):             # <<<<<<<<<<<<<<
+ *                 buf.discard_message()
+ *             return
+ */
+    while (1) {
+      __pyx_t_5 = __pyx_v_take_message_type(((PyObject *)__pyx_v_buf), 'D'); if (unlikely(__pyx_t_5 == ((int32_t)-1))) __PYX_ERR(5, 484, __pyx_L1_error)
+      __pyx_t_2 = (__pyx_t_5 != 0);
+      if (!__pyx_t_2) break;
+
+      /* "asyncpg/protocol/coreproto.pyx":485
+ *         if self._discard_data:
+ *             while take_message_type(buf, b'D'):
+ *                 buf.discard_message()             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+      __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->discard_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 485, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":486
+ *             while take_message_type(buf, b'D'):
+ *                 buf.discard_message()
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         if PG_DEBUG:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/coreproto.pyx":483
+ *                     '_parse_data_msgs: first message is not "D"')
+ * 
+ *         if self._discard_data:             # <<<<<<<<<<<<<<
+ *             while take_message_type(buf, b'D'):
+ *                 buf.discard_message()
+ */
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":488
+ *             return
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if type(self.result) is not list:
+ *                 raise apg_exc.InternalClientError(
+ */
+  __pyx_t_2 = (PG_DEBUG != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/coreproto.pyx":489
+ * 
+ *         if PG_DEBUG:
+ *             if type(self.result) is not list:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_parse_data_msgs: result is not a list, but {!r}'.
+ */
+    __pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_self->result)) != ((PyObject *)(&PyList_Type)));
+    __pyx_t_6 = (__pyx_t_2 != 0);
+    if (unlikely(__pyx_t_6)) {
+
+      /* "asyncpg/protocol/coreproto.pyx":490
+ *         if PG_DEBUG:
+ *             if type(self.result) is not list:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     '_parse_data_msgs: result is not a list, but {!r}'.
+ *                     format(self.result))
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 490, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 490, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":491
+ *             if type(self.result) is not list:
+ *                 raise apg_exc.InternalClientError(
+ *                     '_parse_data_msgs: result is not a list, but {!r}'.             # <<<<<<<<<<<<<<
+ *                     format(self.result))
+ * 
+ */
+      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_parse_data_msgs_result_is_not_a, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 491, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+
+      /* "asyncpg/protocol/coreproto.pyx":492
+ *                 raise apg_exc.InternalClientError(
+ *                     '_parse_data_msgs: result is not a list, but {!r}'.
+ *                     format(self.result))             # <<<<<<<<<<<<<<
+ * 
+ *         rows = self.result
+ */
+      __pyx_t_8 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+        if (likely(__pyx_t_8)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+          __Pyx_INCREF(__pyx_t_8);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_7, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_self->result) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_self->result);
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 492, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __pyx_t_7 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_7)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_7);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 490, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(5, 490, __pyx_L1_error)
+
+      /* "asyncpg/protocol/coreproto.pyx":489
+ * 
+ *         if PG_DEBUG:
+ *             if type(self.result) is not list:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_parse_data_msgs: result is not a list, but {!r}'.
+ */
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":488
+ *             return
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if type(self.result) is not list:
+ *                 raise apg_exc.InternalClientError(
+ */
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":494
+ *                     format(self.result))
+ * 
+ *         rows = self.result             # <<<<<<<<<<<<<<
+ *         while take_message_type(buf, b'D'):
+ *             cbuf = try_consume_message(buf, &cbuf_len)
+ */
+  if (!(likely(PyList_CheckExact(__pyx_v_self->result))||((__pyx_v_self->result) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_self->result)->tp_name), 0))) __PYX_ERR(5, 494, __pyx_L1_error)
+  __pyx_t_1 = __pyx_v_self->result;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_rows = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":495
+ * 
+ *         rows = self.result
+ *         while take_message_type(buf, b'D'):             # <<<<<<<<<<<<<<
+ *             cbuf = try_consume_message(buf, &cbuf_len)
+ *             if cbuf != NULL:
+ */
+  while (1) {
+    __pyx_t_5 = __pyx_v_take_message_type(((PyObject *)__pyx_v_buf), 'D'); if (unlikely(__pyx_t_5 == ((int32_t)-1))) __PYX_ERR(5, 495, __pyx_L1_error)
+    __pyx_t_6 = (__pyx_t_5 != 0);
+    if (!__pyx_t_6) break;
+
+    /* "asyncpg/protocol/coreproto.pyx":496
+ *         rows = self.result
+ *         while take_message_type(buf, b'D'):
+ *             cbuf = try_consume_message(buf, &cbuf_len)             # <<<<<<<<<<<<<<
+ *             if cbuf != NULL:
+ *                 row = decoder(self, cbuf, cbuf_len)
+ */
+    __pyx_v_cbuf = __pyx_v_try_consume_message(((PyObject *)__pyx_v_buf), (&__pyx_v_cbuf_len));
+
+    /* "asyncpg/protocol/coreproto.pyx":497
+ *         while take_message_type(buf, b'D'):
+ *             cbuf = try_consume_message(buf, &cbuf_len)
+ *             if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *                 row = decoder(self, cbuf, cbuf_len)
+ *             else:
+ */
+    __pyx_t_6 = ((__pyx_v_cbuf != NULL) != 0);
+    if (__pyx_t_6) {
+
+      /* "asyncpg/protocol/coreproto.pyx":498
+ *             cbuf = try_consume_message(buf, &cbuf_len)
+ *             if cbuf != NULL:
+ *                 row = decoder(self, cbuf, cbuf_len)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 mem = buf.consume_message()
+ */
+      __pyx_t_1 = __pyx_v_decoder(((PyObject *)__pyx_v_self), __pyx_v_cbuf, __pyx_v_cbuf_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 498, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_1);
+      __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":497
+ *         while take_message_type(buf, b'D'):
+ *             cbuf = try_consume_message(buf, &cbuf_len)
+ *             if cbuf != NULL:             # <<<<<<<<<<<<<<
+ *                 row = decoder(self, cbuf, cbuf_len)
+ *             else:
+ */
+      goto __pyx_L12;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":500
+ *                 row = decoder(self, cbuf, cbuf_len)
+ *             else:
+ *                 mem = buf.consume_message()             # <<<<<<<<<<<<<<
+ *                 row = decoder(
+ *                     self,
+ */
+    /*else*/ {
+      __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_buf->__pyx_vtab)->consume_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 500, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_XDECREF_SET(__pyx_v_mem, ((PyObject*)__pyx_t_1));
+      __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":501
+ *             else:
+ *                 mem = buf.consume_message()
+ *                 row = decoder(             # <<<<<<<<<<<<<<
+ *                     self,
+ *                     cpython.PyBytes_AS_STRING(mem),
+ */
+      __pyx_t_1 = __pyx_v_decoder(((PyObject *)__pyx_v_self), PyBytes_AS_STRING(__pyx_v_mem), PyBytes_GET_SIZE(__pyx_v_mem)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 501, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_XDECREF_SET(__pyx_v_row, __pyx_t_1);
+      __pyx_t_1 = 0;
+    }
+    __pyx_L12:;
+
+    /* "asyncpg/protocol/coreproto.pyx":506
+ *                     cpython.PyBytes_GET_SIZE(mem))
+ * 
+ *             cpython.PyList_Append(rows, row)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_backend_key_data(self):
+ */
+    __pyx_t_9 = PyList_Append(__pyx_v_rows, __pyx_v_row); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(5, 506, __pyx_L1_error)
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":462
+ *         self._write(buf)
+ * 
+ *     cdef _parse_data_msgs(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             ReadBuffer buf = self.buffer
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_data_msgs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XDECREF(__pyx_v_rows);
+  __Pyx_XDECREF(__pyx_v_row);
+  __Pyx_XDECREF(__pyx_v_mem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":508
+ *             cpython.PyList_Append(rows, row)
+ * 
+ *     cdef _parse_msg_backend_key_data(self):             # <<<<<<<<<<<<<<
+ *         self.backend_pid = self.buffer.read_int32()
+ *         self.backend_secret = self.buffer.read_int32()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_backend_key_data(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int32_t __pyx_t_1;
+  __Pyx_RefNannySetupContext("_parse_msg_backend_key_data", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":509
+ * 
+ *     cdef _parse_msg_backend_key_data(self):
+ *         self.backend_pid = self.buffer.read_int32()             # <<<<<<<<<<<<<<
+ *         self.backend_secret = self.buffer.read_int32()
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_int32(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(5, 509, __pyx_L1_error)
+  __pyx_v_self->backend_pid = __pyx_t_1;
+
+  /* "asyncpg/protocol/coreproto.pyx":510
+ *     cdef _parse_msg_backend_key_data(self):
+ *         self.backend_pid = self.buffer.read_int32()
+ *         self.backend_secret = self.buffer.read_int32()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_parameter_status(self):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_int32(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(5, 510, __pyx_L1_error)
+  __pyx_v_self->backend_secret = __pyx_t_1;
+
+  /* "asyncpg/protocol/coreproto.pyx":508
+ *             cpython.PyList_Append(rows, row)
+ * 
+ *     cdef _parse_msg_backend_key_data(self):             # <<<<<<<<<<<<<<
+ *         self.backend_pid = self.buffer.read_int32()
+ *         self.backend_secret = self.buffer.read_int32()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_backend_key_data", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":512
+ *         self.backend_secret = self.buffer.read_int32()
+ * 
+ *     cdef _parse_msg_parameter_status(self):             # <<<<<<<<<<<<<<
+ *         name = self.buffer.read_cstr()
+ *         name = name.decode(self.encoding)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_parameter_status(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_v_name = NULL;
+  PyObject *__pyx_v_val = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_parse_msg_parameter_status", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":513
+ * 
+ *     cdef _parse_msg_parameter_status(self):
+ *         name = self.buffer.read_cstr()             # <<<<<<<<<<<<<<
+ *         name = name.decode(self.encoding)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_cstr(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 513, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_name = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":514
+ *     cdef _parse_msg_parameter_status(self):
+ *         name = self.buffer.read_cstr()
+ *         name = name.decode(self.encoding)             # <<<<<<<<<<<<<<
+ * 
+ *         val = self.buffer.read_cstr()
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_name, __pyx_n_s_decode); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 514, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->encoding);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 514, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF_SET(__pyx_v_name, __pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":516
+ *         name = name.decode(self.encoding)
+ * 
+ *         val = self.buffer.read_cstr()             # <<<<<<<<<<<<<<
+ *         val = val.decode(self.encoding)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_cstr(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 516, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_val = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":517
+ * 
+ *         val = self.buffer.read_cstr()
+ *         val = val.decode(self.encoding)             # <<<<<<<<<<<<<<
+ * 
+ *         self._set_server_parameter(name, val)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_val, __pyx_n_s_decode); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 517, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->encoding);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 517, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF_SET(__pyx_v_val, __pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":519
+ *         val = val.decode(self.encoding)
+ * 
+ *         self._set_server_parameter(name, val)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_notification(self):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_server_parameter(__pyx_v_self, __pyx_v_name, __pyx_v_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 519, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":512
+ *         self.backend_secret = self.buffer.read_int32()
+ * 
+ *     cdef _parse_msg_parameter_status(self):             # <<<<<<<<<<<<<<
+ *         name = self.buffer.read_cstr()
+ *         name = name.decode(self.encoding)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_parameter_status", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_name);
+  __Pyx_XDECREF(__pyx_v_val);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":521
+ *         self._set_server_parameter(name, val)
+ * 
+ *     cdef _parse_msg_notification(self):             # <<<<<<<<<<<<<<
+ *         pid = self.buffer.read_int32()
+ *         channel = self.buffer.read_cstr().decode(self.encoding)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_notification(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  int32_t __pyx_v_pid;
+  PyObject *__pyx_v_channel = NULL;
+  PyObject *__pyx_v_payload = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int32_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_parse_msg_notification", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":522
+ * 
+ *     cdef _parse_msg_notification(self):
+ *         pid = self.buffer.read_int32()             # <<<<<<<<<<<<<<
+ *         channel = self.buffer.read_cstr().decode(self.encoding)
+ *         payload = self.buffer.read_cstr().decode(self.encoding)
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_int32(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(5, 522, __pyx_L1_error)
+  __pyx_v_pid = __pyx_t_1;
+
+  /* "asyncpg/protocol/coreproto.pyx":523
+ *     cdef _parse_msg_notification(self):
+ *         pid = self.buffer.read_int32()
+ *         channel = self.buffer.read_cstr().decode(self.encoding)             # <<<<<<<<<<<<<<
+ *         payload = self.buffer.read_cstr().decode(self.encoding)
+ *         self._on_notification(pid, channel, payload)
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_cstr(__pyx_v_self->buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 523, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 523, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_self->encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->encoding);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 523, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_v_channel = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":524
+ *         pid = self.buffer.read_int32()
+ *         channel = self.buffer.read_cstr().decode(self.encoding)
+ *         payload = self.buffer.read_cstr().decode(self.encoding)             # <<<<<<<<<<<<<<
+ *         self._on_notification(pid, channel, payload)
+ * 
+ */
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_cstr(__pyx_v_self->buffer); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 524, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_decode); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 524, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_self->encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->encoding);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 524, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_v_payload = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":525
+ *         channel = self.buffer.read_cstr().decode(self.encoding)
+ *         payload = self.buffer.read_cstr().decode(self.encoding)
+ *         self._on_notification(pid, channel, payload)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_authentication(self):
+ */
+  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_pid); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 525, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_on_notification(__pyx_v_self, __pyx_t_2, __pyx_v_channel, __pyx_v_payload); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 525, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":521
+ *         self._set_server_parameter(name, val)
+ * 
+ *     cdef _parse_msg_notification(self):             # <<<<<<<<<<<<<<
+ *         pid = self.buffer.read_int32()
+ *         channel = self.buffer.read_cstr().decode(self.encoding)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_notification", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_channel);
+  __Pyx_XDECREF(__pyx_v_payload);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":527
+ *         self._on_notification(pid, channel, payload)
+ * 
+ *     cdef _parse_msg_authentication(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             int32_t status
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_authentication(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  int32_t __pyx_v_status;
+  PyObject *__pyx_v_md5_salt = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int32_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("_parse_msg_authentication", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":532
+ *             bytes md5_salt
+ * 
+ *         status = self.buffer.read_int32()             # <<<<<<<<<<<<<<
+ * 
+ *         if status == AUTH_SUCCESSFUL:
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_int32(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(5, 532, __pyx_L1_error)
+  __pyx_v_status = __pyx_t_1;
+
+  /* "asyncpg/protocol/coreproto.pyx":534
+ *         status = self.buffer.read_int32()
+ * 
+ *         if status == AUTH_SUCCESSFUL:             # <<<<<<<<<<<<<<
+ *             # AuthenticationOk
+ *             self.result_type = RESULT_OK
+ */
+  switch (__pyx_v_status) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_SUCCESSFUL:
+
+    /* "asyncpg/protocol/coreproto.pyx":536
+ *         if status == AUTH_SUCCESSFUL:
+ *             # AuthenticationOk
+ *             self.result_type = RESULT_OK             # <<<<<<<<<<<<<<
+ * 
+ *         elif status == AUTH_REQUIRED_PASSWORD:
+ */
+    __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_OK;
+
+    /* "asyncpg/protocol/coreproto.pyx":534
+ *         status = self.buffer.read_int32()
+ * 
+ *         if status == AUTH_SUCCESSFUL:             # <<<<<<<<<<<<<<
+ *             # AuthenticationOk
+ *             self.result_type = RESULT_OK
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_PASSWORD:
+
+    /* "asyncpg/protocol/coreproto.pyx":540
+ *         elif status == AUTH_REQUIRED_PASSWORD:
+ *             # AuthenticationCleartextPassword
+ *             self.result_type = RESULT_OK             # <<<<<<<<<<<<<<
+ *             self.auth_msg = self._auth_password_message_cleartext()
+ * 
+ */
+    __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_OK;
+
+    /* "asyncpg/protocol/coreproto.pyx":541
+ *             # AuthenticationCleartextPassword
+ *             self.result_type = RESULT_OK
+ *             self.auth_msg = self._auth_password_message_cleartext()             # <<<<<<<<<<<<<<
+ * 
+ *         elif status == AUTH_REQUIRED_PASSWORDMD5:
+ */
+    __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_auth_password_message_cleartext(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 541, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_auth_msg, __pyx_t_2) < 0) __PYX_ERR(5, 541, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":538
+ *             self.result_type = RESULT_OK
+ * 
+ *         elif status == AUTH_REQUIRED_PASSWORD:             # <<<<<<<<<<<<<<
+ *             # AuthenticationCleartextPassword
+ *             self.result_type = RESULT_OK
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_PASSWORDMD5:
+
+    /* "asyncpg/protocol/coreproto.pyx":546
+ *             # AuthenticationMD5Password
+ *             # Note: MD5 salt is passed as a four-byte sequence
+ *             md5_salt = self.buffer.read_bytes(4)             # <<<<<<<<<<<<<<
+ *             self.auth_msg = self._auth_password_message_md5(md5_salt)
+ * 
+ */
+    __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_bytes(__pyx_v_self->buffer, 4); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 546, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_v_md5_salt = ((PyObject*)__pyx_t_2);
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":547
+ *             # Note: MD5 salt is passed as a four-byte sequence
+ *             md5_salt = self.buffer.read_bytes(4)
+ *             self.auth_msg = self._auth_password_message_md5(md5_salt)             # <<<<<<<<<<<<<<
+ * 
+ *         elif status in (AUTH_REQUIRED_KERBEROS, AUTH_REQUIRED_SCMCRED,
+ */
+    __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_auth_password_message_md5(__pyx_v_self, __pyx_v_md5_salt); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 547, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_auth_msg, __pyx_t_2) < 0) __PYX_ERR(5, 547, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":543
+ *             self.auth_msg = self._auth_password_message_cleartext()
+ * 
+ *         elif status == AUTH_REQUIRED_PASSWORDMD5:             # <<<<<<<<<<<<<<
+ *             # AuthenticationMD5Password
+ *             # Note: MD5 salt is passed as a four-byte sequence
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_KERBEROS:
+
+    /* "asyncpg/protocol/coreproto.pyx":549
+ *             self.auth_msg = self._auth_password_message_md5(md5_salt)
+ * 
+ *         elif status in (AUTH_REQUIRED_KERBEROS, AUTH_REQUIRED_SCMCRED,             # <<<<<<<<<<<<<<
+ *                         AUTH_REQUIRED_GSS, AUTH_REQUIRED_GSS_CONTINUE,
+ *                         AUTH_REQUIRED_SSPI):
+ */
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_SCMCRED:
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_GSS:
+
+    /* "asyncpg/protocol/coreproto.pyx":550
+ * 
+ *         elif status in (AUTH_REQUIRED_KERBEROS, AUTH_REQUIRED_SCMCRED,
+ *                         AUTH_REQUIRED_GSS, AUTH_REQUIRED_GSS_CONTINUE,             # <<<<<<<<<<<<<<
+ *                         AUTH_REQUIRED_SSPI):
+ *             self.result_type = RESULT_FAILED
+ */
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_GSS_CONTINUE:
+    case __pyx_e_7asyncpg_8protocol_8protocol_AUTH_REQUIRED_SSPI:
+
+    /* "asyncpg/protocol/coreproto.pyx":552
+ *                         AUTH_REQUIRED_GSS, AUTH_REQUIRED_GSS_CONTINUE,
+ *                         AUTH_REQUIRED_SSPI):
+ *             self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *             self.result = apg_exc.InterfaceError(
+ *                 'unsupported authentication method requested by the '
+ */
+    __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+    /* "asyncpg/protocol/coreproto.pyx":553
+ *                         AUTH_REQUIRED_SSPI):
+ *             self.result_type = RESULT_FAILED
+ *             self.result = apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'unsupported authentication method requested by the '
+ *                 'server: {!r}'.format(AUTH_METHOD_NAME[status]))
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 553, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 553, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":555
+ *             self.result = apg_exc.InterfaceError(
+ *                 'unsupported authentication method requested by the '
+ *                 'server: {!r}'.format(AUTH_METHOD_NAME[status]))             # <<<<<<<<<<<<<<
+ * 
+ *         else:
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unsupported_authentication_metho, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 555, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_AUTH_METHOD_NAME); if (unlikely(!__pyx_t_6)) __PYX_ERR(5, 555, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_6, __pyx_v_status, int32_t, 1, __Pyx_PyInt_From_int32_t, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 555, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 555, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 553, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":553
+ *                         AUTH_REQUIRED_SSPI):
+ *             self.result_type = RESULT_FAILED
+ *             self.result = apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'unsupported authentication method requested by the '
+ *                 'server: {!r}'.format(AUTH_METHOD_NAME[status]))
+ */
+    __Pyx_GIVEREF(__pyx_t_2);
+    __Pyx_GOTREF(__pyx_v_self->result);
+    __Pyx_DECREF(__pyx_v_self->result);
+    __pyx_v_self->result = __pyx_t_2;
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":549
+ *             self.auth_msg = self._auth_password_message_md5(md5_salt)
+ * 
+ *         elif status in (AUTH_REQUIRED_KERBEROS, AUTH_REQUIRED_SCMCRED,             # <<<<<<<<<<<<<<
+ *                         AUTH_REQUIRED_GSS, AUTH_REQUIRED_GSS_CONTINUE,
+ *                         AUTH_REQUIRED_SSPI):
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/coreproto.pyx":558
+ * 
+ *         else:
+ *             self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *             self.result = apg_exc.InterfaceError(
+ *                 'unsupported authentication method requested by the '
+ */
+    __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+    /* "asyncpg/protocol/coreproto.pyx":559
+ *         else:
+ *             self.result_type = RESULT_FAILED
+ *             self.result = apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'unsupported authentication method requested by the '
+ *                 'server: {}'.format(status))
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 559, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 559, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":561
+ *             self.result = apg_exc.InterfaceError(
+ *                 'unsupported authentication method requested by the '
+ *                 'server: {}'.format(status))             # <<<<<<<<<<<<<<
+ * 
+ *         self.buffer.discard_message()
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unsupported_authentication_metho_2, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 561, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_status); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 561, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 561, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 559, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":559
+ *         else:
+ *             self.result_type = RESULT_FAILED
+ *             self.result = apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'unsupported authentication method requested by the '
+ *                 'server: {}'.format(status))
+ */
+    __Pyx_GIVEREF(__pyx_t_2);
+    __Pyx_GOTREF(__pyx_v_self->result);
+    __Pyx_DECREF(__pyx_v_self->result);
+    __pyx_v_self->result = __pyx_t_2;
+    __pyx_t_2 = 0;
+    break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":563
+ *                 'server: {}'.format(status))
+ * 
+ *         self.buffer.discard_message()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _auth_password_message_cleartext(self):
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->discard_message(__pyx_v_self->buffer); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 563, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":527
+ *         self._on_notification(pid, channel, payload)
+ * 
+ *     cdef _parse_msg_authentication(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             int32_t status
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_authentication", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_md5_salt);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":565
+ *         self.buffer.discard_message()
+ * 
+ *     cdef _auth_password_message_cleartext(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer msg
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__auth_password_message_cleartext(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_msg = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_auth_password_message_cleartext", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":569
+ *             WriteBuffer msg
+ * 
+ *         msg = WriteBuffer.new_message(b'p')             # <<<<<<<<<<<<<<
+ *         msg.write_bytestring(self.password.encode('ascii'))
+ *         msg.end_message()
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('p')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 569, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_msg = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":570
+ * 
+ *         msg = WriteBuffer.new_message(b'p')
+ *         msg.write_bytestring(self.password.encode('ascii'))             # <<<<<<<<<<<<<<
+ *         msg.end_message()
+ * 
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_password); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 570, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 570, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_n_u_ascii) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_ascii);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 570, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(5, 570, __pyx_L1_error)
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_msg->__pyx_vtab)->write_bytestring(__pyx_v_msg, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 570, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":571
+ *         msg = WriteBuffer.new_message(b'p')
+ *         msg.write_bytestring(self.password.encode('ascii'))
+ *         msg.end_message()             # <<<<<<<<<<<<<<
+ * 
+ *         return msg
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_msg->__pyx_vtab)->end_message(__pyx_v_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 571, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":573
+ *         msg.end_message()
+ * 
+ *         return msg             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _auth_password_message_md5(self, bytes salt):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(((PyObject *)__pyx_v_msg));
+  __pyx_r = ((PyObject *)__pyx_v_msg);
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/coreproto.pyx":565
+ *         self.buffer.discard_message()
+ * 
+ *     cdef _auth_password_message_cleartext(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer msg
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._auth_password_message_cleartext", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":575
+ *         return msg
+ * 
+ *     cdef _auth_password_message_md5(self, bytes salt):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer msg
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__auth_password_message_md5(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_salt) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_msg = 0;
+  PyObject *__pyx_v_userpass = NULL;
+  PyObject *__pyx_v_hash = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  __Pyx_RefNannySetupContext("_auth_password_message_md5", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":579
+ *             WriteBuffer msg
+ * 
+ *         msg = WriteBuffer.new_message(b'p')             # <<<<<<<<<<<<<<
+ * 
+ *         # 'md5' + md5(md5(password + username) + salt))
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('p')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 579, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_msg = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":582
+ * 
+ *         # 'md5' + md5(md5(password + username) + salt))
+ *         userpass = ((self.password or '') + (self.user or '')).encode('ascii')             # <<<<<<<<<<<<<<
+ *         hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\
+ *                 encode('ascii') + salt).hexdigest().encode('ascii')
+ */
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_password); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 582, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(5, 582, __pyx_L1_error)
+  if (!__pyx_t_4) {
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  } else {
+    __Pyx_INCREF(__pyx_t_3);
+    __pyx_t_2 = __pyx_t_3;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __Pyx_INCREF(__pyx_kp_u__25);
+  __pyx_t_2 = __pyx_kp_u__25;
+  __pyx_L3_bool_binop_done:;
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_user); if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 582, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(5, 582, __pyx_L1_error)
+  if (!__pyx_t_4) {
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  } else {
+    __Pyx_INCREF(__pyx_t_5);
+    __pyx_t_3 = __pyx_t_5;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    goto __pyx_L5_bool_binop_done;
+  }
+  __Pyx_INCREF(__pyx_kp_u__25);
+  __pyx_t_3 = __pyx_kp_u__25;
+  __pyx_L5_bool_binop_done:;
+  __pyx_t_5 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 582, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 582, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_n_u_ascii) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_ascii);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 582, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_v_userpass = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":583
+ *         # 'md5' + md5(md5(password + username) + salt))
+ *         userpass = ((self.password or '') + (self.user or '')).encode('ascii')
+ *         hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\             # <<<<<<<<<<<<<<
+ *                 encode('ascii') + salt).hexdigest().encode('ascii')
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_hashlib_md5); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+
+  /* "asyncpg/protocol/coreproto.pyx":584
+ *         userpass = ((self.password or '') + (self.user or '')).encode('ascii')
+ *         hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\
+ *                 encode('ascii') + salt).hexdigest().encode('ascii')             # <<<<<<<<<<<<<<
+ * 
+ *         msg.write_bytestring(b'md5' + hash)
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_hashlib_md5); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+
+  /* "asyncpg/protocol/coreproto.pyx":583
+ *         # 'md5' + md5(md5(password + username) + salt))
+ *         userpass = ((self.password or '') + (self.user or '')).encode('ascii')
+ *         hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\             # <<<<<<<<<<<<<<
+ *                 encode('ascii') + salt).hexdigest().encode('ascii')
+ * 
+ */
+  __pyx_t_10 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
+    __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
+    if (likely(__pyx_t_10)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+      __Pyx_INCREF(__pyx_t_10);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_9, function);
+    }
+  }
+  __pyx_t_8 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_v_userpass) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_userpass);
+  __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+  if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_hexdigest); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __pyx_t_8 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
+    if (likely(__pyx_t_8)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+      __Pyx_INCREF(__pyx_t_8);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_9, function);
+    }
+  }
+  __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+  if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_encode); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __pyx_t_7 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_9, function);
+    }
+  }
+  __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_7, __pyx_n_u_ascii) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_n_u_ascii);
+  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+  if (unlikely(!__pyx_t_6)) __PYX_ERR(5, 584, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":584
+ *         userpass = ((self.password or '') + (self.user or '')).encode('ascii')
+ *         hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\
+ *                 encode('ascii') + salt).hexdigest().encode('ascii')             # <<<<<<<<<<<<<<
+ * 
+ *         msg.write_bytestring(b'md5' + hash)
+ */
+  __pyx_t_9 = PyNumber_Add(__pyx_t_6, __pyx_v_salt); if (unlikely(!__pyx_t_9)) __PYX_ERR(5, 584, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  __pyx_t_6 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 583, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_hexdigest); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 584, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 584, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 584, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_u_ascii) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_ascii);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 584, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_hash = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":586
+ *                 encode('ascii') + salt).hexdigest().encode('ascii')
+ * 
+ *         msg.write_bytestring(b'md5' + hash)             # <<<<<<<<<<<<<<
+ *         msg.end_message()
+ * 
+ */
+  __pyx_t_1 = PyNumber_Add(__pyx_n_b_md5, __pyx_v_hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 586, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(5, 586, __pyx_L1_error)
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_msg->__pyx_vtab)->write_bytestring(__pyx_v_msg, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 586, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":587
+ * 
+ *         msg.write_bytestring(b'md5' + hash)
+ *         msg.end_message()             # <<<<<<<<<<<<<<
+ * 
+ *         return msg
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_msg->__pyx_vtab)->end_message(__pyx_v_msg); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 587, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":589
+ *         msg.end_message()
+ * 
+ *         return msg             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_ready_for_query(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(((PyObject *)__pyx_v_msg));
+  __pyx_r = ((PyObject *)__pyx_v_msg);
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/coreproto.pyx":575
+ *         return msg
+ * 
+ *     cdef _auth_password_message_md5(self, bytes salt):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer msg
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._auth_password_message_md5", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
+  __Pyx_XDECREF(__pyx_v_userpass);
+  __Pyx_XDECREF(__pyx_v_hash);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":591
+ *         return msg
+ * 
+ *     cdef _parse_msg_ready_for_query(self):             # <<<<<<<<<<<<<<
+ *         cdef char status = self.buffer.read_byte()
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_ready_for_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  char __pyx_v_status;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  char __pyx_t_1;
+  __Pyx_RefNannySetupContext("_parse_msg_ready_for_query", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":592
+ * 
+ *     cdef _parse_msg_ready_for_query(self):
+ *         cdef char status = self.buffer.read_byte()             # <<<<<<<<<<<<<<
+ * 
+ *         if status == b'I':
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_byte(__pyx_v_self->buffer); if (unlikely(__pyx_t_1 == ((char)-1) && PyErr_Occurred())) __PYX_ERR(5, 592, __pyx_L1_error)
+  __pyx_v_status = __pyx_t_1;
+
+  /* "asyncpg/protocol/coreproto.pyx":594
+ *         cdef char status = self.buffer.read_byte()
+ * 
+ *         if status == b'I':             # <<<<<<<<<<<<<<
+ *             self.xact_status = PQTRANS_IDLE
+ *         elif status == b'T':
+ */
+  switch (__pyx_v_status) {
+    case 'I':
+
+    /* "asyncpg/protocol/coreproto.pyx":595
+ * 
+ *         if status == b'I':
+ *             self.xact_status = PQTRANS_IDLE             # <<<<<<<<<<<<<<
+ *         elif status == b'T':
+ *             self.xact_status = PQTRANS_INTRANS
+ */
+    __pyx_v_self->xact_status = __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_IDLE;
+
+    /* "asyncpg/protocol/coreproto.pyx":594
+ *         cdef char status = self.buffer.read_byte()
+ * 
+ *         if status == b'I':             # <<<<<<<<<<<<<<
+ *             self.xact_status = PQTRANS_IDLE
+ *         elif status == b'T':
+ */
+    break;
+    case 'T':
+
+    /* "asyncpg/protocol/coreproto.pyx":597
+ *             self.xact_status = PQTRANS_IDLE
+ *         elif status == b'T':
+ *             self.xact_status = PQTRANS_INTRANS             # <<<<<<<<<<<<<<
+ *         elif status == b'E':
+ *             self.xact_status = PQTRANS_INERROR
+ */
+    __pyx_v_self->xact_status = __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_INTRANS;
+
+    /* "asyncpg/protocol/coreproto.pyx":596
+ *         if status == b'I':
+ *             self.xact_status = PQTRANS_IDLE
+ *         elif status == b'T':             # <<<<<<<<<<<<<<
+ *             self.xact_status = PQTRANS_INTRANS
+ *         elif status == b'E':
+ */
+    break;
+    case 'E':
+
+    /* "asyncpg/protocol/coreproto.pyx":599
+ *             self.xact_status = PQTRANS_INTRANS
+ *         elif status == b'E':
+ *             self.xact_status = PQTRANS_INERROR             # <<<<<<<<<<<<<<
+ *         else:
+ *             self.xact_status = PQTRANS_UNKNOWN
+ */
+    __pyx_v_self->xact_status = __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_INERROR;
+
+    /* "asyncpg/protocol/coreproto.pyx":598
+ *         elif status == b'T':
+ *             self.xact_status = PQTRANS_INTRANS
+ *         elif status == b'E':             # <<<<<<<<<<<<<<
+ *             self.xact_status = PQTRANS_INERROR
+ *         else:
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/coreproto.pyx":601
+ *             self.xact_status = PQTRANS_INERROR
+ *         else:
+ *             self.xact_status = PQTRANS_UNKNOWN             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _parse_msg_error_response(self, is_error):
+ */
+    __pyx_v_self->xact_status = __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_UNKNOWN;
+    break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":591
+ *         return msg
+ * 
+ *     cdef _parse_msg_ready_for_query(self):             # <<<<<<<<<<<<<<
+ *         cdef char status = self.buffer.read_byte()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_ready_for_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":603
+ *             self.xact_status = PQTRANS_UNKNOWN
+ * 
+ *     cdef _parse_msg_error_response(self, is_error):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             char code
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_error_response(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_is_error) {
+  char __pyx_v_code;
+  PyObject *__pyx_v_message = 0;
+  PyObject *__pyx_v_parsed = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  char __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_parse_msg_error_response", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":607
+ *             char code
+ *             bytes message
+ *             dict parsed = {}             # <<<<<<<<<<<<<<
+ * 
+ *         while True:
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 607, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_parsed = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":609
+ *             dict parsed = {}
+ * 
+ *         while True:             # <<<<<<<<<<<<<<
+ *             code = self.buffer.read_byte()
+ *             if code == 0:
+ */
+  while (1) {
+
+    /* "asyncpg/protocol/coreproto.pyx":610
+ * 
+ *         while True:
+ *             code = self.buffer.read_byte()             # <<<<<<<<<<<<<<
+ *             if code == 0:
+ *                 break
+ */
+    __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_byte(__pyx_v_self->buffer); if (unlikely(__pyx_t_2 == ((char)-1) && PyErr_Occurred())) __PYX_ERR(5, 610, __pyx_L1_error)
+    __pyx_v_code = __pyx_t_2;
+
+    /* "asyncpg/protocol/coreproto.pyx":611
+ *         while True:
+ *             code = self.buffer.read_byte()
+ *             if code == 0:             # <<<<<<<<<<<<<<
+ *                 break
+ * 
+ */
+    __pyx_t_3 = ((__pyx_v_code == 0) != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/protocol/coreproto.pyx":612
+ *             code = self.buffer.read_byte()
+ *             if code == 0:
+ *                 break             # <<<<<<<<<<<<<<
+ * 
+ *             message = self.buffer.read_cstr()
+ */
+      goto __pyx_L4_break;
+
+      /* "asyncpg/protocol/coreproto.pyx":611
+ *         while True:
+ *             code = self.buffer.read_byte()
+ *             if code == 0:             # <<<<<<<<<<<<<<
+ *                 break
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":614
+ *                 break
+ * 
+ *             message = self.buffer.read_cstr()             # <<<<<<<<<<<<<<
+ * 
+ *             parsed[chr(code)] = message.decode()
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->buffer->__pyx_vtab)->read_cstr(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 614, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(5, 614, __pyx_L1_error)
+    __Pyx_XDECREF_SET(__pyx_v_message, ((PyObject*)__pyx_t_1));
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":616
+ *             message = self.buffer.read_cstr()
+ * 
+ *             parsed[chr(code)] = message.decode()             # <<<<<<<<<<<<<<
+ * 
+ *         if is_error:
+ */
+    if (unlikely(__pyx_v_message == Py_None)) {
+      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "decode");
+      __PYX_ERR(5, 616, __pyx_L1_error)
+    }
+    __pyx_t_1 = __Pyx_decode_bytes(__pyx_v_message, 0, PY_SSIZE_T_MAX, NULL, NULL, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 616, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 616, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 616, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(PyDict_SetItem(__pyx_v_parsed, __pyx_t_5, __pyx_t_1) < 0)) __PYX_ERR(5, 616, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+  __pyx_L4_break:;
+
+  /* "asyncpg/protocol/coreproto.pyx":618
+ *             parsed[chr(code)] = message.decode()
+ * 
+ *         if is_error:             # <<<<<<<<<<<<<<
+ *             self.result_type = RESULT_FAILED
+ *             self.result = parsed
+ */
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_is_error); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(5, 618, __pyx_L1_error)
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/coreproto.pyx":619
+ * 
+ *         if is_error:
+ *             self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *             self.result = parsed
+ *         else:
+ */
+    __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+    /* "asyncpg/protocol/coreproto.pyx":620
+ *         if is_error:
+ *             self.result_type = RESULT_FAILED
+ *             self.result = parsed             # <<<<<<<<<<<<<<
+ *         else:
+ *             return parsed
+ */
+    __Pyx_INCREF(__pyx_v_parsed);
+    __Pyx_GIVEREF(__pyx_v_parsed);
+    __Pyx_GOTREF(__pyx_v_self->result);
+    __Pyx_DECREF(__pyx_v_self->result);
+    __pyx_v_self->result = __pyx_v_parsed;
+
+    /* "asyncpg/protocol/coreproto.pyx":618
+ *             parsed[chr(code)] = message.decode()
+ * 
+ *         if is_error:             # <<<<<<<<<<<<<<
+ *             self.result_type = RESULT_FAILED
+ *             self.result = parsed
+ */
+    goto __pyx_L6;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":622
+ *             self.result = parsed
+ *         else:
+ *             return parsed             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _push_result(self):
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(__pyx_v_parsed);
+    __pyx_r = __pyx_v_parsed;
+    goto __pyx_L0;
+  }
+  __pyx_L6:;
+
+  /* "asyncpg/protocol/coreproto.pyx":603
+ *             self.xact_status = PQTRANS_UNKNOWN
+ * 
+ *     cdef _parse_msg_error_response(self, is_error):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             char code
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._parse_msg_error_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_message);
+  __Pyx_XDECREF(__pyx_v_parsed);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":624
+ *             return parsed
+ * 
+ *     cdef _push_result(self):             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._on_result()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__push_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  char const *__pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  __Pyx_RefNannySetupContext("_push_result", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":625
+ * 
+ *     cdef _push_result(self):
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._on_result()
+ *         finally:
+ */
+  /*try:*/ {
+
+    /* "asyncpg/protocol/coreproto.pyx":626
+ *     cdef _push_result(self):
+ *         try:
+ *             self._on_result()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             self._set_state(PROTOCOL_IDLE)
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_on_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 626, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":628
+ *             self._on_result()
+ *         finally:
+ *             self._set_state(PROTOCOL_IDLE)             # <<<<<<<<<<<<<<
+ *             self._reset_result()
+ * 
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 628, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":629
+ *         finally:
+ *             self._set_state(PROTOCOL_IDLE)
+ *             self._reset_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _reset_result(self):
+ */
+      __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_reset_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 629, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      goto __pyx_L5;
+    }
+    __pyx_L4_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0)) __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __pyx_t_2 = __pyx_lineno; __pyx_t_3 = __pyx_clineno; __pyx_t_4 = __pyx_filename;
+      {
+
+        /* "asyncpg/protocol/coreproto.pyx":628
+ *             self._on_result()
+ *         finally:
+ *             self._set_state(PROTOCOL_IDLE)             # <<<<<<<<<<<<<<
+ *             self._reset_result()
+ * 
+ */
+        __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 628, __pyx_L7_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+        /* "asyncpg/protocol/coreproto.pyx":629
+ *         finally:
+ *             self._set_state(PROTOCOL_IDLE)
+ *             self._reset_result()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _reset_result(self):
+ */
+        __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_reset_result(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 629, __pyx_L7_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_8);
+        __Pyx_XGIVEREF(__pyx_t_9);
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
+      }
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_7);
+      __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0;
+      __pyx_lineno = __pyx_t_2; __pyx_clineno = __pyx_t_3; __pyx_filename = __pyx_t_4;
+      goto __pyx_L1_error;
+      __pyx_L7_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_8);
+        __Pyx_XGIVEREF(__pyx_t_9);
+        __Pyx_XGIVEREF(__pyx_t_10);
+        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
+      }
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0;
+      goto __pyx_L1_error;
+    }
+    __pyx_L5:;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":624
+ *             return parsed
+ * 
+ *     cdef _push_result(self):             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._on_result()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._push_result", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":631
+ *             self._reset_result()
+ * 
+ *     cdef _reset_result(self):             # <<<<<<<<<<<<<<
+ *         self.result_type = RESULT_OK
+ *         self.result = None
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__reset_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_reset_result", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":632
+ * 
+ *     cdef _reset_result(self):
+ *         self.result_type = RESULT_OK             # <<<<<<<<<<<<<<
+ *         self.result = None
+ *         self.result_param_desc = None
+ */
+  __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_OK;
+
+  /* "asyncpg/protocol/coreproto.pyx":633
+ *     cdef _reset_result(self):
+ *         self.result_type = RESULT_OK
+ *         self.result = None             # <<<<<<<<<<<<<<
+ *         self.result_param_desc = None
+ *         self.result_row_desc = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->result);
+  __Pyx_DECREF(__pyx_v_self->result);
+  __pyx_v_self->result = Py_None;
+
+  /* "asyncpg/protocol/coreproto.pyx":634
+ *         self.result_type = RESULT_OK
+ *         self.result = None
+ *         self.result_param_desc = None             # <<<<<<<<<<<<<<
+ *         self.result_row_desc = None
+ *         self.result_status_msg = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->result_param_desc);
+  __Pyx_DECREF(__pyx_v_self->result_param_desc);
+  __pyx_v_self->result_param_desc = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/coreproto.pyx":635
+ *         self.result = None
+ *         self.result_param_desc = None
+ *         self.result_row_desc = None             # <<<<<<<<<<<<<<
+ *         self.result_status_msg = None
+ *         self.result_execute_completed = False
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->result_row_desc);
+  __Pyx_DECREF(__pyx_v_self->result_row_desc);
+  __pyx_v_self->result_row_desc = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/coreproto.pyx":636
+ *         self.result_param_desc = None
+ *         self.result_row_desc = None
+ *         self.result_status_msg = None             # <<<<<<<<<<<<<<
+ *         self.result_execute_completed = False
+ *         self._discard_data = False
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->result_status_msg);
+  __Pyx_DECREF(__pyx_v_self->result_status_msg);
+  __pyx_v_self->result_status_msg = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/coreproto.pyx":637
+ *         self.result_row_desc = None
+ *         self.result_status_msg = None
+ *         self.result_execute_completed = False             # <<<<<<<<<<<<<<
+ *         self._discard_data = False
+ * 
+ */
+  __pyx_v_self->result_execute_completed = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":638
+ *         self.result_status_msg = None
+ *         self.result_execute_completed = False
+ *         self._discard_data = False             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _set_state(self, ProtocolState new_state):
+ */
+  __pyx_v_self->_discard_data = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":631
+ *             self._reset_result()
+ * 
+ *     cdef _reset_result(self):             # <<<<<<<<<<<<<<
+ *         self.result_type = RESULT_OK
+ *         self.result = None
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":640
+ *         self._discard_data = False
+ * 
+ *     cdef _set_state(self, ProtocolState new_state):             # <<<<<<<<<<<<<<
+ *         if new_state == PROTOCOL_IDLE:
+ *             if self.state == PROTOCOL_FAILED:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __pyx_v_new_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  __Pyx_RefNannySetupContext("_set_state", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":641
+ * 
+ *     cdef _set_state(self, ProtocolState new_state):
+ *         if new_state == PROTOCOL_IDLE:             # <<<<<<<<<<<<<<
+ *             if self.state == PROTOCOL_FAILED:
+ *                 raise apg_exc.InternalClientError(
+ */
+  switch (__pyx_v_new_state) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE:
+
+    /* "asyncpg/protocol/coreproto.pyx":642
+ *     cdef _set_state(self, ProtocolState new_state):
+ *         if new_state == PROTOCOL_IDLE:
+ *             if self.state == PROTOCOL_FAILED:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     'cannot switch to "idle" state; '
+ */
+    switch (__pyx_v_self->state) {
+      case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED:
+
+      /* "asyncpg/protocol/coreproto.pyx":643
+ *         if new_state == PROTOCOL_IDLE:
+ *             if self.state == PROTOCOL_FAILED:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'cannot switch to "idle" state; '
+ *                     'protocol is in the "failed" state')
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 643, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 643, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __pyx_t_2 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_2)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_2);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_cannot_switch_to_idle_state_prot) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_cannot_switch_to_idle_state_prot);
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 643, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(5, 643, __pyx_L1_error)
+
+      /* "asyncpg/protocol/coreproto.pyx":642
+ *     cdef _set_state(self, ProtocolState new_state):
+ *         if new_state == PROTOCOL_IDLE:
+ *             if self.state == PROTOCOL_FAILED:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     'cannot switch to "idle" state; '
+ */
+      break;
+      case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE:
+
+      /* "asyncpg/protocol/coreproto.pyx":646
+ *                     'cannot switch to "idle" state; '
+ *                     'protocol is in the "failed" state')
+ *             elif self.state == PROTOCOL_IDLE:             # <<<<<<<<<<<<<<
+ *                 pass
+ *             else:
+ */
+      break;
+      default:
+
+      /* "asyncpg/protocol/coreproto.pyx":649
+ *                 pass
+ *             else:
+ *                 self.state = new_state             # <<<<<<<<<<<<<<
+ * 
+ *         elif new_state == PROTOCOL_FAILED:
+ */
+      __pyx_v_self->state = __pyx_v_new_state;
+      break;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":641
+ * 
+ *     cdef _set_state(self, ProtocolState new_state):
+ *         if new_state == PROTOCOL_IDLE:             # <<<<<<<<<<<<<<
+ *             if self.state == PROTOCOL_FAILED:
+ *                 raise apg_exc.InternalClientError(
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED:
+
+    /* "asyncpg/protocol/coreproto.pyx":652
+ * 
+ *         elif new_state == PROTOCOL_FAILED:
+ *             self.state = PROTOCOL_FAILED             # <<<<<<<<<<<<<<
+ * 
+ *         elif new_state == PROTOCOL_CANCELLED:
+ */
+    __pyx_v_self->state = __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED;
+
+    /* "asyncpg/protocol/coreproto.pyx":651
+ *                 self.state = new_state
+ * 
+ *         elif new_state == PROTOCOL_FAILED:             # <<<<<<<<<<<<<<
+ *             self.state = PROTOCOL_FAILED
+ * 
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CANCELLED:
+
+    /* "asyncpg/protocol/coreproto.pyx":655
+ * 
+ *         elif new_state == PROTOCOL_CANCELLED:
+ *             self.state = PROTOCOL_CANCELLED             # <<<<<<<<<<<<<<
+ * 
+ *         elif new_state == PROTOCOL_TERMINATING:
+ */
+    __pyx_v_self->state = __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CANCELLED;
+
+    /* "asyncpg/protocol/coreproto.pyx":654
+ *             self.state = PROTOCOL_FAILED
+ * 
+ *         elif new_state == PROTOCOL_CANCELLED:             # <<<<<<<<<<<<<<
+ *             self.state = PROTOCOL_CANCELLED
+ * 
+ */
+    break;
+    case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_TERMINATING:
+
+    /* "asyncpg/protocol/coreproto.pyx":658
+ * 
+ *         elif new_state == PROTOCOL_TERMINATING:
+ *             self.state = PROTOCOL_TERMINATING             # <<<<<<<<<<<<<<
+ * 
+ *         else:
+ */
+    __pyx_v_self->state = __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_TERMINATING;
+
+    /* "asyncpg/protocol/coreproto.pyx":657
+ *             self.state = PROTOCOL_CANCELLED
+ * 
+ *         elif new_state == PROTOCOL_TERMINATING:             # <<<<<<<<<<<<<<
+ *             self.state = PROTOCOL_TERMINATING
+ * 
+ */
+    break;
+    default:
+
+    /* "asyncpg/protocol/coreproto.pyx":661
+ * 
+ *         else:
+ *             if self.state == PROTOCOL_IDLE:             # <<<<<<<<<<<<<<
+ *                 self.state = new_state
+ * 
+ */
+    __pyx_t_4 = ((__pyx_v_self->state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_IDLE) != 0);
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/coreproto.pyx":662
+ *         else:
+ *             if self.state == PROTOCOL_IDLE:
+ *                 self.state = new_state             # <<<<<<<<<<<<<<
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT and
+ */
+      __pyx_v_self->state = __pyx_v_new_state;
+
+      /* "asyncpg/protocol/coreproto.pyx":661
+ * 
+ *         else:
+ *             if self.state == PROTOCOL_IDLE:             # <<<<<<<<<<<<<<
+ *                 self.state = new_state
+ * 
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":664
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_OUT_DATA):
+ *                 self.state = new_state
+ */
+    __pyx_t_5 = ((__pyx_v_self->state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT) != 0);
+    if (__pyx_t_5) {
+    } else {
+      __pyx_t_4 = __pyx_t_5;
+      goto __pyx_L4_bool_binop_done;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":665
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT and
+ *                     new_state == PROTOCOL_COPY_OUT_DATA):             # <<<<<<<<<<<<<<
+ *                 self.state = new_state
+ * 
+ */
+    __pyx_t_5 = ((__pyx_v_new_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DATA) != 0);
+    __pyx_t_4 = __pyx_t_5;
+    __pyx_L4_bool_binop_done:;
+
+    /* "asyncpg/protocol/coreproto.pyx":664
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_OUT_DATA):
+ *                 self.state = new_state
+ */
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/coreproto.pyx":666
+ *             elif (self.state == PROTOCOL_COPY_OUT and
+ *                     new_state == PROTOCOL_COPY_OUT_DATA):
+ *                 self.state = new_state             # <<<<<<<<<<<<<<
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA and
+ */
+      __pyx_v_self->state = __pyx_v_new_state;
+
+      /* "asyncpg/protocol/coreproto.pyx":664
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_OUT_DATA):
+ *                 self.state = new_state
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":668
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_OUT_DONE):
+ *                 self.state = new_state
+ */
+    __pyx_t_5 = ((__pyx_v_self->state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DATA) != 0);
+    if (__pyx_t_5) {
+    } else {
+      __pyx_t_4 = __pyx_t_5;
+      goto __pyx_L6_bool_binop_done;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":669
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA and
+ *                     new_state == PROTOCOL_COPY_OUT_DONE):             # <<<<<<<<<<<<<<
+ *                 self.state = new_state
+ * 
+ */
+    __pyx_t_5 = ((__pyx_v_new_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DONE) != 0);
+    __pyx_t_4 = __pyx_t_5;
+    __pyx_L6_bool_binop_done:;
+
+    /* "asyncpg/protocol/coreproto.pyx":668
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_OUT_DONE):
+ *                 self.state = new_state
+ */
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/coreproto.pyx":670
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA and
+ *                     new_state == PROTOCOL_COPY_OUT_DONE):
+ *                 self.state = new_state             # <<<<<<<<<<<<<<
+ * 
+ *             elif (self.state == PROTOCOL_COPY_IN and
+ */
+      __pyx_v_self->state = __pyx_v_new_state;
+
+      /* "asyncpg/protocol/coreproto.pyx":668
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_OUT_DONE):
+ *                 self.state = new_state
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":672
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_IN and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_IN_DATA):
+ *                 self.state = new_state
+ */
+    __pyx_t_5 = ((__pyx_v_self->state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN) != 0);
+    if (__pyx_t_5) {
+    } else {
+      __pyx_t_4 = __pyx_t_5;
+      goto __pyx_L8_bool_binop_done;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":673
+ * 
+ *             elif (self.state == PROTOCOL_COPY_IN and
+ *                     new_state == PROTOCOL_COPY_IN_DATA):             # <<<<<<<<<<<<<<
+ *                 self.state = new_state
+ * 
+ */
+    __pyx_t_5 = ((__pyx_v_new_state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN_DATA) != 0);
+    __pyx_t_4 = __pyx_t_5;
+    __pyx_L8_bool_binop_done:;
+
+    /* "asyncpg/protocol/coreproto.pyx":672
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_IN and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_IN_DATA):
+ *                 self.state = new_state
+ */
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/coreproto.pyx":674
+ *             elif (self.state == PROTOCOL_COPY_IN and
+ *                     new_state == PROTOCOL_COPY_IN_DATA):
+ *                 self.state = new_state             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_FAILED:
+ */
+      __pyx_v_self->state = __pyx_v_new_state;
+
+      /* "asyncpg/protocol/coreproto.pyx":672
+ *                 self.state = new_state
+ * 
+ *             elif (self.state == PROTOCOL_COPY_IN and             # <<<<<<<<<<<<<<
+ *                     new_state == PROTOCOL_COPY_IN_DATA):
+ *                 self.state = new_state
+ */
+      goto __pyx_L3;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":676
+ *                 self.state = new_state
+ * 
+ *             elif self.state == PROTOCOL_FAILED:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     'cannot switch to state {}; '
+ */
+    __pyx_t_4 = ((__pyx_v_self->state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED) != 0);
+    if (unlikely(__pyx_t_4)) {
+
+      /* "asyncpg/protocol/coreproto.pyx":677
+ * 
+ *             elif self.state == PROTOCOL_FAILED:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'cannot switch to state {}; '
+ *                     'protocol is in the "failed" state'.format(new_state))
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 677, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 677, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":679
+ *                 raise apg_exc.InternalClientError(
+ *                     'cannot switch to state {}; '
+ *                     'protocol is in the "failed" state'.format(new_state))             # <<<<<<<<<<<<<<
+ *             else:
+ *                 raise apg_exc.InternalClientError(
+ */
+      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_cannot_switch_to_state_protocol, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(5, 679, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_7 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_new_state); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 679, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_8 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
+        if (likely(__pyx_t_8)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+          __Pyx_INCREF(__pyx_t_8);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_6, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 679, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_2, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 677, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(5, 677, __pyx_L1_error)
+
+      /* "asyncpg/protocol/coreproto.pyx":676
+ *                 self.state = new_state
+ * 
+ *             elif self.state == PROTOCOL_FAILED:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     'cannot switch to state {}; '
+ */
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":681
+ *                     'protocol is in the "failed" state'.format(new_state))
+ *             else:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'cannot switch to state {}; '
+ *                     'another operation ({}) is in progress'.format(
+ */
+    /*else*/ {
+      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 681, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 681, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":683
+ *                 raise apg_exc.InternalClientError(
+ *                     'cannot switch to state {}; '
+ *                     'another operation ({}) is in progress'.format(             # <<<<<<<<<<<<<<
+ *                         new_state, self.state))
+ * 
+ */
+      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_cannot_switch_to_state_another_o, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(5, 683, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+
+      /* "asyncpg/protocol/coreproto.pyx":684
+ *                     'cannot switch to state {}; '
+ *                     'another operation ({}) is in progress'.format(
+ *                         new_state, self.state))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _ensure_connected(self):
+ */
+      __pyx_t_7 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_new_state); if (unlikely(!__pyx_t_7)) __PYX_ERR(5, 684, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_8 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_self->state); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 684, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __pyx_t_9 = NULL;
+      __pyx_t_10 = 0;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
+        if (likely(__pyx_t_9)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+          __Pyx_INCREF(__pyx_t_9);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_6, function);
+          __pyx_t_10 = 1;
+        }
+      }
+      #if CYTHON_FAST_PYCALL
+      if (PyFunction_Check(__pyx_t_6)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
+        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 683, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      } else
+      #endif
+      #if CYTHON_FAST_PYCCALL
+      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
+        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 683, __pyx_L1_error)
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      } else
+      #endif
+      {
+        __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(5, 683, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        if (__pyx_t_9) {
+          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+        }
+        __Pyx_GIVEREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_7);
+        __Pyx_GIVEREF(__pyx_t_8);
+        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
+        __pyx_t_7 = 0;
+        __pyx_t_8 = 0;
+        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 683, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_2);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_3, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 681, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(5, 681, __pyx_L1_error)
+    }
+    __pyx_L3:;
+    break;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":640
+ *         self._discard_data = False
+ * 
+ *     cdef _set_state(self, ProtocolState new_state):             # <<<<<<<<<<<<<<
+ *         if new_state == PROTOCOL_IDLE:
+ *             if self.state == PROTOCOL_FAILED:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":686
+ *                         new_state, self.state))
+ * 
+ *     cdef _ensure_connected(self):             # <<<<<<<<<<<<<<
+ *         if self.con_status != CONNECTION_OK:
+ *             raise apg_exc.InternalClientError('not connected')
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__ensure_connected(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_ensure_connected", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":687
+ * 
+ *     cdef _ensure_connected(self):
+ *         if self.con_status != CONNECTION_OK:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError('not connected')
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_self->con_status != __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_OK) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/protocol/coreproto.pyx":688
+ *     cdef _ensure_connected(self):
+ *         if self.con_status != CONNECTION_OK:
+ *             raise apg_exc.InternalClientError('not connected')             # <<<<<<<<<<<<<<
+ * 
+ *     cdef WriteBuffer _build_bind_message(self, str portal_name,
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 688, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 688, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_not_connected) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_not_connected);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 688, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(5, 688, __pyx_L1_error)
+
+    /* "asyncpg/protocol/coreproto.pyx":687
+ * 
+ *     cdef _ensure_connected(self):
+ *         if self.con_status != CONNECTION_OK:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError('not connected')
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":686
+ *                         new_state, self.state))
+ * 
+ *     cdef _ensure_connected(self):             # <<<<<<<<<<<<<<
+ *         if self.con_status != CONNECTION_OK:
+ *             raise apg_exc.InternalClientError('not connected')
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._ensure_connected", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":690
+ *             raise apg_exc.InternalClientError('not connected')
+ * 
+ *     cdef WriteBuffer _build_bind_message(self, str portal_name,             # <<<<<<<<<<<<<<
+ *                                          str stmt_name,
+ *                                          WriteBuffer bind_data):
+ */
+
+static struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__build_bind_message(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_build_bind_message", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":695
+ *         cdef WriteBuffer buf
+ * 
+ *         buf = WriteBuffer.new_message(b'B')             # <<<<<<<<<<<<<<
+ *         buf.write_str(portal_name, self.encoding)
+ *         buf.write_str(stmt_name, self.encoding)
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('B')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 695, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":696
+ * 
+ *         buf = WriteBuffer.new_message(b'B')
+ *         buf.write_str(portal_name, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.write_str(stmt_name, self.encoding)
+ * 
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_portal_name, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 696, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":697
+ *         buf = WriteBuffer.new_message(b'B')
+ *         buf.write_str(portal_name, self.encoding)
+ *         buf.write_str(stmt_name, self.encoding)             # <<<<<<<<<<<<<<
+ * 
+ *         # Arguments
+ */
+  __pyx_t_2 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_stmt_name, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 697, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":700
+ * 
+ *         # Arguments
+ *         buf.write_buffer(bind_data)             # <<<<<<<<<<<<<<
+ * 
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_buffer(__pyx_v_buf, __pyx_v_bind_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 700, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":702
+ *         buf.write_buffer(bind_data)
+ * 
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         return buf
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 702, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":703
+ * 
+ *         buf.end_message()
+ *         return buf             # <<<<<<<<<<<<<<
+ * 
+ *     # API for subclasses
+ */
+  __Pyx_XDECREF(((PyObject *)__pyx_r));
+  __Pyx_INCREF(((PyObject *)__pyx_v_buf));
+  __pyx_r = __pyx_v_buf;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/coreproto.pyx":690
+ *             raise apg_exc.InternalClientError('not connected')
+ * 
+ *     cdef WriteBuffer _build_bind_message(self, str portal_name,             # <<<<<<<<<<<<<<
+ *                                          str stmt_name,
+ *                                          WriteBuffer bind_data):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._build_bind_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF((PyObject *)__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":707
+ *     # API for subclasses
+ * 
+ *     cdef _connect(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__connect(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_outbuf = 0;
+  PyObject *__pyx_v_k = NULL;
+  PyObject *__pyx_v_v = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  Py_ssize_t __pyx_t_7;
+  Py_ssize_t __pyx_t_8;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  int32_t __pyx_t_11;
+  __Pyx_RefNannySetupContext("_connect", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":712
+ *             WriteBuffer outbuf
+ * 
+ *         if self.con_status != CONNECTION_BAD:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError('already connected')
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_self->con_status != __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/protocol/coreproto.pyx":713
+ * 
+ *         if self.con_status != CONNECTION_BAD:
+ *             raise apg_exc.InternalClientError('already connected')             # <<<<<<<<<<<<<<
+ * 
+ *         self._set_state(PROTOCOL_AUTH)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 713, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 713, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_kp_u_already_connected) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_already_connected);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 713, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __PYX_ERR(5, 713, __pyx_L1_error)
+
+    /* "asyncpg/protocol/coreproto.pyx":712
+ *             WriteBuffer outbuf
+ * 
+ *         if self.con_status != CONNECTION_BAD:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError('already connected')
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":715
+ *             raise apg_exc.InternalClientError('already connected')
+ * 
+ *         self._set_state(PROTOCOL_AUTH)             # <<<<<<<<<<<<<<
+ *         self.con_status = CONNECTION_STARTED
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_AUTH); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 715, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":716
+ * 
+ *         self._set_state(PROTOCOL_AUTH)
+ *         self.con_status = CONNECTION_STARTED             # <<<<<<<<<<<<<<
+ * 
+ *         # Assemble a startup message
+ */
+  __pyx_v_self->con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_STARTED;
+
+  /* "asyncpg/protocol/coreproto.pyx":719
+ * 
+ *         # Assemble a startup message
+ *         buf = WriteBuffer()             # <<<<<<<<<<<<<<
+ * 
+ *         # protocol version
+ */
+  __pyx_t_2 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 719, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":722
+ * 
+ *         # protocol version
+ *         buf.write_int16(3)             # <<<<<<<<<<<<<<
+ *         buf.write_int16(0)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int16(__pyx_v_buf, 3); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 722, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":723
+ *         # protocol version
+ *         buf.write_int16(3)
+ *         buf.write_int16(0)             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_bytestring(b'client_encoding')
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int16(__pyx_v_buf, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 723, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":725
+ *         buf.write_int16(0)
+ * 
+ *         buf.write_bytestring(b'client_encoding')             # <<<<<<<<<<<<<<
+ *         buf.write_bytestring("'{}'".format(self.encoding).encode('ascii'))
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_bytestring(__pyx_v_buf, __pyx_n_b_client_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 725, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":726
+ * 
+ *         buf.write_bytestring(b'client_encoding')
+ *         buf.write_bytestring("'{}'".format(self.encoding).encode('ascii'))             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_str('user', self.encoding)
+ */
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u__26, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_self->encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->encoding);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_n_u_ascii) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_n_u_ascii);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(5, 726, __pyx_L1_error)
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_bytestring(__pyx_v_buf, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":728
+ *         buf.write_bytestring("'{}'".format(self.encoding).encode('ascii'))
+ * 
+ *         buf.write_str('user', self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.write_str(self.con_params.user, self.encoding)
+ * 
+ */
+  __pyx_t_3 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_3);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_n_u_user, ((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 728, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":729
+ * 
+ *         buf.write_str('user', self.encoding)
+ *         buf.write_str(self.con_params.user, self.encoding)             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_str('database', self.encoding)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->con_params, __pyx_n_s_user); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 729, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(5, 729, __pyx_L1_error)
+  __pyx_t_3 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_3);
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, ((PyObject*)__pyx_t_2), ((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 729, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":731
+ *         buf.write_str(self.con_params.user, self.encoding)
+ * 
+ *         buf.write_str('database', self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.write_str(self.con_params.database, self.encoding)
+ * 
+ */
+  __pyx_t_4 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_4);
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_n_u_database, ((PyObject*)__pyx_t_4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 731, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":732
+ * 
+ *         buf.write_str('database', self.encoding)
+ *         buf.write_str(self.con_params.database, self.encoding)             # <<<<<<<<<<<<<<
+ * 
+ *         if self.con_params.server_settings is not None:
+ */
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->con_params, __pyx_n_s_database); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 732, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(5, 732, __pyx_L1_error)
+  __pyx_t_4 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_4);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, ((PyObject*)__pyx_t_3), ((PyObject*)__pyx_t_4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 732, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":734
+ *         buf.write_str(self.con_params.database, self.encoding)
+ * 
+ *         if self.con_params.server_settings is not None:             # <<<<<<<<<<<<<<
+ *             for k, v in self.con_params.server_settings.items():
+ *                 buf.write_str(k, self.encoding)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->con_params, __pyx_n_s_server_settings); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 734, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = (__pyx_t_2 != Py_None);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_6 = (__pyx_t_1 != 0);
+  if (__pyx_t_6) {
+
+    /* "asyncpg/protocol/coreproto.pyx":735
+ * 
+ *         if self.con_params.server_settings is not None:
+ *             for k, v in self.con_params.server_settings.items():             # <<<<<<<<<<<<<<
+ *                 buf.write_str(k, self.encoding)
+ *                 buf.write_str(v, self.encoding)
+ */
+    __pyx_t_7 = 0;
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->con_params, __pyx_n_s_server_settings); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 735, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    if (unlikely(__pyx_t_4 == Py_None)) {
+      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items");
+      __PYX_ERR(5, 735, __pyx_L1_error)
+    }
+    __pyx_t_3 = __Pyx_dict_iterator(__pyx_t_4, 0, __pyx_n_s_items, (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 735, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_XDECREF(__pyx_t_2);
+    __pyx_t_2 = __pyx_t_3;
+    __pyx_t_3 = 0;
+    while (1) {
+      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_8, &__pyx_t_7, &__pyx_t_3, &__pyx_t_4, NULL, __pyx_t_9);
+      if (unlikely(__pyx_t_10 == 0)) break;
+      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(5, 735, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3);
+      __pyx_t_3 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_4);
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":736
+ *         if self.con_params.server_settings is not None:
+ *             for k, v in self.con_params.server_settings.items():
+ *                 buf.write_str(k, self.encoding)             # <<<<<<<<<<<<<<
+ *                 buf.write_str(v, self.encoding)
+ * 
+ */
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_k))||((__pyx_v_k) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_k)->tp_name), 0))) __PYX_ERR(5, 736, __pyx_L1_error)
+      __pyx_t_4 = __pyx_v_self->encoding;
+      __Pyx_INCREF(__pyx_t_4);
+      __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, ((PyObject*)__pyx_v_k), ((PyObject*)__pyx_t_4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 736, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":737
+ *             for k, v in self.con_params.server_settings.items():
+ *                 buf.write_str(k, self.encoding)
+ *                 buf.write_str(v, self.encoding)             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_bytestring(b'')
+ */
+      if (!(likely(PyUnicode_CheckExact(__pyx_v_v))||((__pyx_v_v) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_v)->tp_name), 0))) __PYX_ERR(5, 737, __pyx_L1_error)
+      __pyx_t_3 = __pyx_v_self->encoding;
+      __Pyx_INCREF(__pyx_t_3);
+      __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, ((PyObject*)__pyx_v_v), ((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 737, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":734
+ *         buf.write_str(self.con_params.database, self.encoding)
+ * 
+ *         if self.con_params.server_settings is not None:             # <<<<<<<<<<<<<<
+ *             for k, v in self.con_params.server_settings.items():
+ *                 buf.write_str(k, self.encoding)
+ */
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":739
+ *                 buf.write_str(v, self.encoding)
+ * 
+ *         buf.write_bytestring(b'')             # <<<<<<<<<<<<<<
+ * 
+ *         # Send the buffer
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_bytestring(__pyx_v_buf, __pyx_kp_b__25); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 739, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":742
+ * 
+ *         # Send the buffer
+ *         outbuf = WriteBuffer()             # <<<<<<<<<<<<<<
+ *         outbuf.write_int32(buf.len() + 4)
+ *         outbuf.write_buffer(buf)
+ */
+  __pyx_t_2 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 742, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_outbuf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":743
+ *         # Send the buffer
+ *         outbuf = WriteBuffer()
+ *         outbuf.write_int32(buf.len() + 4)             # <<<<<<<<<<<<<<
+ *         outbuf.write_buffer(buf)
+ *         self._write(outbuf)
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 743, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_4, 4, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 743, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_11 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(5, 743, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_outbuf->__pyx_vtab)->write_int32(__pyx_v_outbuf, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 743, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":744
+ *         outbuf = WriteBuffer()
+ *         outbuf.write_int32(buf.len() + 4)
+ *         outbuf.write_buffer(buf)             # <<<<<<<<<<<<<<
+ *         self._write(outbuf)
+ * 
+ */
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_outbuf->__pyx_vtab)->write_buffer(__pyx_v_outbuf, __pyx_v_buf); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 744, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":745
+ *         outbuf.write_int32(buf.len() + 4)
+ *         outbuf.write_buffer(buf)
+ *         self._write(outbuf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _prepare(self, str stmt_name, str query):
+ */
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_outbuf)); if (unlikely(!__pyx_t_4)) __PYX_ERR(5, 745, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":707
+ *     # API for subclasses
+ * 
+ *     cdef _connect(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer buf
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._connect", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XDECREF((PyObject *)__pyx_v_outbuf);
+  __Pyx_XDECREF(__pyx_v_k);
+  __Pyx_XDECREF(__pyx_v_v);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":747
+ *         self._write(outbuf)
+ * 
+ *     cdef _prepare(self, str stmt_name, str query):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer packet
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_stmt_name, PyObject *__pyx_v_query) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_packet = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_prepare", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":752
+ *             WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_PREPARE)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 752, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":753
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_PREPARE)             # <<<<<<<<<<<<<<
+ * 
+ *         buf = WriteBuffer.new_message(b'P')
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_PREPARE); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 753, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":755
+ *         self._set_state(PROTOCOL_PREPARE)
+ * 
+ *         buf = WriteBuffer.new_message(b'P')             # <<<<<<<<<<<<<<
+ *         buf.write_str(stmt_name, self.encoding)
+ *         buf.write_str(query, self.encoding)
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('P')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 755, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":756
+ * 
+ *         buf = WriteBuffer.new_message(b'P')
+ *         buf.write_str(stmt_name, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.write_str(query, self.encoding)
+ *         buf.write_int16(0)
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_stmt_name, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 756, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":757
+ *         buf = WriteBuffer.new_message(b'P')
+ *         buf.write_str(stmt_name, self.encoding)
+ *         buf.write_str(query, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.write_int16(0)
+ *         buf.end_message()
+ */
+  __pyx_t_2 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_query, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 757, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":758
+ *         buf.write_str(stmt_name, self.encoding)
+ *         buf.write_str(query, self.encoding)
+ *         buf.write_int16(0)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         packet = buf
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int16(__pyx_v_buf, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 758, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":759
+ *         buf.write_str(query, self.encoding)
+ *         buf.write_int16(0)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         packet = buf
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 759, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":760
+ *         buf.write_int16(0)
+ *         buf.end_message()
+ *         packet = buf             # <<<<<<<<<<<<<<
+ * 
+ *         buf = WriteBuffer.new_message(b'D')
+ */
+  __Pyx_INCREF(((PyObject *)__pyx_v_buf));
+  __pyx_v_packet = __pyx_v_buf;
+
+  /* "asyncpg/protocol/coreproto.pyx":762
+ *         packet = buf
+ * 
+ *         buf = WriteBuffer.new_message(b'D')             # <<<<<<<<<<<<<<
+ *         buf.write_byte(b'S')
+ *         buf.write_str(stmt_name, self.encoding)
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('D')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 762, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF_SET(__pyx_v_buf, ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1));
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":763
+ * 
+ *         buf = WriteBuffer.new_message(b'D')
+ *         buf.write_byte(b'S')             # <<<<<<<<<<<<<<
+ *         buf.write_str(stmt_name, self.encoding)
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_byte(__pyx_v_buf, 'S'); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 763, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":764
+ *         buf = WriteBuffer.new_message(b'D')
+ *         buf.write_byte(b'S')
+ *         buf.write_str(stmt_name, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         packet.write_buffer(buf)
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_stmt_name, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 764, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":765
+ *         buf.write_byte(b'S')
+ *         buf.write_str(stmt_name, self.encoding)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         packet.write_buffer(buf)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 765, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":766
+ *         buf.write_str(stmt_name, self.encoding)
+ *         buf.end_message()
+ *         packet.write_buffer(buf)             # <<<<<<<<<<<<<<
+ * 
+ *         packet.write_bytes(SYNC_MESSAGE)
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_packet->__pyx_vtab)->write_buffer(__pyx_v_packet, __pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 766, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":768
+ *         packet.write_buffer(buf)
+ * 
+ *         packet.write_bytes(SYNC_MESSAGE)             # <<<<<<<<<<<<<<
+ * 
+ *         self._write(packet)
+ */
+  __pyx_t_2 = __pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_packet->__pyx_vtab)->write_bytes(__pyx_v_packet, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 768, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":770
+ *         packet.write_bytes(SYNC_MESSAGE)
+ * 
+ *         self._write(packet)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _send_bind_message(self, str portal_name, str stmt_name,
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_packet)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 770, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":747
+ *         self._write(outbuf)
+ * 
+ *     cdef _prepare(self, str stmt_name, str query):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             WriteBuffer packet
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_packet);
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":772
+ *         self._write(packet)
+ * 
+ *     cdef _send_bind_message(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                             WriteBuffer bind_data, int32_t limit):
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__send_bind_message(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data, int32_t __pyx_v_limit) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_packet = 0;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_send_bind_message", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":779
+ *             WriteBuffer buf
+ * 
+ *         buf = self._build_bind_message(portal_name, stmt_name, bind_data)             # <<<<<<<<<<<<<<
+ *         packet = buf
+ * 
+ */
+  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_build_bind_message(__pyx_v_self, __pyx_v_portal_name, __pyx_v_stmt_name, __pyx_v_bind_data)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 779, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":780
+ * 
+ *         buf = self._build_bind_message(portal_name, stmt_name, bind_data)
+ *         packet = buf             # <<<<<<<<<<<<<<
+ * 
+ *         buf = WriteBuffer.new_message(b'E')
+ */
+  __Pyx_INCREF(((PyObject *)__pyx_v_buf));
+  __pyx_v_packet = __pyx_v_buf;
+
+  /* "asyncpg/protocol/coreproto.pyx":782
+ *         packet = buf
+ * 
+ *         buf = WriteBuffer.new_message(b'E')             # <<<<<<<<<<<<<<
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('E')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 782, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF_SET(__pyx_v_buf, ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1));
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":783
+ * 
+ *         buf = WriteBuffer.new_message(b'E')
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal             # <<<<<<<<<<<<<<
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ *         buf.end_message()
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_portal_name, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 783, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":784
+ *         buf = WriteBuffer.new_message(b'E')
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         packet.write_buffer(buf)
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_v_limit); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 784, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":785
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         packet.write_buffer(buf)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 785, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":786
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ *         buf.end_message()
+ *         packet.write_buffer(buf)             # <<<<<<<<<<<<<<
+ * 
+ *         packet.write_bytes(SYNC_MESSAGE)
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_packet->__pyx_vtab)->write_buffer(__pyx_v_packet, __pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 786, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":788
+ *         packet.write_buffer(buf)
+ * 
+ *         packet.write_bytes(SYNC_MESSAGE)             # <<<<<<<<<<<<<<
+ * 
+ *         self._write(packet)
+ */
+  __pyx_t_2 = __pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_packet->__pyx_vtab)->write_bytes(__pyx_v_packet, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 788, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":790
+ *         packet.write_bytes(SYNC_MESSAGE)
+ * 
+ *         self._write(packet)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _bind_execute(self, str portal_name, str stmt_name,
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_packet)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 790, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":772
+ *         self._write(packet)
+ * 
+ *     cdef _send_bind_message(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                             WriteBuffer bind_data, int32_t limit):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._send_bind_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_packet);
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":792
+ *         self._write(packet)
+ * 
+ *     cdef _bind_execute(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                        WriteBuffer bind_data, int32_t limit):
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind_execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data, int32_t __pyx_v_limit) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_bind_execute", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":797
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_BIND_EXECUTE)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 797, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":798
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_BIND_EXECUTE)             # <<<<<<<<<<<<<<
+ * 
+ *         self.result = []
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 798, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":800
+ *         self._set_state(PROTOCOL_BIND_EXECUTE)
+ * 
+ *         self.result = []             # <<<<<<<<<<<<<<
+ * 
+ *         self._send_bind_message(portal_name, stmt_name, bind_data, limit)
+ */
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 800, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->result);
+  __Pyx_DECREF(__pyx_v_self->result);
+  __pyx_v_self->result = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":802
+ *         self.result = []
+ * 
+ *         self._send_bind_message(portal_name, stmt_name, bind_data, limit)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _bind_execute_many(self, str portal_name, str stmt_name,
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_send_bind_message(__pyx_v_self, __pyx_v_portal_name, __pyx_v_stmt_name, __pyx_v_bind_data, __pyx_v_limit); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 802, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":792
+ *         self._write(packet)
+ * 
+ *     cdef _bind_execute(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                        WriteBuffer bind_data, int32_t limit):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._bind_execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":804
+ *         self._send_bind_message(portal_name, stmt_name, bind_data, limit)
+ * 
+ *     cdef _bind_execute_many(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                             object bind_data):
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind_execute_many(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, PyObject *__pyx_v_bind_data) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  char const *__pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  __Pyx_RefNannySetupContext("_bind_execute_many", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":809
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_BIND_EXECUTE_MANY)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 809, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":810
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_BIND_EXECUTE_MANY)             # <<<<<<<<<<<<<<
+ * 
+ *         self.result = None
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE_MANY); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 810, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":812
+ *         self._set_state(PROTOCOL_BIND_EXECUTE_MANY)
+ * 
+ *         self.result = None             # <<<<<<<<<<<<<<
+ *         self._discard_data = True
+ *         self._execute_iter = bind_data
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->result);
+  __Pyx_DECREF(__pyx_v_self->result);
+  __pyx_v_self->result = Py_None;
+
+  /* "asyncpg/protocol/coreproto.pyx":813
+ * 
+ *         self.result = None
+ *         self._discard_data = True             # <<<<<<<<<<<<<<
+ *         self._execute_iter = bind_data
+ *         self._execute_portal_name = portal_name
+ */
+  __pyx_v_self->_discard_data = 1;
+
+  /* "asyncpg/protocol/coreproto.pyx":814
+ *         self.result = None
+ *         self._discard_data = True
+ *         self._execute_iter = bind_data             # <<<<<<<<<<<<<<
+ *         self._execute_portal_name = portal_name
+ *         self._execute_stmt_name = stmt_name
+ */
+  __Pyx_INCREF(__pyx_v_bind_data);
+  __Pyx_GIVEREF(__pyx_v_bind_data);
+  __Pyx_GOTREF(__pyx_v_self->_execute_iter);
+  __Pyx_DECREF(__pyx_v_self->_execute_iter);
+  __pyx_v_self->_execute_iter = __pyx_v_bind_data;
+
+  /* "asyncpg/protocol/coreproto.pyx":815
+ *         self._discard_data = True
+ *         self._execute_iter = bind_data
+ *         self._execute_portal_name = portal_name             # <<<<<<<<<<<<<<
+ *         self._execute_stmt_name = stmt_name
+ * 
+ */
+  __Pyx_INCREF(__pyx_v_portal_name);
+  __Pyx_GIVEREF(__pyx_v_portal_name);
+  __Pyx_GOTREF(__pyx_v_self->_execute_portal_name);
+  __Pyx_DECREF(__pyx_v_self->_execute_portal_name);
+  __pyx_v_self->_execute_portal_name = __pyx_v_portal_name;
+
+  /* "asyncpg/protocol/coreproto.pyx":816
+ *         self._execute_iter = bind_data
+ *         self._execute_portal_name = portal_name
+ *         self._execute_stmt_name = stmt_name             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+  __Pyx_INCREF(__pyx_v_stmt_name);
+  __Pyx_GIVEREF(__pyx_v_stmt_name);
+  __Pyx_GOTREF(__pyx_v_self->_execute_stmt_name);
+  __Pyx_DECREF(__pyx_v_self->_execute_stmt_name);
+  __pyx_v_self->_execute_stmt_name = __pyx_v_stmt_name;
+
+  /* "asyncpg/protocol/coreproto.pyx":818
+ *         self._execute_stmt_name = stmt_name
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             buf = <WriteBuffer>next(bind_data)
+ *         except StopIteration:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
+    __Pyx_XGOTREF(__pyx_t_2);
+    __Pyx_XGOTREF(__pyx_t_3);
+    __Pyx_XGOTREF(__pyx_t_4);
+    /*try:*/ {
+
+      /* "asyncpg/protocol/coreproto.pyx":819
+ * 
+ *         try:
+ *             buf = <WriteBuffer>next(bind_data)             # <<<<<<<<<<<<<<
+ *         except StopIteration:
+ *             self._push_result()
+ */
+      __pyx_t_1 = __Pyx_PyIter_Next(__pyx_v_bind_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 819, __pyx_L3_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_5 = __pyx_t_1;
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_5);
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/coreproto.pyx":818
+ *         self._execute_stmt_name = stmt_name
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             buf = <WriteBuffer>next(bind_data)
+ *         except StopIteration:
+ */
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":827
+ *             self._push_result()
+ *         else:
+ *             self._send_bind_message(portal_name, stmt_name, buf, 0)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _execute(self, str portal_name, int32_t limit):
+ */
+    /*else:*/ {
+      __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_send_bind_message(__pyx_v_self, __pyx_v_portal_name, __pyx_v_stmt_name, __pyx_v_buf, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(5, 827, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    }
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":820
+ *         try:
+ *             buf = <WriteBuffer>next(bind_data)
+ *         except StopIteration:             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ *         except Exception as e:
+ */
+    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_StopIteration);
+    if (__pyx_t_6) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_1, &__pyx_t_7) < 0) __PYX_ERR(5, 820, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_GOTREF(__pyx_t_7);
+
+      /* "asyncpg/protocol/coreproto.pyx":821
+ *             buf = <WriteBuffer>next(bind_data)
+ *         except StopIteration:
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ *         except Exception as e:
+ *             self.result_type = RESULT_FAILED
+ */
+      __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 821, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+
+    /* "asyncpg/protocol/coreproto.pyx":822
+ *         except StopIteration:
+ *             self._push_result()
+ *         except Exception as e:             # <<<<<<<<<<<<<<
+ *             self.result_type = RESULT_FAILED
+ *             self.result = e
+ */
+    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+    if (__pyx_t_6) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_1, &__pyx_t_5) < 0) __PYX_ERR(5, 822, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_1);
+      __pyx_v_e = __pyx_t_1;
+      /*try:*/ {
+
+        /* "asyncpg/protocol/coreproto.pyx":823
+ *             self._push_result()
+ *         except Exception as e:
+ *             self.result_type = RESULT_FAILED             # <<<<<<<<<<<<<<
+ *             self.result = e
+ *             self._push_result()
+ */
+        __pyx_v_self->result_type = __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED;
+
+        /* "asyncpg/protocol/coreproto.pyx":824
+ *         except Exception as e:
+ *             self.result_type = RESULT_FAILED
+ *             self.result = e             # <<<<<<<<<<<<<<
+ *             self._push_result()
+ *         else:
+ */
+        __Pyx_INCREF(__pyx_v_e);
+        __Pyx_GIVEREF(__pyx_v_e);
+        __Pyx_GOTREF(__pyx_v_self->result);
+        __Pyx_DECREF(__pyx_v_self->result);
+        __pyx_v_self->result = __pyx_v_e;
+
+        /* "asyncpg/protocol/coreproto.pyx":825
+ *             self.result_type = RESULT_FAILED
+ *             self.result = e
+ *             self._push_result()             # <<<<<<<<<<<<<<
+ *         else:
+ *             self._send_bind_message(portal_name, stmt_name, buf, 0)
+ */
+        __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_push_result(__pyx_v_self); if (unlikely(!__pyx_t_8)) __PYX_ERR(5, 825, __pyx_L16_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      }
+
+      /* "asyncpg/protocol/coreproto.pyx":822
+ *         except StopIteration:
+ *             self._push_result()
+ *         except Exception as e:             # <<<<<<<<<<<<<<
+ *             self.result_type = RESULT_FAILED
+ *             self.result = e
+ */
+      /*finally:*/ {
+        /*normal exit:*/{
+          __Pyx_DECREF(__pyx_v_e);
+          __pyx_v_e = NULL;
+          goto __pyx_L17;
+        }
+        __pyx_L16_error:;
+        /*exception exit:*/{
+          __Pyx_PyThreadState_declare
+          __Pyx_PyThreadState_assign
+          __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0;
+          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+          if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);
+          if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13) < 0)) __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
+          __Pyx_XGOTREF(__pyx_t_11);
+          __Pyx_XGOTREF(__pyx_t_12);
+          __Pyx_XGOTREF(__pyx_t_13);
+          __Pyx_XGOTREF(__pyx_t_14);
+          __Pyx_XGOTREF(__pyx_t_15);
+          __Pyx_XGOTREF(__pyx_t_16);
+          __pyx_t_6 = __pyx_lineno; __pyx_t_9 = __pyx_clineno; __pyx_t_10 = __pyx_filename;
+          {
+            __Pyx_DECREF(__pyx_v_e);
+            __pyx_v_e = NULL;
+          }
+          if (PY_MAJOR_VERSION >= 3) {
+            __Pyx_XGIVEREF(__pyx_t_14);
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
+          }
+          __Pyx_XGIVEREF(__pyx_t_11);
+          __Pyx_XGIVEREF(__pyx_t_12);
+          __Pyx_XGIVEREF(__pyx_t_13);
+          __Pyx_ErrRestore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
+          __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0;
+          __pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_9; __pyx_filename = __pyx_t_10;
+          goto __pyx_L5_except_error;
+        }
+        __pyx_L17:;
+      }
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/protocol/coreproto.pyx":818
+ *         self._execute_stmt_name = stmt_name
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             buf = <WriteBuffer>next(bind_data)
+ *         except StopIteration:
+ */
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_XGIVEREF(__pyx_t_4);
+    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __Pyx_XGIVEREF(__pyx_t_3);
+    __Pyx_XGIVEREF(__pyx_t_4);
+    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":804
+ *         self._send_bind_message(portal_name, stmt_name, bind_data, limit)
+ * 
+ *     cdef _bind_execute_many(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                             object bind_data):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":829
+ *             self._send_bind_message(portal_name, stmt_name, buf, 0)
+ * 
+ *     cdef _execute(self, str portal_name, int32_t limit):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, int32_t __pyx_v_limit) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_execute", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":832
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_EXECUTE)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 832, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":833
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_EXECUTE)             # <<<<<<<<<<<<<<
+ * 
+ *         self.result = []
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_EXECUTE); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 833, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":835
+ *         self._set_state(PROTOCOL_EXECUTE)
+ * 
+ *         self.result = []             # <<<<<<<<<<<<<<
+ * 
+ *         buf = WriteBuffer.new_message(b'E')
+ */
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 835, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->result);
+  __Pyx_DECREF(__pyx_v_self->result);
+  __pyx_v_self->result = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":837
+ *         self.result = []
+ * 
+ *         buf = WriteBuffer.new_message(b'E')             # <<<<<<<<<<<<<<
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('E')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 837, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":838
+ * 
+ *         buf = WriteBuffer.new_message(b'E')
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal             # <<<<<<<<<<<<<<
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ *         buf.end_message()
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_portal_name, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 838, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":839
+ *         buf = WriteBuffer.new_message(b'E')
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_int32(__pyx_v_buf, __pyx_v_limit); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 839, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":840
+ *         buf.write_str(portal_name, self.encoding)  # name of the portal
+ *         buf.write_int32(limit)  # number of rows to return; 0 - all
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_bytes(SYNC_MESSAGE)
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 840, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":842
+ *         buf.end_message()
+ * 
+ *         buf.write_bytes(SYNC_MESSAGE)             # <<<<<<<<<<<<<<
+ * 
+ *         self._write(buf)
+ */
+  __pyx_t_2 = __pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE;
+  __Pyx_INCREF(__pyx_t_2);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_bytes(__pyx_v_buf, ((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 842, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":844
+ *         buf.write_bytes(SYNC_MESSAGE)
+ * 
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _bind(self, str portal_name, str stmt_name,
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 844, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":829
+ *             self._send_bind_message(portal_name, stmt_name, buf, 0)
+ * 
+ *     cdef _execute(self, str portal_name, int32_t limit):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":846
+ *         self._write(buf)
+ * 
+ *     cdef _bind(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                WriteBuffer bind_data):
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_stmt_name, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_bind_data) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_bind", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":851
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_BIND)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 851, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":852
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_BIND)             # <<<<<<<<<<<<<<
+ * 
+ *         buf = self._build_bind_message(portal_name, stmt_name, bind_data)
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 852, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":854
+ *         self._set_state(PROTOCOL_BIND)
+ * 
+ *         buf = self._build_bind_message(portal_name, stmt_name, bind_data)             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_bytes(SYNC_MESSAGE)
+ */
+  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_build_bind_message(__pyx_v_self, __pyx_v_portal_name, __pyx_v_stmt_name, __pyx_v_bind_data)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 854, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":856
+ *         buf = self._build_bind_message(portal_name, stmt_name, bind_data)
+ * 
+ *         buf.write_bytes(SYNC_MESSAGE)             # <<<<<<<<<<<<<<
+ * 
+ *         self._write(buf)
+ */
+  __pyx_t_1 = __pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_bytes(__pyx_v_buf, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 856, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":858
+ *         buf.write_bytes(SYNC_MESSAGE)
+ * 
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _close(self, str name, bint is_portal):
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 858, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":846
+ *         self._write(buf)
+ * 
+ *     cdef _bind(self, str portal_name, str stmt_name,             # <<<<<<<<<<<<<<
+ *                WriteBuffer bind_data):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":860
+ *         self._write(buf)
+ * 
+ *     cdef _close(self, str name, bint is_portal):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__close(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_name, int __pyx_v_is_portal) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_close", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":863
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_CLOSE_STMT_PORTAL)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 863, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":864
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_CLOSE_STMT_PORTAL)             # <<<<<<<<<<<<<<
+ * 
+ *         buf = WriteBuffer.new_message(b'C')
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CLOSE_STMT_PORTAL); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 864, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":866
+ *         self._set_state(PROTOCOL_CLOSE_STMT_PORTAL)
+ * 
+ *         buf = WriteBuffer.new_message(b'C')             # <<<<<<<<<<<<<<
+ * 
+ *         if is_portal:
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('C')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 866, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":868
+ *         buf = WriteBuffer.new_message(b'C')
+ * 
+ *         if is_portal:             # <<<<<<<<<<<<<<
+ *             buf.write_byte(b'P')
+ *         else:
+ */
+  __pyx_t_2 = (__pyx_v_is_portal != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/coreproto.pyx":869
+ * 
+ *         if is_portal:
+ *             buf.write_byte(b'P')             # <<<<<<<<<<<<<<
+ *         else:
+ *             buf.write_byte(b'S')
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_byte(__pyx_v_buf, 'P'); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 869, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/coreproto.pyx":868
+ *         buf = WriteBuffer.new_message(b'C')
+ * 
+ *         if is_portal:             # <<<<<<<<<<<<<<
+ *             buf.write_byte(b'P')
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/coreproto.pyx":871
+ *             buf.write_byte(b'P')
+ *         else:
+ *             buf.write_byte(b'S')             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_str(name, self.encoding)
+ */
+  /*else*/ {
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_byte(__pyx_v_buf, 'S'); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 871, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/coreproto.pyx":873
+ *             buf.write_byte(b'S')
+ * 
+ *         buf.write_str(name, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ * 
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_name, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 873, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":874
+ * 
+ *         buf.write_str(name, self.encoding)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ * 
+ *         buf.write_bytes(SYNC_MESSAGE)
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_3)) __PYX_ERR(5, 874, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":876
+ *         buf.end_message()
+ * 
+ *         buf.write_bytes(SYNC_MESSAGE)             # <<<<<<<<<<<<<<
+ * 
+ *         self._write(buf)
+ */
+  __pyx_t_3 = __pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE;
+  __Pyx_INCREF(__pyx_t_3);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_bytes(__pyx_v_buf, ((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 876, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":878
+ *         buf.write_bytes(SYNC_MESSAGE)
+ * 
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _simple_query(self, str query):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 878, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":860
+ *         self._write(buf)
+ * 
+ *     cdef _close(self, str name, bint is_portal):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._close", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":880
+ *         self._write(buf)
+ * 
+ *     cdef _simple_query(self, str query):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__simple_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_query) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_simple_query", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":882
+ *     cdef _simple_query(self, str query):
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_SIMPLE_QUERY)
+ *         buf = WriteBuffer.new_message(b'Q')
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 882, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":883
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_SIMPLE_QUERY)             # <<<<<<<<<<<<<<
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(query, self.encoding)
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_SIMPLE_QUERY); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 883, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":884
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_SIMPLE_QUERY)
+ *         buf = WriteBuffer.new_message(b'Q')             # <<<<<<<<<<<<<<
+ *         buf.write_str(query, self.encoding)
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('Q')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 884, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":885
+ *         self._set_state(PROTOCOL_SIMPLE_QUERY)
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(query, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         self._write(buf)
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_query, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 885, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":886
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(query, self.encoding)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         self._write(buf)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 886, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":887
+ *         buf.write_str(query, self.encoding)
+ *         buf.end_message()
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _copy_out(self, str copy_stmt):
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 887, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":880
+ *         self._write(buf)
+ * 
+ *     cdef _simple_query(self, str query):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._simple_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":889
+ *         self._write(buf)
+ * 
+ *     cdef _copy_out(self, str copy_stmt):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_copy_out", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":892
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_COPY_OUT)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 892, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":893
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_COPY_OUT)             # <<<<<<<<<<<<<<
+ * 
+ *         # Send the COPY .. TO STDOUT using the SimpleQuery protocol.
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 893, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":896
+ * 
+ *         # Send the COPY .. TO STDOUT using the SimpleQuery protocol.
+ *         buf = WriteBuffer.new_message(b'Q')             # <<<<<<<<<<<<<<
+ *         buf.write_str(copy_stmt, self.encoding)
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('Q')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 896, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":897
+ *         # Send the COPY .. TO STDOUT using the SimpleQuery protocol.
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(copy_stmt, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         self._write(buf)
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_copy_stmt, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 897, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":898
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(copy_stmt, self.encoding)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         self._write(buf)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 898, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":899
+ *         buf.write_str(copy_stmt, self.encoding)
+ *         buf.end_message()
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _copy_in(self, str copy_stmt):
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 899, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":889
+ *         self._write(buf)
+ * 
+ *     cdef _copy_out(self, str copy_stmt):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":901
+ *         self._write(buf)
+ * 
+ *     cdef _copy_in(self, str copy_stmt):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("_copy_in", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":904
+ *         cdef WriteBuffer buf
+ * 
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_COPY_IN)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 904, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":905
+ * 
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_COPY_IN)             # <<<<<<<<<<<<<<
+ * 
+ *         buf = WriteBuffer.new_message(b'Q')
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 905, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":907
+ *         self._set_state(PROTOCOL_COPY_IN)
+ * 
+ *         buf = WriteBuffer.new_message(b'Q')             # <<<<<<<<<<<<<<
+ *         buf.write_str(copy_stmt, self.encoding)
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('Q')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 907, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":908
+ * 
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(copy_stmt, self.encoding)             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         self._write(buf)
+ */
+  __pyx_t_1 = __pyx_v_self->encoding;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->write_str(__pyx_v_buf, __pyx_v_copy_stmt, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 908, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":909
+ *         buf = WriteBuffer.new_message(b'Q')
+ *         buf.write_str(copy_stmt, self.encoding)
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         self._write(buf)
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 909, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":910
+ *         buf.write_str(copy_stmt, self.encoding)
+ *         buf.end_message()
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _terminate(self):
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 910, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":901
+ *         self._write(buf)
+ * 
+ *     cdef _copy_in(self, str copy_stmt):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":912
+ *         self._write(buf)
+ * 
+ *     cdef _terminate(self):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__terminate(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_buf = 0;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_terminate", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":914
+ *     cdef _terminate(self):
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_TERMINATING)
+ *         buf = WriteBuffer.new_message(b'X')
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_ensure_connected(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 914, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":915
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_TERMINATING)             # <<<<<<<<<<<<<<
+ *         buf = WriteBuffer.new_message(b'X')
+ *         buf.end_message()
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_set_state(__pyx_v_self, __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_TERMINATING); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 915, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":916
+ *         self._ensure_connected()
+ *         self._set_state(PROTOCOL_TERMINATING)
+ *         buf = WriteBuffer.new_message(b'X')             # <<<<<<<<<<<<<<
+ *         buf.end_message()
+ *         self._write(buf)
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('X')); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 916, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_buf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":917
+ *         self._set_state(PROTOCOL_TERMINATING)
+ *         buf = WriteBuffer.new_message(b'X')
+ *         buf.end_message()             # <<<<<<<<<<<<<<
+ *         self._write(buf)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_buf->__pyx_vtab)->end_message(__pyx_v_buf); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 917, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":918
+ *         buf = WriteBuffer.new_message(b'X')
+ *         buf.end_message()
+ *         self._write(buf)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _write(self, buf):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self->__pyx_vtab)->_write(__pyx_v_self, ((PyObject *)__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 918, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":912
+ *         self._write(buf)
+ * 
+ *     cdef _terminate(self):             # <<<<<<<<<<<<<<
+ *         cdef WriteBuffer buf
+ *         self._ensure_connected()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._terminate", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_buf);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":920
+ *         self._write(buf)
+ * 
+ *     cdef _write(self, buf):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_write", 0);
+
+  /* "asyncpg/protocol/coreproto.pyx":921
+ * 
+ *     cdef _write(self, buf):
+ *         raise NotImplementedError             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):
+ */
+  __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
+  __PYX_ERR(5, 921, __pyx_L1_error)
+
+  /* "asyncpg/protocol/coreproto.pyx":920
+ *         self._write(buf)
+ * 
+ *     cdef _write(self, buf):             # <<<<<<<<<<<<<<
+ *         raise NotImplementedError
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol._write", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":923
+ *         raise NotImplementedError
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):             # <<<<<<<<<<<<<<
+ *         pass
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__decode_row(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED char const *__pyx_v_buf, CYTHON_UNUSED Py_ssize_t __pyx_v_buf_len) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_decode_row", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":926
+ *         pass
+ * 
+ *     cdef _set_server_parameter(self, name, val):             # <<<<<<<<<<<<<<
+ *         pass
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__set_server_parameter(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_name, CYTHON_UNUSED PyObject *__pyx_v_val) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_set_server_parameter", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":929
+ *         pass
+ * 
+ *     cdef _on_result(self):             # <<<<<<<<<<<<<<
+ *         pass
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_result(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_on_result", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":932
+ *         pass
+ * 
+ *     cdef _on_notice(self, parsed):             # <<<<<<<<<<<<<<
+ *         pass
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_notice(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_parsed) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_on_notice", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":935
+ *         pass
+ * 
+ *     cdef _on_notification(self, pid, channel, payload):             # <<<<<<<<<<<<<<
+ *         pass
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_notification(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_pid, CYTHON_UNUSED PyObject *__pyx_v_channel, CYTHON_UNUSED PyObject *__pyx_v_payload) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_on_notification", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pyx":938
+ *         pass
+ * 
+ *     cdef _on_connection_lost(self, exc):             # <<<<<<<<<<<<<<
+ *         pass
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_connection_lost(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_on_connection_lost", 0);
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pxd":95
+ *         object con_params
+ * 
+ *         readonly int32_t backend_pid             # <<<<<<<<<<<<<<
+ *         readonly int32_t backend_secret
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_11backend_pid_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_11backend_pid_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_11backend_pid___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_11backend_pid___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->backend_pid); if (unlikely(!__pyx_t_1)) __PYX_ERR(11, 95, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol.backend_pid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/coreproto.pxd":96
+ * 
+ *         readonly int32_t backend_pid
+ *         readonly int32_t backend_secret             # <<<<<<<<<<<<<<
+ * 
+ *         ## Result
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_14backend_secret_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_14backend_secret_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_14backend_secret___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_14backend_secret___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->backend_secret); if (unlikely(!__pyx_t_1)) __PYX_ERR(11, 96, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol.backend_secret.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.backend_pid, self.backend_secret, self.buffer, self.con_params, self.con_status, self.encoding, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.state, self.transport, self.xact_status)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_2__reduce_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_2__reduce_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self) {
+  int __pyx_v_use_setstate;
+  PyObject *__pyx_v_state = NULL;
+  PyObject *__pyx_v__dict = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  int __pyx_t_11;
+  int __pyx_t_12;
+  int __pyx_t_13;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.backend_pid, self.backend_secret, self.buffer, self.con_params, self.con_status, self.encoding, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.state, self.transport, self.xact_status)             # <<<<<<<<<<<<<<
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ */
+  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->_discard_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->_skip_discard); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_self->backend_pid); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->backend_secret); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(__pyx_v_self->con_status); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = __Pyx_PyBool_FromLong(__pyx_v_self->result_execute_completed); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(__pyx_v_self->result_type); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __pyx_t_8 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_self->state); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __pyx_t_9 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(__pyx_v_self->xact_status); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+  __pyx_t_10 = PyTuple_New(20); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_10);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1);
+  __Pyx_INCREF(__pyx_v_self->_execute_iter);
+  __Pyx_GIVEREF(__pyx_v_self->_execute_iter);
+  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_self->_execute_iter);
+  __Pyx_INCREF(__pyx_v_self->_execute_portal_name);
+  __Pyx_GIVEREF(__pyx_v_self->_execute_portal_name);
+  PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_self->_execute_portal_name);
+  __Pyx_INCREF(__pyx_v_self->_execute_stmt_name);
+  __Pyx_GIVEREF(__pyx_v_self->_execute_stmt_name);
+  PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_v_self->_execute_stmt_name);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_4);
+  PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_4);
+  __Pyx_INCREF(((PyObject *)__pyx_v_self->buffer));
+  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->buffer));
+  PyTuple_SET_ITEM(__pyx_t_10, 7, ((PyObject *)__pyx_v_self->buffer));
+  __Pyx_INCREF(__pyx_v_self->con_params);
+  __Pyx_GIVEREF(__pyx_v_self->con_params);
+  PyTuple_SET_ITEM(__pyx_t_10, 8, __pyx_v_self->con_params);
+  __Pyx_GIVEREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_10, 9, __pyx_t_5);
+  __Pyx_INCREF(__pyx_v_self->encoding);
+  __Pyx_GIVEREF(__pyx_v_self->encoding);
+  PyTuple_SET_ITEM(__pyx_t_10, 10, __pyx_v_self->encoding);
+  __Pyx_INCREF(__pyx_v_self->result);
+  __Pyx_GIVEREF(__pyx_v_self->result);
+  PyTuple_SET_ITEM(__pyx_t_10, 11, __pyx_v_self->result);
+  __Pyx_GIVEREF(__pyx_t_6);
+  PyTuple_SET_ITEM(__pyx_t_10, 12, __pyx_t_6);
+  __Pyx_INCREF(__pyx_v_self->result_param_desc);
+  __Pyx_GIVEREF(__pyx_v_self->result_param_desc);
+  PyTuple_SET_ITEM(__pyx_t_10, 13, __pyx_v_self->result_param_desc);
+  __Pyx_INCREF(__pyx_v_self->result_row_desc);
+  __Pyx_GIVEREF(__pyx_v_self->result_row_desc);
+  PyTuple_SET_ITEM(__pyx_t_10, 14, __pyx_v_self->result_row_desc);
+  __Pyx_INCREF(__pyx_v_self->result_status_msg);
+  __Pyx_GIVEREF(__pyx_v_self->result_status_msg);
+  PyTuple_SET_ITEM(__pyx_t_10, 15, __pyx_v_self->result_status_msg);
+  __Pyx_GIVEREF(__pyx_t_7);
+  PyTuple_SET_ITEM(__pyx_t_10, 16, __pyx_t_7);
+  __Pyx_GIVEREF(__pyx_t_8);
+  PyTuple_SET_ITEM(__pyx_t_10, 17, __pyx_t_8);
+  __Pyx_INCREF(__pyx_v_self->transport);
+  __Pyx_GIVEREF(__pyx_v_self->transport);
+  PyTuple_SET_ITEM(__pyx_t_10, 18, __pyx_v_self->transport);
+  __Pyx_GIVEREF(__pyx_t_9);
+  PyTuple_SET_ITEM(__pyx_t_10, 19, __pyx_t_9);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_3 = 0;
+  __pyx_t_4 = 0;
+  __pyx_t_5 = 0;
+  __pyx_t_6 = 0;
+  __pyx_t_7 = 0;
+  __pyx_t_8 = 0;
+  __pyx_t_9 = 0;
+  __pyx_v_state = ((PyObject*)__pyx_t_10);
+  __pyx_t_10 = 0;
+
+  /* "(tree fragment)":4
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.backend_pid, self.backend_secret, self.buffer, self.con_params, self.con_status, self.encoding, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.state, self.transport, self.xact_status)
+ *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
+ *     if _dict is not None:
+ *         state += (_dict,)
+ */
+  __pyx_t_10 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_10);
+  __pyx_v__dict = __pyx_t_10;
+  __pyx_t_10 = 0;
+
+  /* "(tree fragment)":5
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.backend_pid, self.backend_secret, self.buffer, self.con_params, self.con_status, self.encoding, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.state, self.transport, self.xact_status)
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+  __pyx_t_11 = (__pyx_v__dict != Py_None);
+  __pyx_t_12 = (__pyx_t_11 != 0);
+  if (__pyx_t_12) {
+
+    /* "(tree fragment)":6
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ *         state += (_dict,)             # <<<<<<<<<<<<<<
+ *         use_setstate = True
+ *     else:
+ */
+    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    __Pyx_INCREF(__pyx_v__dict);
+    __Pyx_GIVEREF(__pyx_v__dict);
+    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v__dict);
+    __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_9));
+    __pyx_t_9 = 0;
+
+    /* "(tree fragment)":7
+ *     if _dict is not None:
+ *         state += (_dict,)
+ *         use_setstate = True             # <<<<<<<<<<<<<<
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.buffer is not None or self.con_params is not None or self.encoding is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.transport is not None
+ */
+    __pyx_v_use_setstate = 1;
+
+    /* "(tree fragment)":5
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.backend_pid, self.backend_secret, self.buffer, self.con_params, self.con_status, self.encoding, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.state, self.transport, self.xact_status)
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+    goto __pyx_L3;
+  }
+
+  /* "(tree fragment)":9
+ *         use_setstate = True
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.buffer is not None or self.con_params is not None or self.encoding is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.transport is not None             # <<<<<<<<<<<<<<
+ *     if use_setstate:
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, None), state
+ */
+  /*else*/ {
+    __pyx_t_11 = (__pyx_v_self->_execute_iter != Py_None);
+    __pyx_t_13 = (__pyx_t_11 != 0);
+    if (!__pyx_t_13) {
+    } else {
+      __pyx_t_12 = __pyx_t_13;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_13 = (__pyx_v_self->_execute_portal_name != ((PyObject*)Py_None));
+    __pyx_t_11 = (__pyx_t_13 != 0);
+    if (!__pyx_t_11) {
+    } else {
+      __pyx_t_12 = __pyx_t_11;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_11 = (__pyx_v_self->_execute_stmt_name != ((PyObject*)Py_None));
+    __pyx_t_13 = (__pyx_t_11 != 0);
+    if (!__pyx_t_13) {
+    } else {
+      __pyx_t_12 = __pyx_t_13;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_13 = (((PyObject *)__pyx_v_self->buffer) != Py_None);
+    __pyx_t_11 = (__pyx_t_13 != 0);
+    if (!__pyx_t_11) {
+    } else {
+      __pyx_t_12 = __pyx_t_11;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_11 = (__pyx_v_self->con_params != Py_None);
+    __pyx_t_13 = (__pyx_t_11 != 0);
+    if (!__pyx_t_13) {
+    } else {
+      __pyx_t_12 = __pyx_t_13;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_13 = (__pyx_v_self->encoding != ((PyObject*)Py_None));
+    __pyx_t_11 = (__pyx_t_13 != 0);
+    if (!__pyx_t_11) {
+    } else {
+      __pyx_t_12 = __pyx_t_11;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_11 = (__pyx_v_self->result != Py_None);
+    __pyx_t_13 = (__pyx_t_11 != 0);
+    if (!__pyx_t_13) {
+    } else {
+      __pyx_t_12 = __pyx_t_13;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_13 = (__pyx_v_self->result_param_desc != ((PyObject*)Py_None));
+    __pyx_t_11 = (__pyx_t_13 != 0);
+    if (!__pyx_t_11) {
+    } else {
+      __pyx_t_12 = __pyx_t_11;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_11 = (__pyx_v_self->result_row_desc != ((PyObject*)Py_None));
+    __pyx_t_13 = (__pyx_t_11 != 0);
+    if (!__pyx_t_13) {
+    } else {
+      __pyx_t_12 = __pyx_t_13;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_13 = (__pyx_v_self->result_status_msg != ((PyObject*)Py_None));
+    __pyx_t_11 = (__pyx_t_13 != 0);
+    if (!__pyx_t_11) {
+    } else {
+      __pyx_t_12 = __pyx_t_11;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_11 = (__pyx_v_self->transport != Py_None);
+    __pyx_t_13 = (__pyx_t_11 != 0);
+    __pyx_t_12 = __pyx_t_13;
+    __pyx_L4_bool_binop_done:;
+    __pyx_v_use_setstate = __pyx_t_12;
+  }
+  __pyx_L3:;
+
+  /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.buffer is not None or self.con_params is not None or self.encoding is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.transport is not None
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, None), state
+ *     else:
+ */
+  __pyx_t_12 = (__pyx_v_use_setstate != 0);
+  if (__pyx_t_12) {
+
+    /* "(tree fragment)":11
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.buffer is not None or self.con_params is not None or self.encoding is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.transport is not None
+ *     if use_setstate:
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, None), state             # <<<<<<<<<<<<<<
+ *     else:
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, state)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pyx_unpickle_CoreProtocol); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_26708044);
+    __Pyx_GIVEREF(__pyx_int_26708044);
+    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_26708044);
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    PyTuple_SET_ITEM(__pyx_t_10, 2, Py_None);
+    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_GIVEREF(__pyx_t_9);
+    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
+    __Pyx_GIVEREF(__pyx_t_10);
+    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_10);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_state);
+    __pyx_t_9 = 0;
+    __pyx_t_10 = 0;
+    __pyx_r = __pyx_t_8;
+    __pyx_t_8 = 0;
+    goto __pyx_L0;
+
+    /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.buffer is not None or self.con_params is not None or self.encoding is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.transport is not None
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, None), state
+ *     else:
+ */
+  }
+
+  /* "(tree fragment)":13
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, None), state
+ *     else:
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, state)             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_CoreProtocol__set_state(self, __pyx_state)
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pyx_unpickle_CoreProtocol); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_26708044);
+    __Pyx_GIVEREF(__pyx_int_26708044);
+    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_26708044);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_state);
+    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    __Pyx_GIVEREF(__pyx_t_8);
+    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
+    __Pyx_GIVEREF(__pyx_t_10);
+    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10);
+    __pyx_t_8 = 0;
+    __pyx_t_10 = 0;
+    __pyx_r = __pyx_t_9;
+    __pyx_t_9 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.backend_pid, self.backend_secret, self.buffer, self.con_params, self.con_status, self.encoding, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.state, self.transport, self.xact_status)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_state);
+  __Pyx_XDECREF(__pyx_v__dict);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_CoreProtocol__set_state(self, __pyx_state)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_4__setstate_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12CoreProtocol_4__setstate_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":15
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, state)
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_CoreProtocol__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
+ */
+  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error)
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_CoreProtocol__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_CoreProtocol, (type(self), 0x197884c, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_CoreProtocol__set_state(self, __pyx_state)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.CoreProtocol.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":14
+ * cdef class PreparedStatementState:
+ * 
+ *     def __cinit__(self, str name, str query, BaseProtocol protocol):             # <<<<<<<<<<<<<<
+ *         self.name = name
+ *         self.query = query
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_name = 0;
+  PyObject *__pyx_v_query = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_protocol = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_query,&__pyx_n_s_protocol,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, 1); __PYX_ERR(6, 14, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_protocol)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, 2); __PYX_ERR(6, 14, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(6, 14, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v_name = ((PyObject*)values[0]);
+    __pyx_v_query = ((PyObject*)values[1]);
+    __pyx_v_protocol = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)values[2]);
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(6, 14, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_name), (&PyUnicode_Type), 1, "name", 1))) __PYX_ERR(6, 14, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyUnicode_Type), 1, "query", 1))) __PYX_ERR(6, 14, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_protocol), __pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol, 1, "protocol", 0))) __PYX_ERR(6, 14, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState___cinit__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self), __pyx_v_name, __pyx_v_query, __pyx_v_protocol);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState___cinit__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_query, struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_protocol) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__cinit__", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":15
+ * 
+ *     def __cinit__(self, str name, str query, BaseProtocol protocol):
+ *         self.name = name             # <<<<<<<<<<<<<<
+ *         self.query = query
+ *         self.settings = protocol.settings
+ */
+  __Pyx_INCREF(__pyx_v_name);
+  __Pyx_GIVEREF(__pyx_v_name);
+  __Pyx_GOTREF(__pyx_v_self->name);
+  __Pyx_DECREF(__pyx_v_self->name);
+  __pyx_v_self->name = __pyx_v_name;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":16
+ *     def __cinit__(self, str name, str query, BaseProtocol protocol):
+ *         self.name = name
+ *         self.query = query             # <<<<<<<<<<<<<<
+ *         self.settings = protocol.settings
+ *         self.row_desc = self.parameters_desc = None
+ */
+  __Pyx_INCREF(__pyx_v_query);
+  __Pyx_GIVEREF(__pyx_v_query);
+  __Pyx_GOTREF(__pyx_v_self->query);
+  __Pyx_DECREF(__pyx_v_self->query);
+  __pyx_v_self->query = __pyx_v_query;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":17
+ *         self.name = name
+ *         self.query = query
+ *         self.settings = protocol.settings             # <<<<<<<<<<<<<<
+ *         self.row_desc = self.parameters_desc = None
+ *         self.args_codecs = self.rows_codecs = None
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_v_protocol->settings);
+  __Pyx_INCREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->settings);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->settings));
+  __pyx_v_self->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":18
+ *         self.query = query
+ *         self.settings = protocol.settings
+ *         self.row_desc = self.parameters_desc = None             # <<<<<<<<<<<<<<
+ *         self.args_codecs = self.rows_codecs = None
+ *         self.args_num = self.cols_num = 0
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->row_desc);
+  __Pyx_DECREF(__pyx_v_self->row_desc);
+  __pyx_v_self->row_desc = ((PyObject*)Py_None);
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->parameters_desc);
+  __Pyx_DECREF(__pyx_v_self->parameters_desc);
+  __pyx_v_self->parameters_desc = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":19
+ *         self.settings = protocol.settings
+ *         self.row_desc = self.parameters_desc = None
+ *         self.args_codecs = self.rows_codecs = None             # <<<<<<<<<<<<<<
+ *         self.args_num = self.cols_num = 0
+ *         self.cols_desc = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->args_codecs);
+  __Pyx_DECREF(__pyx_v_self->args_codecs);
+  __pyx_v_self->args_codecs = ((PyObject*)Py_None);
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->rows_codecs);
+  __Pyx_DECREF(__pyx_v_self->rows_codecs);
+  __pyx_v_self->rows_codecs = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":20
+ *         self.row_desc = self.parameters_desc = None
+ *         self.args_codecs = self.rows_codecs = None
+ *         self.args_num = self.cols_num = 0             # <<<<<<<<<<<<<<
+ *         self.cols_desc = None
+ *         self.closed = False
+ */
+  __pyx_v_self->args_num = 0;
+  __pyx_v_self->cols_num = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":21
+ *         self.args_codecs = self.rows_codecs = None
+ *         self.args_num = self.cols_num = 0
+ *         self.cols_desc = None             # <<<<<<<<<<<<<<
+ *         self.closed = False
+ *         self.refs = 0
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->cols_desc);
+  __Pyx_DECREF(__pyx_v_self->cols_desc);
+  __pyx_v_self->cols_desc = Py_None;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":22
+ *         self.args_num = self.cols_num = 0
+ *         self.cols_desc = None
+ *         self.closed = False             # <<<<<<<<<<<<<<
+ *         self.refs = 0
+ * 
+ */
+  __pyx_v_self->closed = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":23
+ *         self.cols_desc = None
+ *         self.closed = False
+ *         self.refs = 0             # <<<<<<<<<<<<<<
+ * 
+ *     def _get_parameters(self):
+ */
+  __pyx_v_self->refs = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":14
+ * cdef class PreparedStatementState:
+ * 
+ *     def __cinit__(self, str name, str query, BaseProtocol protocol):             # <<<<<<<<<<<<<<
+ *         self.name = name
+ *         self.query = query
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":25
+ *         self.refs = 0
+ * 
+ *     def _get_parameters(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_3_get_parameters(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_3_get_parameters(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_get_parameters (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_2_get_parameters(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_2_get_parameters(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_result = NULL;
+  PyObject *__pyx_v_oid = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  uint32_t __pyx_t_4;
+  int __pyx_t_5;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  int __pyx_t_11;
+  int __pyx_t_12;
+  __Pyx_RefNannySetupContext("_get_parameters", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":28
+ *         cdef Codec codec
+ * 
+ *         result = []             # <<<<<<<<<<<<<<
+ *         for oid in self.parameters_desc:
+ *             codec = self.settings.get_data_codec(oid)
+ */
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 28, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_result = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":29
+ * 
+ *         result = []
+ *         for oid in self.parameters_desc:             # <<<<<<<<<<<<<<
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:
+ */
+  if (unlikely(__pyx_v_self->parameters_desc == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+    __PYX_ERR(6, 29, __pyx_L1_error)
+  }
+  __pyx_t_1 = __pyx_v_self->parameters_desc; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+  for (;;) {
+    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(6, 29, __pyx_L1_error)
+    #else
+    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 29, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_oid, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":30
+ *         result = []
+ *         for oid in self.parameters_desc:
+ *             codec = self.settings.get_data_codec(oid)             # <<<<<<<<<<<<<<
+ *             if codec is None:
+ *                 raise exceptions.InternalClientError(
+ */
+    __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 30, __pyx_L1_error)
+    __pyx_t_3 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_self->settings, __pyx_t_4, 0, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 30, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":31
+ *         for oid in self.parameters_desc:
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))
+ */
+    __pyx_t_5 = (((PyObject *)__pyx_v_codec) == Py_None);
+    __pyx_t_6 = (__pyx_t_5 != 0);
+    if (unlikely(__pyx_t_6)) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":32
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'missing codec information for OID {}'.format(oid))
+ *             result.append(apg_types.Type(
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 32, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 32, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":33
+ *             if codec is None:
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))             # <<<<<<<<<<<<<<
+ *             result.append(apg_types.Type(
+ *                 oid, codec.name, codec.kind, codec.schema))
+ */
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_missing_codec_information_for_OI, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(6, 33, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_10 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_10)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_10);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+        }
+      }
+      __pyx_t_7 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_v_oid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_oid);
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 33, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
+        if (likely(__pyx_t_9)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+          __Pyx_INCREF(__pyx_t_9);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_8, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 32, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(6, 32, __pyx_L1_error)
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":31
+ *         for oid in self.parameters_desc:
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":34
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))
+ *             result.append(apg_types.Type(             # <<<<<<<<<<<<<<
+ *                 oid, codec.name, codec.kind, codec.schema))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_apg_types); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 34, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_Type); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 34, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":35
+ *                     'missing codec information for OID {}'.format(oid))
+ *             result.append(apg_types.Type(
+ *                 oid, codec.name, codec.kind, codec.schema))             # <<<<<<<<<<<<<<
+ * 
+ *         return tuple(result)
+ */
+    __pyx_t_8 = NULL;
+    __pyx_t_11 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+        __pyx_t_11 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_7)) {
+      PyObject *__pyx_temp[5] = {__pyx_t_8, __pyx_v_oid, __pyx_v_codec->name, __pyx_v_codec->kind, __pyx_v_codec->schema};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 34, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
+      PyObject *__pyx_temp[5] = {__pyx_t_8, __pyx_v_oid, __pyx_v_codec->name, __pyx_v_codec->kind, __pyx_v_codec->schema};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 34, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+    } else
+    #endif
+    {
+      __pyx_t_9 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(6, 34, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      if (__pyx_t_8) {
+        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_v_oid);
+      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_11, __pyx_v_oid);
+      __Pyx_INCREF(__pyx_v_codec->name);
+      __Pyx_GIVEREF(__pyx_v_codec->name);
+      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_11, __pyx_v_codec->name);
+      __Pyx_INCREF(__pyx_v_codec->kind);
+      __Pyx_GIVEREF(__pyx_v_codec->kind);
+      PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_11, __pyx_v_codec->kind);
+      __Pyx_INCREF(__pyx_v_codec->schema);
+      __Pyx_GIVEREF(__pyx_v_codec->schema);
+      PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_11, __pyx_v_codec->schema);
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 34, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":34
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))
+ *             result.append(apg_types.Type(             # <<<<<<<<<<<<<<
+ *                 oid, codec.name, codec.kind, codec.schema))
+ * 
+ */
+    __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(6, 34, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":29
+ * 
+ *         result = []
+ *         for oid in self.parameters_desc:             # <<<<<<<<<<<<<<
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:
+ */
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":37
+ *                 oid, codec.name, codec.kind, codec.schema))
+ * 
+ *         return tuple(result)             # <<<<<<<<<<<<<<
+ * 
+ *     def _get_attributes(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 37, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":25
+ *         self.refs = 0
+ * 
+ *     def _get_parameters(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._get_parameters", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF(__pyx_v_oid);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":39
+ *         return tuple(result)
+ * 
+ *     def _get_attributes(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_5_get_attributes(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_5_get_attributes(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_get_attributes (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4_get_attributes(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4_get_attributes(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_result = NULL;
+  PyObject *__pyx_v_d = NULL;
+  PyObject *__pyx_v_name = NULL;
+  PyObject *__pyx_v_oid = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  Py_ssize_t __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  uint32_t __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  int __pyx_t_11;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  __Pyx_RefNannySetupContext("_get_attributes", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":42
+ *         cdef Codec codec
+ * 
+ *         if not self.row_desc:             # <<<<<<<<<<<<<<
+ *             return ()
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_self->row_desc != Py_None)&&(PyList_GET_SIZE(__pyx_v_self->row_desc) != 0);
+  __pyx_t_2 = ((!__pyx_t_1) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":43
+ * 
+ *         if not self.row_desc:
+ *             return ()             # <<<<<<<<<<<<<<
+ * 
+ *         result = []
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(__pyx_empty_tuple);
+    __pyx_r = __pyx_empty_tuple;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":42
+ *         cdef Codec codec
+ * 
+ *         if not self.row_desc:             # <<<<<<<<<<<<<<
+ *             return ()
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":45
+ *             return ()
+ * 
+ *         result = []             # <<<<<<<<<<<<<<
+ *         for d in self.row_desc:
+ *             name = d[0]
+ */
+  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 45, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_v_result = ((PyObject*)__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":46
+ * 
+ *         result = []
+ *         for d in self.row_desc:             # <<<<<<<<<<<<<<
+ *             name = d[0]
+ *             oid = d[3]
+ */
+  if (unlikely(__pyx_v_self->row_desc == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+    __PYX_ERR(6, 46, __pyx_L1_error)
+  }
+  __pyx_t_3 = __pyx_v_self->row_desc; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
+  for (;;) {
+    if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(6, 46, __pyx_L1_error)
+    #else
+    __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 46, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    #endif
+    __Pyx_XDECREF_SET(__pyx_v_d, __pyx_t_5);
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":47
+ *         result = []
+ *         for d in self.row_desc:
+ *             name = d[0]             # <<<<<<<<<<<<<<
+ *             oid = d[3]
+ * 
+ */
+    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_d, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 47, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_5);
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":48
+ *         for d in self.row_desc:
+ *             name = d[0]
+ *             oid = d[3]             # <<<<<<<<<<<<<<
+ * 
+ *             codec = self.settings.get_data_codec(oid)
+ */
+    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_d, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 48, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_XDECREF_SET(__pyx_v_oid, __pyx_t_5);
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":50
+ *             oid = d[3]
+ * 
+ *             codec = self.settings.get_data_codec(oid)             # <<<<<<<<<<<<<<
+ *             if codec is None:
+ *                 raise exceptions.InternalClientError(
+ */
+    __pyx_t_6 = __Pyx_PyInt_As_uint32_t(__pyx_v_oid); if (unlikely((__pyx_t_6 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 50, __pyx_L1_error)
+    __pyx_t_5 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_self->settings, __pyx_t_6, 0, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 50, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_5));
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":51
+ * 
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))
+ */
+    __pyx_t_2 = (((PyObject *)__pyx_v_codec) == Py_None);
+    __pyx_t_1 = (__pyx_t_2 != 0);
+    if (unlikely(__pyx_t_1)) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":52
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'missing codec information for OID {}'.format(oid))
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 52, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 52, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":53
+ *             if codec is None:
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))             # <<<<<<<<<<<<<<
+ * 
+ *             name = name.decode(self.settings._encoding)
+ */
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_missing_codec_information_for_OI, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(6, 53, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_10 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_10)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_10);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+        }
+      }
+      __pyx_t_7 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_v_oid) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_oid);
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 53, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
+        if (likely(__pyx_t_9)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+          __Pyx_INCREF(__pyx_t_9);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_8, function);
+        }
+      }
+      __pyx_t_5 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 52, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __PYX_ERR(6, 52, __pyx_L1_error)
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":51
+ * 
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None:             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'missing codec information for OID {}'.format(oid))
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":55
+ *                     'missing codec information for OID {}'.format(oid))
+ * 
+ *             name = name.decode(self.settings._encoding)             # <<<<<<<<<<<<<<
+ * 
+ *             result.append(
+ */
+    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_name, __pyx_n_s_decode); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 55, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_7 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
+      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
+      if (likely(__pyx_t_7)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_8, function);
+      }
+    }
+    __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_self->settings->_encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_self->settings->_encoding);
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 55, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_DECREF_SET(__pyx_v_name, __pyx_t_5);
+    __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":58
+ * 
+ *             result.append(
+ *                 apg_types.Attribute(name,             # <<<<<<<<<<<<<<
+ *                     apg_types.Type(oid, codec.name, codec.kind, codec.schema)))
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_apg_types); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 58, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_Attribute); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 58, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":59
+ *             result.append(
+ *                 apg_types.Attribute(name,
+ *                     apg_types.Type(oid, codec.name, codec.kind, codec.schema)))             # <<<<<<<<<<<<<<
+ * 
+ *         return tuple(result)
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_apg_types); if (unlikely(!__pyx_t_9)) __PYX_ERR(6, 59, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_Type); if (unlikely(!__pyx_t_10)) __PYX_ERR(6, 59, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+    __pyx_t_9 = NULL;
+    __pyx_t_11 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10);
+      if (likely(__pyx_t_9)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
+        __Pyx_INCREF(__pyx_t_9);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_10, function);
+        __pyx_t_11 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_10)) {
+      PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_v_oid, __pyx_v_codec->name, __pyx_v_codec->kind, __pyx_v_codec->schema};
+      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 59, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_8);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
+      PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_v_oid, __pyx_v_codec->name, __pyx_v_codec->kind, __pyx_v_codec->schema};
+      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 59, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_8);
+    } else
+    #endif
+    {
+      __pyx_t_12 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(6, 59, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_12);
+      if (__pyx_t_9) {
+        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_9); __pyx_t_9 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_oid);
+      __Pyx_GIVEREF(__pyx_v_oid);
+      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_v_oid);
+      __Pyx_INCREF(__pyx_v_codec->name);
+      __Pyx_GIVEREF(__pyx_v_codec->name);
+      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_v_codec->name);
+      __Pyx_INCREF(__pyx_v_codec->kind);
+      __Pyx_GIVEREF(__pyx_v_codec->kind);
+      PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_11, __pyx_v_codec->kind);
+      __Pyx_INCREF(__pyx_v_codec->schema);
+      __Pyx_GIVEREF(__pyx_v_codec->schema);
+      PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_11, __pyx_v_codec->schema);
+      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 59, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __pyx_t_10 = NULL;
+    __pyx_t_11 = 0;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_10)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_10);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+        __pyx_t_11 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_7)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_name, __pyx_t_8};
+      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 58, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_name, __pyx_t_8};
+      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 58, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(6, 58, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_12);
+      if (__pyx_t_10) {
+        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_name);
+      __Pyx_GIVEREF(__pyx_v_name);
+      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_v_name);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_8);
+      __pyx_t_8 = 0;
+      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_12, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 58, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":57
+ *             name = name.decode(self.settings._encoding)
+ * 
+ *             result.append(             # <<<<<<<<<<<<<<
+ *                 apg_types.Attribute(name,
+ *                     apg_types.Type(oid, codec.name, codec.kind, codec.schema)))
+ */
+    __pyx_t_13 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_13 == ((int)-1))) __PYX_ERR(6, 57, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":46
+ * 
+ *         result = []
+ *         for d in self.row_desc:             # <<<<<<<<<<<<<<
+ *             name = d[0]
+ *             oid = d[3]
+ */
+  }
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":61
+ *                     apg_types.Type(oid, codec.name, codec.kind, codec.schema)))
+ * 
+ *         return tuple(result)             # <<<<<<<<<<<<<<
+ * 
+ *     def _init_types(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_3 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 61, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":39
+ *         return tuple(result)
+ * 
+ *     def _get_attributes(self):             # <<<<<<<<<<<<<<
+ *         cdef Codec codec
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._get_attributes", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XDECREF(__pyx_v_d);
+  __Pyx_XDECREF(__pyx_v_name);
+  __Pyx_XDECREF(__pyx_v_oid);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":63
+ *         return tuple(result)
+ * 
+ *     def _init_types(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec codec
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_7_init_types(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_7_init_types(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_init_types (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_6_init_types(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_6_init_types(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_missing = 0;
+  PyObject *__pyx_v_p_oid = NULL;
+  PyObject *__pyx_v_rdesc = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  Py_ssize_t __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  uint32_t __pyx_t_5;
+  int __pyx_t_6;
+  int __pyx_t_7;
+  int __pyx_t_8;
+  __Pyx_RefNannySetupContext("_init_types", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":66
+ *         cdef:
+ *             Codec codec
+ *             set missing = set()             # <<<<<<<<<<<<<<
+ * 
+ *         if self.parameters_desc:
+ */
+  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 66, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_missing = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":68
+ *             set missing = set()
+ * 
+ *         if self.parameters_desc:             # <<<<<<<<<<<<<<
+ *             for p_oid in self.parameters_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ */
+  __pyx_t_2 = (__pyx_v_self->parameters_desc != Py_None)&&(PyList_GET_SIZE(__pyx_v_self->parameters_desc) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":69
+ * 
+ *         if self.parameters_desc:
+ *             for p_oid in self.parameters_desc:             # <<<<<<<<<<<<<<
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ *                 if codec is None or not codec.has_encoder():
+ */
+    if (unlikely(__pyx_v_self->parameters_desc == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+      __PYX_ERR(6, 69, __pyx_L1_error)
+    }
+    __pyx_t_1 = __pyx_v_self->parameters_desc; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
+    for (;;) {
+      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
+      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(6, 69, __pyx_L1_error)
+      #else
+      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 69, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      #endif
+      __Pyx_XDECREF_SET(__pyx_v_p_oid, __pyx_t_4);
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":70
+ *         if self.parameters_desc:
+ *             for p_oid in self.parameters_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)             # <<<<<<<<<<<<<<
+ *                 if codec is None or not codec.has_encoder():
+ *                     missing.add(p_oid)
+ */
+      __pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_v_p_oid); if (unlikely((__pyx_t_5 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 70, __pyx_L1_error)
+      __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_self->settings, ((uint32_t)__pyx_t_5), 0, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 70, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_4));
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":71
+ *             for p_oid in self.parameters_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ *                 if codec is None or not codec.has_encoder():             # <<<<<<<<<<<<<<
+ *                     missing.add(p_oid)
+ * 
+ */
+      __pyx_t_6 = (((PyObject *)__pyx_v_codec) == Py_None);
+      __pyx_t_7 = (__pyx_t_6 != 0);
+      if (!__pyx_t_7) {
+      } else {
+        __pyx_t_2 = __pyx_t_7;
+        goto __pyx_L7_bool_binop_done;
+      }
+      __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(__pyx_v_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 71, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(6, 71, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_6 = ((!__pyx_t_7) != 0);
+      __pyx_t_2 = __pyx_t_6;
+      __pyx_L7_bool_binop_done:;
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":72
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ *                 if codec is None or not codec.has_encoder():
+ *                     missing.add(p_oid)             # <<<<<<<<<<<<<<
+ * 
+ *         if self.row_desc:
+ */
+        __pyx_t_8 = PySet_Add(__pyx_v_missing, __pyx_v_p_oid); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(6, 72, __pyx_L1_error)
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":71
+ *             for p_oid in self.parameters_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ *                 if codec is None or not codec.has_encoder():             # <<<<<<<<<<<<<<
+ *                     missing.add(p_oid)
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":69
+ * 
+ *         if self.parameters_desc:
+ *             for p_oid in self.parameters_desc:             # <<<<<<<<<<<<<<
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ *                 if codec is None or not codec.has_encoder():
+ */
+    }
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":68
+ *             set missing = set()
+ * 
+ *         if self.parameters_desc:             # <<<<<<<<<<<<<<
+ *             for p_oid in self.parameters_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>p_oid)
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":74
+ *                     missing.add(p_oid)
+ * 
+ *         if self.row_desc:             # <<<<<<<<<<<<<<
+ *             for rdesc in self.row_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ */
+  __pyx_t_2 = (__pyx_v_self->row_desc != Py_None)&&(PyList_GET_SIZE(__pyx_v_self->row_desc) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":75
+ * 
+ *         if self.row_desc:
+ *             for rdesc in self.row_desc:             # <<<<<<<<<<<<<<
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ *                 if codec is None or not codec.has_decoder():
+ */
+    if (unlikely(__pyx_v_self->row_desc == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+      __PYX_ERR(6, 75, __pyx_L1_error)
+    }
+    __pyx_t_1 = __pyx_v_self->row_desc; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
+    for (;;) {
+      if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
+      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(6, 75, __pyx_L1_error)
+      #else
+      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 75, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      #endif
+      __Pyx_XDECREF_SET(__pyx_v_rdesc, __pyx_t_4);
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":76
+ *         if self.row_desc:
+ *             for rdesc in self.row_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))             # <<<<<<<<<<<<<<
+ *                 if codec is None or not codec.has_decoder():
+ *                     missing.add(rdesc[3])
+ */
+      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_rdesc, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 76, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_t_4); if (unlikely((__pyx_t_5 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 76, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_self->settings, ((uint32_t)__pyx_t_5), 0, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 76, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_4));
+      __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":77
+ *             for rdesc in self.row_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ *                 if codec is None or not codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                     missing.add(rdesc[3])
+ * 
+ */
+      __pyx_t_6 = (((PyObject *)__pyx_v_codec) == Py_None);
+      __pyx_t_7 = (__pyx_t_6 != 0);
+      if (!__pyx_t_7) {
+      } else {
+        __pyx_t_2 = __pyx_t_7;
+        goto __pyx_L13_bool_binop_done;
+      }
+      __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(__pyx_v_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 77, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(6, 77, __pyx_L1_error)
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_6 = ((!__pyx_t_7) != 0);
+      __pyx_t_2 = __pyx_t_6;
+      __pyx_L13_bool_binop_done:;
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":78
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ *                 if codec is None or not codec.has_decoder():
+ *                     missing.add(rdesc[3])             # <<<<<<<<<<<<<<
+ * 
+ *         return missing
+ */
+        __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_rdesc, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 78, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_8 = PySet_Add(__pyx_v_missing, __pyx_t_4); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(6, 78, __pyx_L1_error)
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":77
+ *             for rdesc in self.row_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ *                 if codec is None or not codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                     missing.add(rdesc[3])
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":75
+ * 
+ *         if self.row_desc:
+ *             for rdesc in self.row_desc:             # <<<<<<<<<<<<<<
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ *                 if codec is None or not codec.has_decoder():
+ */
+    }
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":74
+ *                     missing.add(p_oid)
+ * 
+ *         if self.row_desc:             # <<<<<<<<<<<<<<
+ *             for rdesc in self.row_desc:
+ *                 codec = self.settings.get_data_codec(<uint32_t>(rdesc[3]))
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":80
+ *                     missing.add(rdesc[3])
+ * 
+ *         return missing             # <<<<<<<<<<<<<<
+ * 
+ *     cpdef _init_codecs(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_missing);
+  __pyx_r = __pyx_v_missing;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":63
+ *         return tuple(result)
+ * 
+ *     def _init_types(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec codec
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._init_types", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_missing);
+  __Pyx_XDECREF(__pyx_v_p_oid);
+  __Pyx_XDECREF(__pyx_v_rdesc);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":82
+ *         return missing
+ * 
+ *     cpdef _init_codecs(self):             # <<<<<<<<<<<<<<
+ *         self._ensure_args_encoder()
+ *         self._ensure_rows_decoder()
+ */
+
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_9_init_codecs(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__init_codecs(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, CYTHON_UNUSED int __pyx_skip_dispatch) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_init_codecs", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":83
+ * 
+ *     cpdef _init_codecs(self):
+ *         self._ensure_args_encoder()             # <<<<<<<<<<<<<<
+ *         self._ensure_rows_decoder()
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_args_encoder(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 83, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":84
+ *     cpdef _init_codecs(self):
+ *         self._ensure_args_encoder()
+ *         self._ensure_rows_decoder()             # <<<<<<<<<<<<<<
+ * 
+ *     def attach(self):
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_rows_decoder(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 84, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":82
+ *         return missing
+ * 
+ *     cpdef _init_codecs(self):             # <<<<<<<<<<<<<<
+ *         self._ensure_args_encoder()
+ *         self._ensure_rows_decoder()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._init_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_9_init_codecs(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_9_init_codecs(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_init_codecs (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_8_init_codecs(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_8_init_codecs(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_init_codecs", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__init_codecs(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 82, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._init_codecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":86
+ *         self._ensure_rows_decoder()
+ * 
+ *     def attach(self):             # <<<<<<<<<<<<<<
+ *         self.refs += 1
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_11attach(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_11attach(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("attach (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_10attach(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_10attach(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("attach", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":87
+ * 
+ *     def attach(self):
+ *         self.refs += 1             # <<<<<<<<<<<<<<
+ * 
+ *     def detach(self):
+ */
+  __pyx_v_self->refs = (__pyx_v_self->refs + 1);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":86
+ *         self._ensure_rows_decoder()
+ * 
+ *     def attach(self):             # <<<<<<<<<<<<<<
+ *         self.refs += 1
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":89
+ *         self.refs += 1
+ * 
+ *     def detach(self):             # <<<<<<<<<<<<<<
+ *         self.refs -= 1
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_13detach(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_13detach(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("detach (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_12detach(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_12detach(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("detach", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":90
+ * 
+ *     def detach(self):
+ *         self.refs -= 1             # <<<<<<<<<<<<<<
+ * 
+ *     def mark_closed(self):
+ */
+  __pyx_v_self->refs = (__pyx_v_self->refs - 1);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":89
+ *         self.refs += 1
+ * 
+ *     def detach(self):             # <<<<<<<<<<<<<<
+ *         self.refs -= 1
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":92
+ *         self.refs -= 1
+ * 
+ *     def mark_closed(self):             # <<<<<<<<<<<<<<
+ *         self.closed = True
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_15mark_closed(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_15mark_closed(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("mark_closed (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_14mark_closed(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_14mark_closed(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("mark_closed", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":93
+ * 
+ *     def mark_closed(self):
+ *         self.closed = True             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _encode_bind_msg(self, args):
+ */
+  __pyx_v_self->closed = 1;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":92
+ *         self.refs -= 1
+ * 
+ *     def mark_closed(self):             # <<<<<<<<<<<<<<
+ *         self.closed = True
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":95
+ *         self.closed = True
+ * 
+ *     cdef _encode_bind_msg(self, args):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             int idx
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_args) {
+  int __pyx_v_idx;
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_writer = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  Py_ssize_t __pyx_v_num_args_passed;
+  PyObject *__pyx_v_hint = NULL;
+  PyObject *__pyx_v_arg = NULL;
+  PyObject *__pyx_v_e = NULL;
+  PyObject *__pyx_v_value_repr = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int16_t __pyx_t_7;
+  int16_t __pyx_t_8;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  int __pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  int __pyx_t_19;
+  char const *__pyx_t_20;
+  PyObject *__pyx_t_21 = NULL;
+  PyObject *__pyx_t_22 = NULL;
+  PyObject *__pyx_t_23 = NULL;
+  PyObject *__pyx_t_24 = NULL;
+  PyObject *__pyx_t_25 = NULL;
+  PyObject *__pyx_t_26 = NULL;
+  __Pyx_RefNannySetupContext("_encode_bind_msg", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":101
+ *             Codec codec
+ * 
+ *         if len(args) > 32767:             # <<<<<<<<<<<<<<
+ *             raise exceptions.InterfaceError(
+ *                 'the number of query arguments cannot exceed 32767')
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(6, 101, __pyx_L1_error)
+  __pyx_t_2 = ((__pyx_t_1 > 0x7FFF) != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":102
+ * 
+ *         if len(args) > 32767:
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'the number of query arguments cannot exceed 32767')
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 102, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 102, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_the_number_of_query_arguments_ca) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_the_number_of_query_arguments_ca);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 102, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(6, 102, __pyx_L1_error)
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":101
+ *             Codec codec
+ * 
+ *         if len(args) > 32767:             # <<<<<<<<<<<<<<
+ *             raise exceptions.InterfaceError(
+ *                 'the number of query arguments cannot exceed 32767')
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":105
+ *                 'the number of query arguments cannot exceed 32767')
+ * 
+ *         writer = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ * 
+ *         num_args_passed = len(args)
+ */
+  __pyx_t_3 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 105, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_v_writer = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":107
+ *         writer = WriteBuffer.new()
+ * 
+ *         num_args_passed = len(args)             # <<<<<<<<<<<<<<
+ *         if self.args_num != num_args_passed:
+ *             hint = 'Check the query against the passed list of arguments.'
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(6, 107, __pyx_L1_error)
+  __pyx_v_num_args_passed = __pyx_t_1;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":108
+ * 
+ *         num_args_passed = len(args)
+ *         if self.args_num != num_args_passed:             # <<<<<<<<<<<<<<
+ *             hint = 'Check the query against the passed list of arguments.'
+ * 
+ */
+  __pyx_t_2 = ((__pyx_v_self->args_num != __pyx_v_num_args_passed) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":109
+ *         num_args_passed = len(args)
+ *         if self.args_num != num_args_passed:
+ *             hint = 'Check the query against the passed list of arguments.'             # <<<<<<<<<<<<<<
+ * 
+ *             if self.args_num == 0:
+ */
+    __Pyx_INCREF(__pyx_kp_u_Check_the_query_against_the_pass);
+    __pyx_v_hint = __pyx_kp_u_Check_the_query_against_the_pass;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":111
+ *             hint = 'Check the query against the passed list of arguments.'
+ * 
+ *             if self.args_num == 0:             # <<<<<<<<<<<<<<
+ *                 # If the server was expecting zero arguments, it is likely
+ *                 # that the user tried to parametrize a statement that does
+ */
+    __pyx_t_2 = ((__pyx_v_self->args_num == 0) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":115
+ *                 # that the user tried to parametrize a statement that does
+ *                 # not support parameters.
+ *                 hint += (r'  Note that parameters are supported only in'             # <<<<<<<<<<<<<<
+ *                          r' SELECT, INSERT, UPDATE, DELETE, and VALUES'
+ *                          r' statements, and will *not* work in statements '
+ */
+      __pyx_t_3 = __Pyx_PyUnicode_Concat(__pyx_v_hint, __pyx_kp_u_Note_that_parameters_are_suppor); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 115, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF_SET(__pyx_v_hint, ((PyObject*)__pyx_t_3));
+      __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":111
+ *             hint = 'Check the query against the passed list of arguments.'
+ * 
+ *             if self.args_num == 0:             # <<<<<<<<<<<<<<
+ *                 # If the server was expecting zero arguments, it is likely
+ *                 # that the user tried to parametrize a statement that does
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":120
+ *                          r' like CREATE VIEW or DECLARE CURSOR.')
+ * 
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'the server expects {x} argument{s} for this query, '
+ *                 '{y} {w} passed'.format(
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 120, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 120, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":122
+ *             raise exceptions.InterfaceError(
+ *                 'the server expects {x} argument{s} for this query, '
+ *                 '{y} {w} passed'.format(             # <<<<<<<<<<<<<<
+ *                     x=self.args_num, s='s' if self.args_num != 1 else '',
+ *                     y=num_args_passed,
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_the_server_expects_x_argument_s, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":123
+ *                 'the server expects {x} argument{s} for this query, '
+ *                 '{y} {w} passed'.format(
+ *                     x=self.args_num, s='s' if self.args_num != 1 else '',             # <<<<<<<<<<<<<<
+ *                     y=num_args_passed,
+ *                     w='was' if num_args_passed == 1 else 'were'),
+ */
+    __pyx_t_4 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 123, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_6 = __Pyx_PyInt_From_int16_t(__pyx_v_self->args_num); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 123, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_x, __pyx_t_6) < 0) __PYX_ERR(6, 123, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (((__pyx_v_self->args_num != 1) != 0)) {
+      __Pyx_INCREF(__pyx_n_u_s);
+      __pyx_t_6 = __pyx_n_u_s;
+    } else {
+      __Pyx_INCREF(__pyx_kp_u__25);
+      __pyx_t_6 = __pyx_kp_u__25;
+    }
+    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_s, __pyx_t_6) < 0) __PYX_ERR(6, 123, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":124
+ *                 '{y} {w} passed'.format(
+ *                     x=self.args_num, s='s' if self.args_num != 1 else '',
+ *                     y=num_args_passed,             # <<<<<<<<<<<<<<
+ *                     w='was' if num_args_passed == 1 else 'were'),
+ *                 hint=hint)
+ */
+    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_num_args_passed); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 124, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_y, __pyx_t_6) < 0) __PYX_ERR(6, 123, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":125
+ *                     x=self.args_num, s='s' if self.args_num != 1 else '',
+ *                     y=num_args_passed,
+ *                     w='was' if num_args_passed == 1 else 'were'),             # <<<<<<<<<<<<<<
+ *                 hint=hint)
+ * 
+ */
+    if (((__pyx_v_num_args_passed == 1) != 0)) {
+      __Pyx_INCREF(__pyx_n_u_was);
+      __pyx_t_6 = __pyx_n_u_was;
+    } else {
+      __Pyx_INCREF(__pyx_n_u_were);
+      __pyx_t_6 = __pyx_n_u_were;
+    }
+    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_w, __pyx_t_6) < 0) __PYX_ERR(6, 123, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":122
+ *             raise exceptions.InterfaceError(
+ *                 'the server expects {x} argument{s} for this query, '
+ *                 '{y} {w} passed'.format(             # <<<<<<<<<<<<<<
+ *                     x=self.args_num, s='s' if self.args_num != 1 else '',
+ *                     y=num_args_passed,
+ */
+    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 122, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":120
+ *                          r' like CREATE VIEW or DECLARE CURSOR.')
+ * 
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'the server expects {x} argument{s} for this query, '
+ *                 '{y} {w} passed'.format(
+ */
+    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 120, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
+    __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":126
+ *                     y=num_args_passed,
+ *                     w='was' if num_args_passed == 1 else 'were'),
+ *                 hint=hint)             # <<<<<<<<<<<<<<
+ * 
+ *         if self.have_text_args:
+ */
+    __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 126, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_hint, __pyx_v_hint) < 0) __PYX_ERR(6, 126, __pyx_L1_error)
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":120
+ *                          r' like CREATE VIEW or DECLARE CURSOR.')
+ * 
+ *             raise exceptions.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'the server expects {x} argument{s} for this query, '
+ *                 '{y} {w} passed'.format(
+ */
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 120, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(6, 120, __pyx_L1_error)
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":108
+ * 
+ *         num_args_passed = len(args)
+ *         if self.args_num != num_args_passed:             # <<<<<<<<<<<<<<
+ *             hint = 'Check the query against the passed list of arguments.'
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":128
+ *                 hint=hint)
+ * 
+ *         if self.have_text_args:             # <<<<<<<<<<<<<<
+ *             writer.write_int16(self.args_num)
+ *             for idx in range(self.args_num):
+ */
+  __pyx_t_2 = (__pyx_v_self->have_text_args != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":129
+ * 
+ *         if self.have_text_args:
+ *             writer.write_int16(self.args_num)             # <<<<<<<<<<<<<<
+ *             for idx in range(self.args_num):
+ *                 codec = <Codec>(self.args_codecs[idx])
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int16(__pyx_v_writer, __pyx_v_self->args_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 129, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":130
+ *         if self.have_text_args:
+ *             writer.write_int16(self.args_num)
+ *             for idx in range(self.args_num):             # <<<<<<<<<<<<<<
+ *                 codec = <Codec>(self.args_codecs[idx])
+ *                 writer.write_int16(codec.format)
+ */
+    __pyx_t_7 = __pyx_v_self->args_num;
+    __pyx_t_8 = __pyx_t_7;
+    for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
+      __pyx_v_idx = __pyx_t_9;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":131
+ *             writer.write_int16(self.args_num)
+ *             for idx in range(self.args_num):
+ *                 codec = <Codec>(self.args_codecs[idx])             # <<<<<<<<<<<<<<
+ *                 writer.write_int16(codec.format)
+ *         else:
+ */
+      if (unlikely(__pyx_v_self->args_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(6, 131, __pyx_L1_error)
+      }
+      __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_self->args_codecs, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 131, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_6 = __pyx_t_3;
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_6));
+      __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":132
+ *             for idx in range(self.args_num):
+ *                 codec = <Codec>(self.args_codecs[idx])
+ *                 writer.write_int16(codec.format)             # <<<<<<<<<<<<<<
+ *         else:
+ *             # All arguments are in binary format
+ */
+      __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int16(__pyx_v_writer, __pyx_v_codec->format); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 132, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":128
+ *                 hint=hint)
+ * 
+ *         if self.have_text_args:             # <<<<<<<<<<<<<<
+ *             writer.write_int16(self.args_num)
+ *             for idx in range(self.args_num):
+ */
+    goto __pyx_L6;
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":135
+ *         else:
+ *             # All arguments are in binary format
+ *             writer.write_int32(0x00010001)             # <<<<<<<<<<<<<<
+ * 
+ *         writer.write_int16(self.args_num)
+ */
+  /*else*/ {
+    __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int32(__pyx_v_writer, 0x00010001); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 135, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  }
+  __pyx_L6:;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":137
+ *             writer.write_int32(0x00010001)
+ * 
+ *         writer.write_int16(self.args_num)             # <<<<<<<<<<<<<<
+ * 
+ *         for idx in range(self.args_num):
+ */
+  __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int16(__pyx_v_writer, __pyx_v_self->args_num); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 137, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":139
+ *         writer.write_int16(self.args_num)
+ * 
+ *         for idx in range(self.args_num):             # <<<<<<<<<<<<<<
+ *             arg = args[idx]
+ *             if arg is None:
+ */
+  __pyx_t_7 = __pyx_v_self->args_num;
+  __pyx_t_8 = __pyx_t_7;
+  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
+    __pyx_v_idx = __pyx_t_9;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":140
+ * 
+ *         for idx in range(self.args_num):
+ *             arg = args[idx]             # <<<<<<<<<<<<<<
+ *             if arg is None:
+ *                 writer.write_int32(-1)
+ */
+    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 140, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_XDECREF_SET(__pyx_v_arg, __pyx_t_6);
+    __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":141
+ *         for idx in range(self.args_num):
+ *             arg = args[idx]
+ *             if arg is None:             # <<<<<<<<<<<<<<
+ *                 writer.write_int32(-1)
+ *             else:
+ */
+    __pyx_t_2 = (__pyx_v_arg == Py_None);
+    __pyx_t_10 = (__pyx_t_2 != 0);
+    if (__pyx_t_10) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":142
+ *             arg = args[idx]
+ *             if arg is None:
+ *                 writer.write_int32(-1)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 codec = <Codec>(self.args_codecs[idx])
+ */
+      __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int32(__pyx_v_writer, -1); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 142, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":141
+ *         for idx in range(self.args_num):
+ *             arg = args[idx]
+ *             if arg is None:             # <<<<<<<<<<<<<<
+ *                 writer.write_int32(-1)
+ *             else:
+ */
+      goto __pyx_L11;
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":144
+ *                 writer.write_int32(-1)
+ *             else:
+ *                 codec = <Codec>(self.args_codecs[idx])             # <<<<<<<<<<<<<<
+ *                 try:
+ *                     codec.encode(self.settings, writer, arg)
+ */
+    /*else*/ {
+      if (unlikely(__pyx_v_self->args_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(6, 144, __pyx_L1_error)
+      }
+      __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v_self->args_codecs, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 144, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __pyx_t_3 = __pyx_t_6;
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+      __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":145
+ *             else:
+ *                 codec = <Codec>(self.args_codecs[idx])
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     codec.encode(self.settings, writer, arg)
+ *                 except (AssertionError, exceptions.InternalClientError):
+ */
+      {
+        __Pyx_PyThreadState_declare
+        __Pyx_PyThreadState_assign
+        __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
+        __Pyx_XGOTREF(__pyx_t_11);
+        __Pyx_XGOTREF(__pyx_t_12);
+        __Pyx_XGOTREF(__pyx_t_13);
+        /*try:*/ {
+
+          /* "asyncpg/protocol/prepared_stmt.pyx":146
+ *                 codec = <Codec>(self.args_codecs[idx])
+ *                 try:
+ *                     codec.encode(self.settings, writer, arg)             # <<<<<<<<<<<<<<
+ *                 except (AssertionError, exceptions.InternalClientError):
+ *                     # These are internal errors and should raise as-is.
+ */
+          __pyx_t_3 = ((PyObject *)__pyx_v_self->settings);
+          __Pyx_INCREF(__pyx_t_3);
+          __pyx_t_6 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_t_3), __pyx_v_writer, __pyx_v_arg); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 146, __pyx_L12_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+          /* "asyncpg/protocol/prepared_stmt.pyx":145
+ *             else:
+ *                 codec = <Codec>(self.args_codecs[idx])
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     codec.encode(self.settings, writer, arg)
+ *                 except (AssertionError, exceptions.InternalClientError):
+ */
+        }
+        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        goto __pyx_L19_try_end;
+        __pyx_L12_error:;
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":147
+ *                 try:
+ *                     codec.encode(self.settings, writer, arg)
+ *                 except (AssertionError, exceptions.InternalClientError):             # <<<<<<<<<<<<<<
+ *                     # These are internal errors and should raise as-is.
+ *                     raise
+ */
+        __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_3, &__pyx_t_4);
+        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 147, __pyx_L14_except_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_14)) __PYX_ERR(6, 147, __pyx_L14_except_error)
+        __Pyx_GOTREF(__pyx_t_14);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __pyx_t_15 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_builtin_AssertionError) || __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_14);
+        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+        __Pyx_ErrRestore(__pyx_t_6, __pyx_t_3, __pyx_t_4);
+        __pyx_t_6 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0;
+        if (__pyx_t_15) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_6) < 0) __PYX_ERR(6, 147, __pyx_L14_except_error)
+          __Pyx_GOTREF(__pyx_t_4);
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_GOTREF(__pyx_t_6);
+
+          /* "asyncpg/protocol/prepared_stmt.pyx":149
+ *                 except (AssertionError, exceptions.InternalClientError):
+ *                     # These are internal errors and should raise as-is.
+ *                     raise             # <<<<<<<<<<<<<<
+ *                 except exceptions.InterfaceError:
+ *                     # This is already a descriptive error.
+ */
+          __Pyx_GIVEREF(__pyx_t_4);
+          __Pyx_GIVEREF(__pyx_t_3);
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_3, __pyx_t_6);
+          __pyx_t_4 = 0; __pyx_t_3 = 0; __pyx_t_6 = 0; 
+          __PYX_ERR(6, 149, __pyx_L14_except_error)
+        }
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":150
+ *                     # These are internal errors and should raise as-is.
+ *                     raise
+ *                 except exceptions.InterfaceError:             # <<<<<<<<<<<<<<
+ *                     # This is already a descriptive error.
+ *                     raise
+ */
+        __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_3, &__pyx_t_4);
+        __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_14)) __PYX_ERR(6, 150, __pyx_L14_except_error)
+        __Pyx_GOTREF(__pyx_t_14);
+        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 150, __pyx_L14_except_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+        __pyx_t_15 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_5);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_ErrRestore(__pyx_t_6, __pyx_t_3, __pyx_t_4);
+        __pyx_t_6 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0;
+        if (__pyx_t_15) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_6) < 0) __PYX_ERR(6, 150, __pyx_L14_except_error)
+          __Pyx_GOTREF(__pyx_t_4);
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_GOTREF(__pyx_t_6);
+
+          /* "asyncpg/protocol/prepared_stmt.pyx":152
+ *                 except exceptions.InterfaceError:
+ *                     # This is already a descriptive error.
+ *                     raise             # <<<<<<<<<<<<<<
+ *                 except Exception as e:
+ *                     # Everything else is assumed to be an encoding error
+ */
+          __Pyx_GIVEREF(__pyx_t_4);
+          __Pyx_GIVEREF(__pyx_t_3);
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_3, __pyx_t_6);
+          __pyx_t_4 = 0; __pyx_t_3 = 0; __pyx_t_6 = 0; 
+          __PYX_ERR(6, 152, __pyx_L14_except_error)
+        }
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":153
+ *                     # This is already a descriptive error.
+ *                     raise
+ *                 except Exception as e:             # <<<<<<<<<<<<<<
+ *                     # Everything else is assumed to be an encoding error
+ *                     # due to invalid input.
+ */
+        __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+        if (__pyx_t_15) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(6, 153, __pyx_L14_except_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_GOTREF(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_3);
+          __pyx_v_e = __pyx_t_3;
+          /*try:*/ {
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":156
+ *                     # Everything else is assumed to be an encoding error
+ *                     # due to invalid input.
+ *                     value_repr = repr(arg)             # <<<<<<<<<<<<<<
+ *                     if len(value_repr) > 40:
+ *                         value_repr = value_repr[:40] + '...'
+ */
+            __pyx_t_5 = PyObject_Repr(__pyx_v_arg); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 156, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            __pyx_v_value_repr = __pyx_t_5;
+            __pyx_t_5 = 0;
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":157
+ *                     # due to invalid input.
+ *                     value_repr = repr(arg)
+ *                     if len(value_repr) > 40:             # <<<<<<<<<<<<<<
+ *                         value_repr = value_repr[:40] + '...'
+ * 
+ */
+            __pyx_t_1 = PyObject_Length(__pyx_v_value_repr); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(6, 157, __pyx_L29_error)
+            __pyx_t_10 = ((__pyx_t_1 > 40) != 0);
+            if (__pyx_t_10) {
+
+              /* "asyncpg/protocol/prepared_stmt.pyx":158
+ *                     value_repr = repr(arg)
+ *                     if len(value_repr) > 40:
+ *                         value_repr = value_repr[:40] + '...'             # <<<<<<<<<<<<<<
+ * 
+ *                     raise exceptions.DataError(
+ */
+              __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_v_value_repr, 0, 40, NULL, NULL, &__pyx_slice__27, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 158, __pyx_L29_error)
+              __Pyx_GOTREF(__pyx_t_5);
+              __pyx_t_14 = PyNumber_Add(__pyx_t_5, __pyx_kp_u__28); if (unlikely(!__pyx_t_14)) __PYX_ERR(6, 158, __pyx_L29_error)
+              __Pyx_GOTREF(__pyx_t_14);
+              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+              __Pyx_DECREF_SET(__pyx_v_value_repr, __pyx_t_14);
+              __pyx_t_14 = 0;
+
+              /* "asyncpg/protocol/prepared_stmt.pyx":157
+ *                     # due to invalid input.
+ *                     value_repr = repr(arg)
+ *                     if len(value_repr) > 40:             # <<<<<<<<<<<<<<
+ *                         value_repr = value_repr[:40] + '...'
+ * 
+ */
+            }
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":160
+ *                         value_repr = value_repr[:40] + '...'
+ * 
+ *                     raise exceptions.DataError(             # <<<<<<<<<<<<<<
+ *                         'invalid input for query argument'
+ *                         ' ${n}: {v} ({msg})'.format(
+ */
+            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 160, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_DataError); if (unlikely(!__pyx_t_16)) __PYX_ERR(6, 160, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_16);
+            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":162
+ *                     raise exceptions.DataError(
+ *                         'invalid input for query argument'
+ *                         ' ${n}: {v} ({msg})'.format(             # <<<<<<<<<<<<<<
+ *                             n=idx + 1, v=value_repr, msg=e)) from e
+ * 
+ */
+            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_input_for_query_argument, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 162, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_5);
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":163
+ *                         'invalid input for query argument'
+ *                         ' ${n}: {v} ({msg})'.format(
+ *                             n=idx + 1, v=value_repr, msg=e)) from e             # <<<<<<<<<<<<<<
+ * 
+ *         if self.have_text_cols:
+ */
+            __pyx_t_17 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_17)) __PYX_ERR(6, 163, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_17);
+            __pyx_t_18 = __Pyx_PyInt_From_long((__pyx_v_idx + 1)); if (unlikely(!__pyx_t_18)) __PYX_ERR(6, 163, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_18);
+            if (PyDict_SetItem(__pyx_t_17, __pyx_n_s_n, __pyx_t_18) < 0) __PYX_ERR(6, 163, __pyx_L29_error)
+            __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+            if (PyDict_SetItem(__pyx_t_17, __pyx_n_s_v, __pyx_v_value_repr) < 0) __PYX_ERR(6, 163, __pyx_L29_error)
+            if (PyDict_SetItem(__pyx_t_17, __pyx_n_s_msg, __pyx_v_e) < 0) __PYX_ERR(6, 163, __pyx_L29_error)
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":162
+ *                     raise exceptions.DataError(
+ *                         'invalid input for query argument'
+ *                         ' ${n}: {v} ({msg})'.format(             # <<<<<<<<<<<<<<
+ *                             n=idx + 1, v=value_repr, msg=e)) from e
+ * 
+ */
+            __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_17); if (unlikely(!__pyx_t_18)) __PYX_ERR(6, 162, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_18);
+            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
+            __pyx_t_17 = NULL;
+            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
+              __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16);
+              if (likely(__pyx_t_17)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
+                __Pyx_INCREF(__pyx_t_17);
+                __Pyx_INCREF(function);
+                __Pyx_DECREF_SET(__pyx_t_16, function);
+              }
+            }
+            __pyx_t_14 = (__pyx_t_17) ? __Pyx_PyObject_Call2Args(__pyx_t_16, __pyx_t_17, __pyx_t_18) : __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_18);
+            __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+            __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
+            if (unlikely(!__pyx_t_14)) __PYX_ERR(6, 160, __pyx_L29_error)
+            __Pyx_GOTREF(__pyx_t_14);
+            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+
+            /* "asyncpg/protocol/prepared_stmt.pyx":163
+ *                         'invalid input for query argument'
+ *                         ' ${n}: {v} ({msg})'.format(
+ *                             n=idx + 1, v=value_repr, msg=e)) from e             # <<<<<<<<<<<<<<
+ * 
+ *         if self.have_text_cols:
+ */
+            __Pyx_Raise(__pyx_t_14, 0, 0, __pyx_v_e);
+            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+            __PYX_ERR(6, 160, __pyx_L29_error)
+          }
+
+          /* "asyncpg/protocol/prepared_stmt.pyx":153
+ *                     # This is already a descriptive error.
+ *                     raise
+ *                 except Exception as e:             # <<<<<<<<<<<<<<
+ *                     # Everything else is assumed to be an encoding error
+ *                     # due to invalid input.
+ */
+          /*finally:*/ {
+            __pyx_L29_error:;
+            /*exception exit:*/{
+              __Pyx_PyThreadState_declare
+              __Pyx_PyThreadState_assign
+              __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0;
+              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+              __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
+              __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
+              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+              if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_24, &__pyx_t_25, &__pyx_t_26);
+              if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23) < 0)) __Pyx_ErrFetch(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23);
+              __Pyx_XGOTREF(__pyx_t_21);
+              __Pyx_XGOTREF(__pyx_t_22);
+              __Pyx_XGOTREF(__pyx_t_23);
+              __Pyx_XGOTREF(__pyx_t_24);
+              __Pyx_XGOTREF(__pyx_t_25);
+              __Pyx_XGOTREF(__pyx_t_26);
+              __pyx_t_15 = __pyx_lineno; __pyx_t_19 = __pyx_clineno; __pyx_t_20 = __pyx_filename;
+              {
+                __Pyx_DECREF(__pyx_v_e);
+                __pyx_v_e = NULL;
+              }
+              if (PY_MAJOR_VERSION >= 3) {
+                __Pyx_XGIVEREF(__pyx_t_24);
+                __Pyx_XGIVEREF(__pyx_t_25);
+                __Pyx_XGIVEREF(__pyx_t_26);
+                __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_25, __pyx_t_26);
+              }
+              __Pyx_XGIVEREF(__pyx_t_21);
+              __Pyx_XGIVEREF(__pyx_t_22);
+              __Pyx_XGIVEREF(__pyx_t_23);
+              __Pyx_ErrRestore(__pyx_t_21, __pyx_t_22, __pyx_t_23);
+              __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0;
+              __pyx_lineno = __pyx_t_15; __pyx_clineno = __pyx_t_19; __pyx_filename = __pyx_t_20;
+              goto __pyx_L14_except_error;
+            }
+          }
+        }
+        goto __pyx_L14_except_error;
+        __pyx_L14_except_error:;
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":145
+ *             else:
+ *                 codec = <Codec>(self.args_codecs[idx])
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     codec.encode(self.settings, writer, arg)
+ *                 except (AssertionError, exceptions.InternalClientError):
+ */
+        __Pyx_XGIVEREF(__pyx_t_11);
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
+        goto __pyx_L1_error;
+        __pyx_L19_try_end:;
+      }
+    }
+    __pyx_L11:;
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":165
+ *                             n=idx + 1, v=value_repr, msg=e)) from e
+ * 
+ *         if self.have_text_cols:             # <<<<<<<<<<<<<<
+ *             writer.write_int16(self.cols_num)
+ *             for idx in range(self.cols_num):
+ */
+  __pyx_t_10 = (__pyx_v_self->have_text_cols != 0);
+  if (__pyx_t_10) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":166
+ * 
+ *         if self.have_text_cols:
+ *             writer.write_int16(self.cols_num)             # <<<<<<<<<<<<<<
+ *             for idx in range(self.cols_num):
+ *                 codec = <Codec>(self.rows_codecs[idx])
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int16(__pyx_v_writer, __pyx_v_self->cols_num); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 166, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":167
+ *         if self.have_text_cols:
+ *             writer.write_int16(self.cols_num)
+ *             for idx in range(self.cols_num):             # <<<<<<<<<<<<<<
+ *                 codec = <Codec>(self.rows_codecs[idx])
+ *                 writer.write_int16(codec.format)
+ */
+    __pyx_t_7 = __pyx_v_self->cols_num;
+    __pyx_t_8 = __pyx_t_7;
+    for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
+      __pyx_v_idx = __pyx_t_9;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":168
+ *             writer.write_int16(self.cols_num)
+ *             for idx in range(self.cols_num):
+ *                 codec = <Codec>(self.rows_codecs[idx])             # <<<<<<<<<<<<<<
+ *                 writer.write_int16(codec.format)
+ *         else:
+ */
+      if (unlikely(__pyx_v_self->rows_codecs == Py_None)) {
+        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+        __PYX_ERR(6, 168, __pyx_L1_error)
+      }
+      __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_self->rows_codecs, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 168, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_3 = __pyx_t_4;
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+      __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":169
+ *             for idx in range(self.cols_num):
+ *                 codec = <Codec>(self.rows_codecs[idx])
+ *                 writer.write_int16(codec.format)             # <<<<<<<<<<<<<<
+ *         else:
+ *             # All columns are in binary format
+ */
+      __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int16(__pyx_v_writer, __pyx_v_codec->format); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 169, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":165
+ *                             n=idx + 1, v=value_repr, msg=e)) from e
+ * 
+ *         if self.have_text_cols:             # <<<<<<<<<<<<<<
+ *             writer.write_int16(self.cols_num)
+ *             for idx in range(self.cols_num):
+ */
+    goto __pyx_L36;
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":172
+ *         else:
+ *             # All columns are in binary format
+ *             writer.write_int32(0x00010001)             # <<<<<<<<<<<<<<
+ * 
+ *         return writer
+ */
+  /*else*/ {
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_v_writer->__pyx_vtab)->write_int32(__pyx_v_writer, 0x00010001); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 172, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  }
+  __pyx_L36:;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":174
+ *             writer.write_int32(0x00010001)
+ * 
+ *         return writer             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _ensure_rows_decoder(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(((PyObject *)__pyx_v_writer));
+  __pyx_r = ((PyObject *)__pyx_v_writer);
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":95
+ *         self.closed = True
+ * 
+ *     cdef _encode_bind_msg(self, args):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             int idx
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_XDECREF(__pyx_t_17);
+  __Pyx_XDECREF(__pyx_t_18);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_writer);
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_hint);
+  __Pyx_XDECREF(__pyx_v_arg);
+  __Pyx_XDECREF(__pyx_v_e);
+  __Pyx_XDECREF(__pyx_v_value_repr);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":176
+ *         return writer
+ * 
+ *     cdef _ensure_rows_decoder(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             list cols_names
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_rows_decoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_v_cols_names = 0;
+  PyObject *__pyx_v_cols_mapping = 0;
+  PyObject *__pyx_v_row = 0;
+  uint32_t __pyx_v_oid;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_codecs = 0;
+  long __pyx_v_i;
+  PyObject *__pyx_v_col_name = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int16_t __pyx_t_6;
+  int __pyx_t_7;
+  uint32_t __pyx_t_8;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  __Pyx_RefNannySetupContext("_ensure_rows_decoder", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":185
+ *             list codecs
+ * 
+ *         if self.cols_desc is not None:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  __pyx_t_1 = (__pyx_v_self->cols_desc != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":186
+ * 
+ *         if self.cols_desc is not None:
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         if self.cols_num == 0:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":185
+ *             list codecs
+ * 
+ *         if self.cols_desc is not None:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":188
+ *             return
+ * 
+ *         if self.cols_num == 0:             # <<<<<<<<<<<<<<
+ *             self.cols_desc = record.ApgRecordDesc_New({}, ())
+ *             return
+ */
+  __pyx_t_2 = ((__pyx_v_self->cols_num == 0) != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":189
+ * 
+ *         if self.cols_num == 0:
+ *             self.cols_desc = record.ApgRecordDesc_New({}, ())             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+    __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 189, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = ApgRecordDesc_New(__pyx_t_3, __pyx_empty_tuple); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 189, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GIVEREF(__pyx_t_4);
+    __Pyx_GOTREF(__pyx_v_self->cols_desc);
+    __Pyx_DECREF(__pyx_v_self->cols_desc);
+    __pyx_v_self->cols_desc = __pyx_t_4;
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":190
+ *         if self.cols_num == 0:
+ *             self.cols_desc = record.ApgRecordDesc_New({}, ())
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         cols_mapping = collections.OrderedDict()
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":188
+ *             return
+ * 
+ *         if self.cols_num == 0:             # <<<<<<<<<<<<<<
+ *             self.cols_desc = record.ApgRecordDesc_New({}, ())
+ *             return
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":192
+ *             return
+ * 
+ *         cols_mapping = collections.OrderedDict()             # <<<<<<<<<<<<<<
+ *         cols_names = []
+ *         codecs = []
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 192, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 192, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 192, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_v_cols_mapping = __pyx_t_4;
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":193
+ * 
+ *         cols_mapping = collections.OrderedDict()
+ *         cols_names = []             # <<<<<<<<<<<<<<
+ *         codecs = []
+ *         for i from 0 <= i < self.cols_num:
+ */
+  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 193, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_v_cols_names = ((PyObject*)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":194
+ *         cols_mapping = collections.OrderedDict()
+ *         cols_names = []
+ *         codecs = []             # <<<<<<<<<<<<<<
+ *         for i from 0 <= i < self.cols_num:
+ *             row = self.row_desc[i]
+ */
+  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 194, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_v_codecs = ((PyObject*)__pyx_t_4);
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":195
+ *         cols_names = []
+ *         codecs = []
+ *         for i from 0 <= i < self.cols_num:             # <<<<<<<<<<<<<<
+ *             row = self.row_desc[i]
+ *             col_name = row[0].decode(self.settings._encoding)
+ */
+  __pyx_t_6 = __pyx_v_self->cols_num;
+  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":196
+ *         codecs = []
+ *         for i from 0 <= i < self.cols_num:
+ *             row = self.row_desc[i]             # <<<<<<<<<<<<<<
+ *             col_name = row[0].decode(self.settings._encoding)
+ *             cols_mapping[col_name] = i
+ */
+    if (unlikely(__pyx_v_self->row_desc == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(6, 196, __pyx_L1_error)
+    }
+    __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_self->row_desc, __pyx_v_i, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 196, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    if (!(likely(PyTuple_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(6, 196, __pyx_L1_error)
+    __Pyx_XDECREF_SET(__pyx_v_row, ((PyObject*)__pyx_t_4));
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":197
+ *         for i from 0 <= i < self.cols_num:
+ *             row = self.row_desc[i]
+ *             col_name = row[0].decode(self.settings._encoding)             # <<<<<<<<<<<<<<
+ *             cols_mapping[col_name] = i
+ *             cols_names.append(col_name)
+ */
+    if (unlikely(__pyx_v_row == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(6, 197, __pyx_L1_error)
+    }
+    __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_row, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 197, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_decode); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 197, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_self->settings->_encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->settings->_encoding);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 197, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF_SET(__pyx_v_col_name, __pyx_t_4);
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":198
+ *             row = self.row_desc[i]
+ *             col_name = row[0].decode(self.settings._encoding)
+ *             cols_mapping[col_name] = i             # <<<<<<<<<<<<<<
+ *             cols_names.append(col_name)
+ *             oid = row[3]
+ */
+    __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 198, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    if (unlikely(PyObject_SetItem(__pyx_v_cols_mapping, __pyx_v_col_name, __pyx_t_4) < 0)) __PYX_ERR(6, 198, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":199
+ *             col_name = row[0].decode(self.settings._encoding)
+ *             cols_mapping[col_name] = i
+ *             cols_names.append(col_name)             # <<<<<<<<<<<<<<
+ *             oid = row[3]
+ *             codec = self.settings.get_data_codec(oid)
+ */
+    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_cols_names, __pyx_v_col_name); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(6, 199, __pyx_L1_error)
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":200
+ *             cols_mapping[col_name] = i
+ *             cols_names.append(col_name)
+ *             oid = row[3]             # <<<<<<<<<<<<<<
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None or not codec.has_decoder():
+ */
+    if (unlikely(__pyx_v_row == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(6, 200, __pyx_L1_error)
+    }
+    __pyx_t_4 = __Pyx_GetItemInt_Tuple(__pyx_v_row, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 200, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_4); if (unlikely((__pyx_t_8 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 200, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_v_oid = __pyx_t_8;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":201
+ *             cols_names.append(col_name)
+ *             oid = row[3]
+ *             codec = self.settings.get_data_codec(oid)             # <<<<<<<<<<<<<<
+ *             if codec is None or not codec.has_decoder():
+ *                 raise exceptions.InternalClientError(
+ */
+    __pyx_t_4 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_self->settings, __pyx_v_oid, 0, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 201, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_4));
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":202
+ *             oid = row[3]
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None or not codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for OID {}'.format(oid))
+ */
+    __pyx_t_1 = (((PyObject *)__pyx_v_codec) == Py_None);
+    __pyx_t_9 = (__pyx_t_1 != 0);
+    if (!__pyx_t_9) {
+    } else {
+      __pyx_t_2 = __pyx_t_9;
+      goto __pyx_L8_bool_binop_done;
+    }
+    __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder(__pyx_v_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 202, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(6, 202, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_1 = ((!__pyx_t_9) != 0);
+    __pyx_t_2 = __pyx_t_1;
+    __pyx_L8_bool_binop_done:;
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":203
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None or not codec.has_decoder():
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'no decoder for OID {}'.format(oid))
+ *             if not codec.is_binary():
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 203, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 203, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":204
+ *             if codec is None or not codec.has_decoder():
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for OID {}'.format(oid))             # <<<<<<<<<<<<<<
+ *             if not codec.is_binary():
+ *                 self.have_text_cols = True
+ */
+      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_no_decoder_for_OID, __pyx_n_s_format); if (unlikely(!__pyx_t_10)) __PYX_ERR(6, 204, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_10);
+      __pyx_t_11 = __Pyx_PyInt_From_uint32_t(__pyx_v_oid); if (unlikely(!__pyx_t_11)) __PYX_ERR(6, 204, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __pyx_t_12 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
+        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_10);
+        if (likely(__pyx_t_12)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
+          __Pyx_INCREF(__pyx_t_12);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_10, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_12, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11);
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(6, 204, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __pyx_t_10 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_10)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_10);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_10, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3);
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 203, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __PYX_ERR(6, 203, __pyx_L1_error)
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":202
+ *             oid = row[3]
+ *             codec = self.settings.get_data_codec(oid)
+ *             if codec is None or not codec.has_decoder():             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for OID {}'.format(oid))
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":205
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for OID {}'.format(oid))
+ *             if not codec.is_binary():             # <<<<<<<<<<<<<<
+ *                 self.have_text_cols = True
+ * 
+ */
+    __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_is_binary(__pyx_v_codec); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 205, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(6, 205, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_1 = ((!__pyx_t_2) != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":206
+ *                     'no decoder for OID {}'.format(oid))
+ *             if not codec.is_binary():
+ *                 self.have_text_cols = True             # <<<<<<<<<<<<<<
+ * 
+ *             codecs.append(codec)
+ */
+      __pyx_v_self->have_text_cols = 1;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":205
+ *                 raise exceptions.InternalClientError(
+ *                     'no decoder for OID {}'.format(oid))
+ *             if not codec.is_binary():             # <<<<<<<<<<<<<<
+ *                 self.have_text_cols = True
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":208
+ *                 self.have_text_cols = True
+ * 
+ *             codecs.append(codec)             # <<<<<<<<<<<<<<
+ * 
+ *         self.cols_desc = record.ApgRecordDesc_New(
+ */
+    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_codecs, ((PyObject *)__pyx_v_codec)); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(6, 208, __pyx_L1_error)
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":211
+ * 
+ *         self.cols_desc = record.ApgRecordDesc_New(
+ *             cols_mapping, tuple(cols_names))             # <<<<<<<<<<<<<<
+ * 
+ *         self.rows_codecs = tuple(codecs)
+ */
+  __pyx_t_4 = PyList_AsTuple(__pyx_v_cols_names); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 211, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":210
+ *             codecs.append(codec)
+ * 
+ *         self.cols_desc = record.ApgRecordDesc_New(             # <<<<<<<<<<<<<<
+ *             cols_mapping, tuple(cols_names))
+ * 
+ */
+  __pyx_t_5 = ApgRecordDesc_New(__pyx_v_cols_mapping, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 210, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_GIVEREF(__pyx_t_5);
+  __Pyx_GOTREF(__pyx_v_self->cols_desc);
+  __Pyx_DECREF(__pyx_v_self->cols_desc);
+  __pyx_v_self->cols_desc = __pyx_t_5;
+  __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":213
+ *             cols_mapping, tuple(cols_names))
+ * 
+ *         self.rows_codecs = tuple(codecs)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _ensure_args_encoder(self):
+ */
+  __pyx_t_5 = PyList_AsTuple(__pyx_v_codecs); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 213, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_GIVEREF(__pyx_t_5);
+  __Pyx_GOTREF(__pyx_v_self->rows_codecs);
+  __Pyx_DECREF(__pyx_v_self->rows_codecs);
+  __pyx_v_self->rows_codecs = ((PyObject*)__pyx_t_5);
+  __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":176
+ *         return writer
+ * 
+ *     cdef _ensure_rows_decoder(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             list cols_names
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._ensure_rows_decoder", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_cols_names);
+  __Pyx_XDECREF(__pyx_v_cols_mapping);
+  __Pyx_XDECREF(__pyx_v_row);
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_codecs);
+  __Pyx_XDECREF(__pyx_v_col_name);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":215
+ *         self.rows_codecs = tuple(codecs)
+ * 
+ *     cdef _ensure_args_encoder(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             uint32_t p_oid
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_args_encoder(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  uint32_t __pyx_v_p_oid;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  PyObject *__pyx_v_codecs = 0;
+  long __pyx_v_i;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  int __pyx_t_4;
+  int16_t __pyx_t_5;
+  uint32_t __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  int __pyx_t_12;
+  __Pyx_RefNannySetupContext("_ensure_args_encoder", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":219
+ *             uint32_t p_oid
+ *             Codec codec
+ *             list codecs = []             # <<<<<<<<<<<<<<
+ * 
+ *         if self.args_num == 0 or self.args_codecs is not None:
+ */
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 219, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":221
+ *             list codecs = []
+ * 
+ *         if self.args_num == 0 or self.args_codecs is not None:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  __pyx_t_3 = ((__pyx_v_self->args_num == 0) != 0);
+  if (!__pyx_t_3) {
+  } else {
+    __pyx_t_2 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_3 = (__pyx_v_self->args_codecs != ((PyObject*)Py_None));
+  __pyx_t_4 = (__pyx_t_3 != 0);
+  __pyx_t_2 = __pyx_t_4;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":222
+ * 
+ *         if self.args_num == 0 or self.args_codecs is not None:
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         for i from 0 <= i < self.args_num:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":221
+ *             list codecs = []
+ * 
+ *         if self.args_num == 0 or self.args_codecs is not None:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":224
+ *             return
+ * 
+ *         for i from 0 <= i < self.args_num:             # <<<<<<<<<<<<<<
+ *             p_oid = self.parameters_desc[i]
+ *             codec = self.settings.get_data_codec(p_oid)
+ */
+  __pyx_t_5 = __pyx_v_self->args_num;
+  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":225
+ * 
+ *         for i from 0 <= i < self.args_num:
+ *             p_oid = self.parameters_desc[i]             # <<<<<<<<<<<<<<
+ *             codec = self.settings.get_data_codec(p_oid)
+ *             if codec is None or not codec.has_encoder():
+ */
+    if (unlikely(__pyx_v_self->parameters_desc == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(6, 225, __pyx_L1_error)
+    }
+    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_self->parameters_desc, __pyx_v_i, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 225, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_6 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_6 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(6, 225, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_v_p_oid = __pyx_t_6;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":226
+ *         for i from 0 <= i < self.args_num:
+ *             p_oid = self.parameters_desc[i]
+ *             codec = self.settings.get_data_codec(p_oid)             # <<<<<<<<<<<<<<
+ *             if codec is None or not codec.has_encoder():
+ *                 raise exceptions.InternalClientError(
+ */
+    __pyx_t_1 = ((PyObject *)__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec(__pyx_v_self->settings, __pyx_v_p_oid, 0, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 226, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_1));
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":227
+ *             p_oid = self.parameters_desc[i]
+ *             codec = self.settings.get_data_codec(p_oid)
+ *             if codec is None or not codec.has_encoder():             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'no encoder for OID {}'.format(p_oid))
+ */
+    __pyx_t_4 = (((PyObject *)__pyx_v_codec) == Py_None);
+    __pyx_t_3 = (__pyx_t_4 != 0);
+    if (!__pyx_t_3) {
+    } else {
+      __pyx_t_2 = __pyx_t_3;
+      goto __pyx_L9_bool_binop_done;
+    }
+    __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(__pyx_v_codec); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 227, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(6, 227, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_4 = ((!__pyx_t_3) != 0);
+    __pyx_t_2 = __pyx_t_4;
+    __pyx_L9_bool_binop_done:;
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":228
+ *             codec = self.settings.get_data_codec(p_oid)
+ *             if codec is None or not codec.has_encoder():
+ *                 raise exceptions.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'no encoder for OID {}'.format(p_oid))
+ *             if codec.type not in {}:
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 228, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 228, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":229
+ *             if codec is None or not codec.has_encoder():
+ *                 raise exceptions.InternalClientError(
+ *                     'no encoder for OID {}'.format(p_oid))             # <<<<<<<<<<<<<<
+ *             if codec.type not in {}:
+ *                 self.have_text_args = True
+ */
+      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_no_encoder_for_OID, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(6, 229, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_p_oid); if (unlikely(!__pyx_t_10)) __PYX_ERR(6, 229, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_10);
+      __pyx_t_11 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
+        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9);
+        if (likely(__pyx_t_11)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+          __Pyx_INCREF(__pyx_t_11);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_9, function);
+        }
+      }
+      __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_11, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10);
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+      if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 229, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
+        if (likely(__pyx_t_9)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+          __Pyx_INCREF(__pyx_t_9);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_8, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 228, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(6, 228, __pyx_L1_error)
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":227
+ *             p_oid = self.parameters_desc[i]
+ *             codec = self.settings.get_data_codec(p_oid)
+ *             if codec is None or not codec.has_encoder():             # <<<<<<<<<<<<<<
+ *                 raise exceptions.InternalClientError(
+ *                     'no encoder for OID {}'.format(p_oid))
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":230
+ *                 raise exceptions.InternalClientError(
+ *                     'no encoder for OID {}'.format(p_oid))
+ *             if codec.type not in {}:             # <<<<<<<<<<<<<<
+ *                 self.have_text_args = True
+ * 
+ */
+    __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_CodecType(__pyx_v_codec->type); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 230, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_8 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 230, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_t_1, __pyx_t_8, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(6, 230, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __pyx_t_4 = (__pyx_t_2 != 0);
+    if (__pyx_t_4) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":231
+ *                     'no encoder for OID {}'.format(p_oid))
+ *             if codec.type not in {}:
+ *                 self.have_text_args = True             # <<<<<<<<<<<<<<
+ * 
+ *             codecs.append(codec)
+ */
+      __pyx_v_self->have_text_args = 1;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":230
+ *                 raise exceptions.InternalClientError(
+ *                     'no encoder for OID {}'.format(p_oid))
+ *             if codec.type not in {}:             # <<<<<<<<<<<<<<
+ *                 self.have_text_args = True
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":233
+ *                 self.have_text_args = True
+ * 
+ *             codecs.append(codec)             # <<<<<<<<<<<<<<
+ * 
+ *         self.args_codecs = tuple(codecs)
+ */
+    __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_codecs, ((PyObject *)__pyx_v_codec)); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(6, 233, __pyx_L1_error)
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":235
+ *             codecs.append(codec)
+ * 
+ *         self.args_codecs = tuple(codecs)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _set_row_desc(self, object desc):
+ */
+  __pyx_t_8 = PyList_AsTuple(__pyx_v_codecs); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 235, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_GIVEREF(__pyx_t_8);
+  __Pyx_GOTREF(__pyx_v_self->args_codecs);
+  __Pyx_DECREF(__pyx_v_self->args_codecs);
+  __pyx_v_self->args_codecs = ((PyObject*)__pyx_t_8);
+  __pyx_t_8 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":215
+ *         self.rows_codecs = tuple(codecs)
+ * 
+ *     cdef _ensure_args_encoder(self):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             uint32_t p_oid
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._ensure_args_encoder", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_codecs);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":237
+ *         self.args_codecs = tuple(codecs)
+ * 
+ *     cdef _set_row_desc(self, object desc):             # <<<<<<<<<<<<<<
+ *         self.row_desc = _decode_row_desc(desc)
+ *         self.cols_num = <int16_t>(len(self.row_desc))
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_row_desc(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_desc) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  __Pyx_RefNannySetupContext("_set_row_desc", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":238
+ * 
+ *     cdef _set_row_desc(self, object desc):
+ *         self.row_desc = _decode_row_desc(desc)             # <<<<<<<<<<<<<<
+ *         self.cols_num = <int16_t>(len(self.row_desc))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol__decode_row_desc(__pyx_v_desc); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 238, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(6, 238, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->row_desc);
+  __Pyx_DECREF(__pyx_v_self->row_desc);
+  __pyx_v_self->row_desc = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":239
+ *     cdef _set_row_desc(self, object desc):
+ *         self.row_desc = _decode_row_desc(desc)
+ *         self.cols_num = <int16_t>(len(self.row_desc))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _set_args_desc(self, object desc):
+ */
+  __pyx_t_1 = __pyx_v_self->row_desc;
+  __Pyx_INCREF(__pyx_t_1);
+  if (unlikely(__pyx_t_1 == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(6, 239, __pyx_L1_error)
+  }
+  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(6, 239, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_self->cols_num = ((int16_t)__pyx_t_2);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":237
+ *         self.args_codecs = tuple(codecs)
+ * 
+ *     cdef _set_row_desc(self, object desc):             # <<<<<<<<<<<<<<
+ *         self.row_desc = _decode_row_desc(desc)
+ *         self.cols_num = <int16_t>(len(self.row_desc))
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._set_row_desc", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":241
+ *         self.cols_num = <int16_t>(len(self.row_desc))
+ * 
+ *     cdef _set_args_desc(self, object desc):             # <<<<<<<<<<<<<<
+ *         self.parameters_desc = _decode_parameters_desc(desc)
+ *         self.args_num = <int16_t>(len(self.parameters_desc))
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_args_desc(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, PyObject *__pyx_v_desc) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  __Pyx_RefNannySetupContext("_set_args_desc", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":242
+ * 
+ *     cdef _set_args_desc(self, object desc):
+ *         self.parameters_desc = _decode_parameters_desc(desc)             # <<<<<<<<<<<<<<
+ *         self.args_num = <int16_t>(len(self.parameters_desc))
+ * 
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol__decode_parameters_desc(__pyx_v_desc); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 242, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(6, 242, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->parameters_desc);
+  __Pyx_DECREF(__pyx_v_self->parameters_desc);
+  __pyx_v_self->parameters_desc = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":243
+ *     cdef _set_args_desc(self, object desc):
+ *         self.parameters_desc = _decode_parameters_desc(desc)
+ *         self.args_num = <int16_t>(len(self.parameters_desc))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _decode_row(self, const char* cbuf, ssize_t buf_len):
+ */
+  __pyx_t_1 = __pyx_v_self->parameters_desc;
+  __Pyx_INCREF(__pyx_t_1);
+  if (unlikely(__pyx_t_1 == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(6, 243, __pyx_L1_error)
+  }
+  __pyx_t_2 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(6, 243, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_self->args_num = ((int16_t)__pyx_t_2);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":241
+ *         self.cols_num = <int16_t>(len(self.row_desc))
+ * 
+ *     cdef _set_args_desc(self, object desc):             # <<<<<<<<<<<<<<
+ *         self.parameters_desc = _decode_parameters_desc(desc)
+ *         self.args_num = <int16_t>(len(self.parameters_desc))
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._set_args_desc", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":245
+ *         self.args_num = <int16_t>(len(self.parameters_desc))
+ * 
+ *     cdef _decode_row(self, const char* cbuf, ssize_t buf_len):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec codec
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__decode_row(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, char const *__pyx_v_cbuf, Py_ssize_t __pyx_v_buf_len) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *__pyx_v_codec = 0;
+  int16_t __pyx_v_fnum;
+  int32_t __pyx_v_flen;
+  PyObject *__pyx_v_dec_row = 0;
+  PyObject *__pyx_v_rows_codecs = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *__pyx_v_settings = 0;
+  int32_t __pyx_v_i;
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer __pyx_v_rbuf;
+  Py_ssize_t __pyx_v_bl;
+  PyObject *__pyx_v_val = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  char const *__pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  int16_t __pyx_t_12;
+  int16_t __pyx_t_13;
+  int32_t __pyx_t_14;
+  PyObject *__pyx_t_15;
+  __Pyx_RefNannySetupContext("_decode_row", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":251
+ *             int32_t flen
+ *             object dec_row
+ *             tuple rows_codecs = self.rows_codecs             # <<<<<<<<<<<<<<
+ *             ConnectionSettings settings = self.settings
+ *             int32_t i
+ */
+  __pyx_t_1 = __pyx_v_self->rows_codecs;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_rows_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":252
+ *             object dec_row
+ *             tuple rows_codecs = self.rows_codecs
+ *             ConnectionSettings settings = self.settings             # <<<<<<<<<<<<<<
+ *             int32_t i
+ *             FRBuffer rbuf
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_v_self->settings);
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":257
+ *             ssize_t bl
+ * 
+ *         frb_init(&rbuf, cbuf, buf_len)             # <<<<<<<<<<<<<<
+ * 
+ *         fnum = hton.unpack_int16(frb_read(&rbuf, 2))
+ */
+  __pyx_f_7asyncpg_7pgproto_7pgproto_frb_init((&__pyx_v_rbuf), __pyx_v_cbuf, __pyx_v_buf_len);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":259
+ *         frb_init(&rbuf, cbuf, buf_len)
+ * 
+ *         fnum = hton.unpack_int16(frb_read(&rbuf, 2))             # <<<<<<<<<<<<<<
+ * 
+ *         if fnum != self.cols_num:
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read((&__pyx_v_rbuf), 2); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(6, 259, __pyx_L1_error)
+  __pyx_v_fnum = unpack_int16(__pyx_t_2);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":261
+ *         fnum = hton.unpack_int16(frb_read(&rbuf, 2))
+ * 
+ *         if fnum != self.cols_num:             # <<<<<<<<<<<<<<
+ *             raise exceptions.ProtocolError(
+ *                 'the number of columns in the result row ({}) is '
+ */
+  __pyx_t_3 = ((__pyx_v_fnum != __pyx_v_self->cols_num) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":262
+ * 
+ *         if fnum != self.cols_num:
+ *             raise exceptions.ProtocolError(             # <<<<<<<<<<<<<<
+ *                 'the number of columns in the result row ({}) is '
+ *                 'different from what was described ({})'.format(
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 262, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 262, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":264
+ *             raise exceptions.ProtocolError(
+ *                 'the number of columns in the result row ({}) is '
+ *                 'different from what was described ({})'.format(             # <<<<<<<<<<<<<<
+ *                     fnum, self.cols_num))
+ * 
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_the_number_of_columns_in_the_res, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 264, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":265
+ *                 'the number of columns in the result row ({}) is '
+ *                 'different from what was described ({})'.format(
+ *                     fnum, self.cols_num))             # <<<<<<<<<<<<<<
+ * 
+ *         dec_row = record.ApgRecord_New(self.cols_desc, fnum)
+ */
+    __pyx_t_7 = __Pyx_PyInt_From_int16_t(__pyx_v_fnum); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 265, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = __Pyx_PyInt_From_int16_t(__pyx_v_self->cols_num); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 265, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_9 = NULL;
+    __pyx_t_10 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_9)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_9);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+        __pyx_t_10 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
+      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 264, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
+      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 264, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(6, 264, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      if (__pyx_t_9) {
+        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_7);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
+      __pyx_t_7 = 0;
+      __pyx_t_8 = 0;
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 264, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 262, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(6, 262, __pyx_L1_error)
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":261
+ *         fnum = hton.unpack_int16(frb_read(&rbuf, 2))
+ * 
+ *         if fnum != self.cols_num:             # <<<<<<<<<<<<<<
+ *             raise exceptions.ProtocolError(
+ *                 'the number of columns in the result row ({}) is '
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":267
+ *                     fnum, self.cols_num))
+ * 
+ *         dec_row = record.ApgRecord_New(self.cols_desc, fnum)             # <<<<<<<<<<<<<<
+ *         for i in range(fnum):
+ *             flen = hton.unpack_int32(frb_read(&rbuf, 4))
+ */
+  __pyx_t_1 = __pyx_v_self->cols_desc;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_t_5 = ApgRecord_New(__pyx_t_1, __pyx_v_fnum); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 267, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v_dec_row = __pyx_t_5;
+  __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":268
+ * 
+ *         dec_row = record.ApgRecord_New(self.cols_desc, fnum)
+ *         for i in range(fnum):             # <<<<<<<<<<<<<<
+ *             flen = hton.unpack_int32(frb_read(&rbuf, 4))
+ * 
+ */
+  __pyx_t_12 = __pyx_v_fnum;
+  __pyx_t_13 = __pyx_t_12;
+  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
+    __pyx_v_i = __pyx_t_14;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":269
+ *         dec_row = record.ApgRecord_New(self.cols_desc, fnum)
+ *         for i in range(fnum):
+ *             flen = hton.unpack_int32(frb_read(&rbuf, 4))             # <<<<<<<<<<<<<<
+ * 
+ *             if flen == -1:
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read((&__pyx_v_rbuf), 4); if (unlikely(__pyx_t_2 == ((char const *)NULL))) __PYX_ERR(6, 269, __pyx_L1_error)
+    __pyx_v_flen = unpack_int32(__pyx_t_2);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":271
+ *             flen = hton.unpack_int32(frb_read(&rbuf, 4))
+ * 
+ *             if flen == -1:             # <<<<<<<<<<<<<<
+ *                 val = None
+ *             else:
+ */
+    __pyx_t_3 = ((__pyx_v_flen == -1L) != 0);
+    if (__pyx_t_3) {
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":272
+ * 
+ *             if flen == -1:
+ *                 val = None             # <<<<<<<<<<<<<<
+ *             else:
+ *                 # Clamp buffer size to that of the reported field length
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_XDECREF_SET(__pyx_v_val, Py_None);
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":271
+ *             flen = hton.unpack_int32(frb_read(&rbuf, 4))
+ * 
+ *             if flen == -1:             # <<<<<<<<<<<<<<
+ *                 val = None
+ *             else:
+ */
+      goto __pyx_L6;
+    }
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":277
+ *                 # to make sure that codecs can rely on read_all() working
+ *                 # properly.
+ *                 bl = frb_get_len(&rbuf)             # <<<<<<<<<<<<<<
+ *                 if flen > bl:
+ *                     frb_check(&rbuf, flen)
+ */
+    /*else*/ {
+      __pyx_v_bl = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len((&__pyx_v_rbuf));
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":278
+ *                 # properly.
+ *                 bl = frb_get_len(&rbuf)
+ *                 if flen > bl:             # <<<<<<<<<<<<<<
+ *                     frb_check(&rbuf, flen)
+ *                 frb_set_len(&rbuf, flen)
+ */
+      __pyx_t_3 = ((__pyx_v_flen > __pyx_v_bl) != 0);
+      if (__pyx_t_3) {
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":279
+ *                 bl = frb_get_len(&rbuf)
+ *                 if flen > bl:
+ *                     frb_check(&rbuf, flen)             # <<<<<<<<<<<<<<
+ *                 frb_set_len(&rbuf, flen)
+ *                 codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)
+ */
+        __pyx_t_5 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_check((&__pyx_v_rbuf), __pyx_v_flen); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 279, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":278
+ *                 # properly.
+ *                 bl = frb_get_len(&rbuf)
+ *                 if flen > bl:             # <<<<<<<<<<<<<<
+ *                     frb_check(&rbuf, flen)
+ *                 frb_set_len(&rbuf, flen)
+ */
+      }
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":280
+ *                 if flen > bl:
+ *                     frb_check(&rbuf, flen)
+ *                 frb_set_len(&rbuf, flen)             # <<<<<<<<<<<<<<
+ *                 codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)
+ *                 val = codec.decode(settings, &rbuf)
+ */
+      __pyx_f_7asyncpg_7pgproto_7pgproto_frb_set_len((&__pyx_v_rbuf), __pyx_v_flen);
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":281
+ *                     frb_check(&rbuf, flen)
+ *                 frb_set_len(&rbuf, flen)
+ *                 codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)             # <<<<<<<<<<<<<<
+ *                 val = codec.decode(settings, &rbuf)
+ *                 if frb_get_len(&rbuf) != 0:
+ */
+      __pyx_t_15 = PyTuple_GET_ITEM(__pyx_v_rows_codecs, __pyx_v_i);
+      __pyx_t_5 = ((PyObject *)__pyx_t_15);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_XDECREF_SET(__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_5));
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":282
+ *                 frb_set_len(&rbuf, flen)
+ *                 codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)
+ *                 val = codec.decode(settings, &rbuf)             # <<<<<<<<<<<<<<
+ *                 if frb_get_len(&rbuf) != 0:
+ *                     raise BufferError(
+ */
+      __pyx_t_5 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode(__pyx_v_codec, __pyx_v_settings, (&__pyx_v_rbuf)); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 282, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_5);
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":283
+ *                 codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)
+ *                 val = codec.decode(settings, &rbuf)
+ *                 if frb_get_len(&rbuf) != 0:             # <<<<<<<<<<<<<<
+ *                     raise BufferError(
+ *                         'unexpected trailing {} bytes in buffer'.format(
+ */
+      __pyx_t_3 = ((__pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len((&__pyx_v_rbuf)) != 0) != 0);
+      if (unlikely(__pyx_t_3)) {
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":285
+ *                 if frb_get_len(&rbuf) != 0:
+ *                     raise BufferError(
+ *                         'unexpected trailing {} bytes in buffer'.format(             # <<<<<<<<<<<<<<
+ *                             frb_get_len(&rbuf)))
+ *                 frb_set_len(&rbuf, bl - flen)
+ */
+        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_trailing_bytes_in_buf, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 285, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_1);
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":286
+ *                     raise BufferError(
+ *                         'unexpected trailing {} bytes in buffer'.format(
+ *                             frb_get_len(&rbuf)))             # <<<<<<<<<<<<<<
+ *                 frb_set_len(&rbuf, bl - flen)
+ * 
+ */
+        __pyx_t_4 = PyInt_FromSsize_t(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len((&__pyx_v_rbuf))); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 286, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_6 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
+          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
+          if (likely(__pyx_t_6)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
+            __Pyx_INCREF(__pyx_t_6);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_1, function);
+          }
+        }
+        __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4);
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 285, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":284
+ *                 val = codec.decode(settings, &rbuf)
+ *                 if frb_get_len(&rbuf) != 0:
+ *                     raise BufferError(             # <<<<<<<<<<<<<<
+ *                         'unexpected trailing {} bytes in buffer'.format(
+ *                             frb_get_len(&rbuf)))
+ */
+        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_BufferError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 284, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+        __PYX_ERR(6, 284, __pyx_L1_error)
+
+        /* "asyncpg/protocol/prepared_stmt.pyx":283
+ *                 codec = <Codec>cpython.PyTuple_GET_ITEM(rows_codecs, i)
+ *                 val = codec.decode(settings, &rbuf)
+ *                 if frb_get_len(&rbuf) != 0:             # <<<<<<<<<<<<<<
+ *                     raise BufferError(
+ *                         'unexpected trailing {} bytes in buffer'.format(
+ */
+      }
+
+      /* "asyncpg/protocol/prepared_stmt.pyx":287
+ *                         'unexpected trailing {} bytes in buffer'.format(
+ *                             frb_get_len(&rbuf)))
+ *                 frb_set_len(&rbuf, bl - flen)             # <<<<<<<<<<<<<<
+ * 
+ *             cpython.Py_INCREF(val)
+ */
+      __pyx_f_7asyncpg_7pgproto_7pgproto_frb_set_len((&__pyx_v_rbuf), (__pyx_v_bl - __pyx_v_flen));
+    }
+    __pyx_L6:;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":289
+ *                 frb_set_len(&rbuf, bl - flen)
+ * 
+ *             cpython.Py_INCREF(val)             # <<<<<<<<<<<<<<
+ *             record.ApgRecord_SET_ITEM(dec_row, i, val)
+ * 
+ */
+    Py_INCREF(__pyx_v_val);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":290
+ * 
+ *             cpython.Py_INCREF(val)
+ *             record.ApgRecord_SET_ITEM(dec_row, i, val)             # <<<<<<<<<<<<<<
+ * 
+ *         if frb_get_len(&rbuf) != 0:
+ */
+    ApgRecord_SET_ITEM(__pyx_v_dec_row, __pyx_v_i, __pyx_v_val);
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":292
+ *             record.ApgRecord_SET_ITEM(dec_row, i, val)
+ * 
+ *         if frb_get_len(&rbuf) != 0:             # <<<<<<<<<<<<<<
+ *             raise BufferError('unexpected trailing {} bytes in buffer'.format(
+ *                 frb_get_len(&rbuf)))
+ */
+  __pyx_t_3 = ((__pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len((&__pyx_v_rbuf)) != 0) != 0);
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":293
+ * 
+ *         if frb_get_len(&rbuf) != 0:
+ *             raise BufferError('unexpected trailing {} bytes in buffer'.format(             # <<<<<<<<<<<<<<
+ *                 frb_get_len(&rbuf)))
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unexpected_trailing_bytes_in_buf, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 293, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":294
+ *         if frb_get_len(&rbuf) != 0:
+ *             raise BufferError('unexpected trailing {} bytes in buffer'.format(
+ *                 frb_get_len(&rbuf)))             # <<<<<<<<<<<<<<
+ * 
+ *         return dec_row
+ */
+    __pyx_t_4 = PyInt_FromSsize_t(__pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len((&__pyx_v_rbuf))); if (unlikely(!__pyx_t_4)) __PYX_ERR(6, 294, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 293, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":293
+ * 
+ *         if frb_get_len(&rbuf) != 0:
+ *             raise BufferError('unexpected trailing {} bytes in buffer'.format(             # <<<<<<<<<<<<<<
+ *                 frb_get_len(&rbuf)))
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_BufferError, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 293, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __PYX_ERR(6, 293, __pyx_L1_error)
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":292
+ *             record.ApgRecord_SET_ITEM(dec_row, i, val)
+ * 
+ *         if frb_get_len(&rbuf) != 0:             # <<<<<<<<<<<<<<
+ *             raise BufferError('unexpected trailing {} bytes in buffer'.format(
+ *                 frb_get_len(&rbuf)))
+ */
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":296
+ *                 frb_get_len(&rbuf)))
+ * 
+ *         return dec_row             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_dec_row);
+  __pyx_r = __pyx_v_dec_row;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":245
+ *         self.args_num = <int16_t>(len(self.parameters_desc))
+ * 
+ *     cdef _decode_row(self, const char* cbuf, ssize_t buf_len):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec codec
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState._decode_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_codec);
+  __Pyx_XDECREF(__pyx_v_dec_row);
+  __Pyx_XDECREF(__pyx_v_rows_codecs);
+  __Pyx_XDECREF((PyObject *)__pyx_v_settings);
+  __Pyx_XDECREF(__pyx_v_val);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pxd":10
+ * cdef class PreparedStatementState:
+ *     cdef:
+ *         readonly str name             # <<<<<<<<<<<<<<
+ *         readonly str query
+ *         readonly bint closed
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_4name_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_4name_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4name___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4name___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->name);
+  __pyx_r = __pyx_v_self->name;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pxd":11
+ *     cdef:
+ *         readonly str name
+ *         readonly str query             # <<<<<<<<<<<<<<
+ *         readonly bint closed
+ *         readonly int refs
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_5query_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_5query_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_5query___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_5query___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->query);
+  __pyx_r = __pyx_v_self->query;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pxd":12
+ *         readonly str name
+ *         readonly str query
+ *         readonly bint closed             # <<<<<<<<<<<<<<
+ *         readonly int refs
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_6closed_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_6closed_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_6closed___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_6closed___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->closed); if (unlikely(!__pyx_t_1)) __PYX_ERR(12, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState.closed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pxd":13
+ *         readonly str query
+ *         readonly bint closed
+ *         readonly int refs             # <<<<<<<<<<<<<<
+ * 
+ *         list         row_desc
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_4refs_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_4refs_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4refs___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_4refs___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->refs); if (unlikely(!__pyx_t_1)) __PYX_ERR(12, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState.refs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_16__reduce_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_16__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 2, __pyx_L1_error)
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_18__setstate_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_22PreparedStatementState_18__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __PYX_ERR(2, 4, __pyx_L1_error)
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.PreparedStatementState.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":299
+ * 
+ * 
+ * cdef _decode_parameters_desc(object desc):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ReadBuffer reader
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__decode_parameters_desc(PyObject *__pyx_v_desc) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_reader = 0;
+  int16_t __pyx_v_nparams;
+  uint32_t __pyx_v_p_oid;
+  PyObject *__pyx_v_result = 0;
+  CYTHON_UNUSED long __pyx_v_i;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int16_t __pyx_t_2;
+  int32_t __pyx_t_3;
+  int __pyx_t_4;
+  __Pyx_RefNannySetupContext("_decode_parameters_desc", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":304
+ *         int16_t nparams
+ *         uint32_t p_oid
+ *         list result = []             # <<<<<<<<<<<<<<
+ * 
+ *     reader = ReadBuffer.new_message_parser(desc)
+ */
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 304, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_result = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":306
+ *         list result = []
+ * 
+ *     reader = ReadBuffer.new_message_parser(desc)             # <<<<<<<<<<<<<<
+ *     nparams = reader.read_int16()
+ * 
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer->new_message_parser(__pyx_v_desc)); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 306, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_reader = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":307
+ * 
+ *     reader = ReadBuffer.new_message_parser(desc)
+ *     nparams = reader.read_int16()             # <<<<<<<<<<<<<<
+ * 
+ *     for i from 0 <= i < nparams:
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int16(__pyx_v_reader); if (unlikely(__pyx_t_2 == ((int16_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 307, __pyx_L1_error)
+  __pyx_v_nparams = __pyx_t_2;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":309
+ *     nparams = reader.read_int16()
+ * 
+ *     for i from 0 <= i < nparams:             # <<<<<<<<<<<<<<
+ *         p_oid = <uint32_t>reader.read_int32()
+ *         result.append(p_oid)
+ */
+  __pyx_t_2 = __pyx_v_nparams;
+  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":310
+ * 
+ *     for i from 0 <= i < nparams:
+ *         p_oid = <uint32_t>reader.read_int32()             # <<<<<<<<<<<<<<
+ *         result.append(p_oid)
+ * 
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int32(__pyx_v_reader); if (unlikely(__pyx_t_3 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 310, __pyx_L1_error)
+    __pyx_v_p_oid = ((uint32_t)__pyx_t_3);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":311
+ *     for i from 0 <= i < nparams:
+ *         p_oid = <uint32_t>reader.read_int32()
+ *         result.append(p_oid)             # <<<<<<<<<<<<<<
+ * 
+ *     return result
+ */
+    __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_p_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 311, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(6, 311, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":313
+ *         result.append(p_oid)
+ * 
+ *     return result             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":299
+ * 
+ * 
+ * cdef _decode_parameters_desc(object desc):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ReadBuffer reader
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._decode_parameters_desc", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_reader);
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/prepared_stmt.pyx":316
+ * 
+ * 
+ * cdef _decode_row_desc(object desc):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ReadBuffer reader
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol__decode_row_desc(PyObject *__pyx_v_desc) {
+  struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_reader = 0;
+  int16_t __pyx_v_nfields;
+  PyObject *__pyx_v_f_name = 0;
+  uint32_t __pyx_v_f_table_oid;
+  int16_t __pyx_v_f_column_num;
+  uint32_t __pyx_v_f_dt_oid;
+  int16_t __pyx_v_f_dt_size;
+  int32_t __pyx_v_f_dt_mod;
+  int16_t __pyx_v_f_format;
+  PyObject *__pyx_v_result = 0;
+  CYTHON_UNUSED long __pyx_v_i;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int16_t __pyx_t_2;
+  int32_t __pyx_t_3;
+  int16_t __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  int __pyx_t_11;
+  __Pyx_RefNannySetupContext("_decode_row_desc", 0);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":332
+ *         list result
+ * 
+ *     reader = ReadBuffer.new_message_parser(desc)             # <<<<<<<<<<<<<<
+ *     nfields = reader.read_int16()
+ *     result = []
+ */
+  __pyx_t_1 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer->new_message_parser(__pyx_v_desc)); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 332, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_reader = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":333
+ * 
+ *     reader = ReadBuffer.new_message_parser(desc)
+ *     nfields = reader.read_int16()             # <<<<<<<<<<<<<<
+ *     result = []
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int16(__pyx_v_reader); if (unlikely(__pyx_t_2 == ((int16_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 333, __pyx_L1_error)
+  __pyx_v_nfields = __pyx_t_2;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":334
+ *     reader = ReadBuffer.new_message_parser(desc)
+ *     nfields = reader.read_int16()
+ *     result = []             # <<<<<<<<<<<<<<
+ * 
+ *     for i from 0 <= i < nfields:
+ */
+  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 334, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_result = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":336
+ *     result = []
+ * 
+ *     for i from 0 <= i < nfields:             # <<<<<<<<<<<<<<
+ *         f_name = reader.read_cstr()
+ *         f_table_oid = <uint32_t>reader.read_int32()
+ */
+  __pyx_t_2 = __pyx_v_nfields;
+  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":337
+ * 
+ *     for i from 0 <= i < nfields:
+ *         f_name = reader.read_cstr()             # <<<<<<<<<<<<<<
+ *         f_table_oid = <uint32_t>reader.read_int32()
+ *         f_column_num = reader.read_int16()
+ */
+    __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_cstr(__pyx_v_reader); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 337, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(6, 337, __pyx_L1_error)
+    __Pyx_XDECREF_SET(__pyx_v_f_name, ((PyObject*)__pyx_t_1));
+    __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":338
+ *     for i from 0 <= i < nfields:
+ *         f_name = reader.read_cstr()
+ *         f_table_oid = <uint32_t>reader.read_int32()             # <<<<<<<<<<<<<<
+ *         f_column_num = reader.read_int16()
+ *         f_dt_oid = <uint32_t>reader.read_int32()
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int32(__pyx_v_reader); if (unlikely(__pyx_t_3 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 338, __pyx_L1_error)
+    __pyx_v_f_table_oid = ((uint32_t)__pyx_t_3);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":339
+ *         f_name = reader.read_cstr()
+ *         f_table_oid = <uint32_t>reader.read_int32()
+ *         f_column_num = reader.read_int16()             # <<<<<<<<<<<<<<
+ *         f_dt_oid = <uint32_t>reader.read_int32()
+ *         f_dt_size = reader.read_int16()
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int16(__pyx_v_reader); if (unlikely(__pyx_t_4 == ((int16_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 339, __pyx_L1_error)
+    __pyx_v_f_column_num = __pyx_t_4;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":340
+ *         f_table_oid = <uint32_t>reader.read_int32()
+ *         f_column_num = reader.read_int16()
+ *         f_dt_oid = <uint32_t>reader.read_int32()             # <<<<<<<<<<<<<<
+ *         f_dt_size = reader.read_int16()
+ *         f_dt_mod = reader.read_int32()
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int32(__pyx_v_reader); if (unlikely(__pyx_t_3 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 340, __pyx_L1_error)
+    __pyx_v_f_dt_oid = ((uint32_t)__pyx_t_3);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":341
+ *         f_column_num = reader.read_int16()
+ *         f_dt_oid = <uint32_t>reader.read_int32()
+ *         f_dt_size = reader.read_int16()             # <<<<<<<<<<<<<<
+ *         f_dt_mod = reader.read_int32()
+ *         f_format = reader.read_int16()
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int16(__pyx_v_reader); if (unlikely(__pyx_t_4 == ((int16_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 341, __pyx_L1_error)
+    __pyx_v_f_dt_size = __pyx_t_4;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":342
+ *         f_dt_oid = <uint32_t>reader.read_int32()
+ *         f_dt_size = reader.read_int16()
+ *         f_dt_mod = reader.read_int32()             # <<<<<<<<<<<<<<
+ *         f_format = reader.read_int16()
+ * 
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int32(__pyx_v_reader); if (unlikely(__pyx_t_3 == ((int32_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 342, __pyx_L1_error)
+    __pyx_v_f_dt_mod = __pyx_t_3;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":343
+ *         f_dt_size = reader.read_int16()
+ *         f_dt_mod = reader.read_int32()
+ *         f_format = reader.read_int16()             # <<<<<<<<<<<<<<
+ * 
+ *         result.append(
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_reader->__pyx_vtab)->read_int16(__pyx_v_reader); if (unlikely(__pyx_t_4 == ((int16_t)-1) && PyErr_Occurred())) __PYX_ERR(6, 343, __pyx_L1_error)
+    __pyx_v_f_format = __pyx_t_4;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":346
+ * 
+ *         result.append(
+ *             (f_name, f_table_oid, f_column_num, f_dt_oid,             # <<<<<<<<<<<<<<
+ *              f_dt_size, f_dt_mod, f_format))
+ * 
+ */
+    __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_f_table_oid); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 346, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_5 = __Pyx_PyInt_From_int16_t(__pyx_v_f_column_num); if (unlikely(!__pyx_t_5)) __PYX_ERR(6, 346, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_f_dt_oid); if (unlikely(!__pyx_t_6)) __PYX_ERR(6, 346, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":347
+ *         result.append(
+ *             (f_name, f_table_oid, f_column_num, f_dt_oid,
+ *              f_dt_size, f_dt_mod, f_format))             # <<<<<<<<<<<<<<
+ * 
+ *     return result
+ */
+    __pyx_t_7 = __Pyx_PyInt_From_int16_t(__pyx_v_f_dt_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(6, 347, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = __Pyx_PyInt_From_int32_t(__pyx_v_f_dt_mod); if (unlikely(!__pyx_t_8)) __PYX_ERR(6, 347, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_9 = __Pyx_PyInt_From_int16_t(__pyx_v_f_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(6, 347, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_9);
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":346
+ * 
+ *         result.append(
+ *             (f_name, f_table_oid, f_column_num, f_dt_oid,             # <<<<<<<<<<<<<<
+ *              f_dt_size, f_dt_mod, f_format))
+ * 
+ */
+    __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) __PYX_ERR(6, 346, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_10);
+    __Pyx_INCREF(__pyx_v_f_name);
+    __Pyx_GIVEREF(__pyx_v_f_name);
+    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_f_name);
+    __Pyx_GIVEREF(__pyx_t_1);
+    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1);
+    __Pyx_GIVEREF(__pyx_t_5);
+    PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5);
+    __Pyx_GIVEREF(__pyx_t_6);
+    PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_7);
+    PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_7);
+    __Pyx_GIVEREF(__pyx_t_8);
+    PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_t_8);
+    __Pyx_GIVEREF(__pyx_t_9);
+    PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_9);
+    __pyx_t_1 = 0;
+    __pyx_t_5 = 0;
+    __pyx_t_6 = 0;
+    __pyx_t_7 = 0;
+    __pyx_t_8 = 0;
+    __pyx_t_9 = 0;
+
+    /* "asyncpg/protocol/prepared_stmt.pyx":345
+ *         f_format = reader.read_int16()
+ * 
+ *         result.append(             # <<<<<<<<<<<<<<
+ *             (f_name, f_table_oid, f_column_num, f_dt_oid,
+ *              f_dt_size, f_dt_mod, f_format))
+ */
+    __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(6, 345, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+  }
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":349
+ *              f_dt_size, f_dt_mod, f_format))
+ * 
+ *     return result             # <<<<<<<<<<<<<<
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_result);
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":316
+ * 
+ * 
+ * cdef _decode_row_desc(object desc):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         ReadBuffer reader
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._decode_row_desc", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF((PyObject *)__pyx_v_reader);
+  __Pyx_XDECREF(__pyx_v_f_name);
+  __Pyx_XDECREF(__pyx_v_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":76
+ * 
+ * cdef class BaseProtocol(CoreProtocol):
+ *     def __init__(self, addr, connected_fut, con_params, loop):             # <<<<<<<<<<<<<<
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         CoreProtocol.__init__(self, con_params)
+ */
+
+/* Python wrapper */
+static int __pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_addr = 0;
+  PyObject *__pyx_v_connected_fut = 0;
+  PyObject *__pyx_v_con_params = 0;
+  PyObject *__pyx_v_loop = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_addr,&__pyx_n_s_connected_fut,&__pyx_n_s_con_params,&__pyx_n_s_loop,0};
+    PyObject* values[4] = {0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_addr)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_connected_fut)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 1); __PYX_ERR(0, 76, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_con_params)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 2); __PYX_ERR(0, 76, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_loop)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 3); __PYX_ERR(0, 76, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 76, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+    }
+    __pyx_v_addr = values[0];
+    __pyx_v_connected_fut = values[1];
+    __pyx_v_con_params = values[2];
+    __pyx_v_loop = values[3];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 76, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol___init__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_addr, __pyx_v_connected_fut, __pyx_v_con_params, __pyx_v_loop);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol___init__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_addr, PyObject *__pyx_v_connected_fut, PyObject *__pyx_v_con_params, PyObject *__pyx_v_loop) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("__init__", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":78
+ *     def __init__(self, addr, connected_fut, con_params, loop):
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         CoreProtocol.__init__(self, con_params)             # <<<<<<<<<<<<<<
+ * 
+ *         self.loop = loop
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_CoreProtocol), __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  __pyx_t_4 = 0;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+      __pyx_t_4 = 1;
+    }
+  }
+  #if CYTHON_FAST_PYCALL
+  if (PyFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_v_con_params};
+    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+  } else
+  #endif
+  #if CYTHON_FAST_PYCCALL
+  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
+    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_v_con_params};
+    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_GOTREF(__pyx_t_1);
+  } else
+  #endif
+  {
+    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    if (__pyx_t_3) {
+      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
+    }
+    __Pyx_INCREF(((PyObject *)__pyx_v_self));
+    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
+    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_self));
+    __Pyx_INCREF(__pyx_v_con_params);
+    __Pyx_GIVEREF(__pyx_v_con_params);
+    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_con_params);
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":80
+ *         CoreProtocol.__init__(self, con_params)
+ * 
+ *         self.loop = loop             # <<<<<<<<<<<<<<
+ *         self.transport = None
+ *         self.waiter = connected_fut
+ */
+  __Pyx_INCREF(__pyx_v_loop);
+  __Pyx_GIVEREF(__pyx_v_loop);
+  __Pyx_GOTREF(__pyx_v_self->loop);
+  __Pyx_DECREF(__pyx_v_self->loop);
+  __pyx_v_self->loop = __pyx_v_loop;
+
+  /* "asyncpg/protocol/protocol.pyx":81
+ * 
+ *         self.loop = loop
+ *         self.transport = None             # <<<<<<<<<<<<<<
+ *         self.waiter = connected_fut
+ *         self.cancel_waiter = None
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->__pyx_base.transport);
+  __Pyx_DECREF(__pyx_v_self->__pyx_base.transport);
+  __pyx_v_self->__pyx_base.transport = Py_None;
+
+  /* "asyncpg/protocol/protocol.pyx":82
+ *         self.loop = loop
+ *         self.transport = None
+ *         self.waiter = connected_fut             # <<<<<<<<<<<<<<
+ *         self.cancel_waiter = None
+ *         self.cancel_sent_waiter = None
+ */
+  __Pyx_INCREF(__pyx_v_connected_fut);
+  __Pyx_GIVEREF(__pyx_v_connected_fut);
+  __Pyx_GOTREF(__pyx_v_self->waiter);
+  __Pyx_DECREF(__pyx_v_self->waiter);
+  __pyx_v_self->waiter = __pyx_v_connected_fut;
+
+  /* "asyncpg/protocol/protocol.pyx":83
+ *         self.transport = None
+ *         self.waiter = connected_fut
+ *         self.cancel_waiter = None             # <<<<<<<<<<<<<<
+ *         self.cancel_sent_waiter = None
+ * 
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->cancel_waiter);
+  __Pyx_DECREF(__pyx_v_self->cancel_waiter);
+  __pyx_v_self->cancel_waiter = Py_None;
+
+  /* "asyncpg/protocol/protocol.pyx":84
+ *         self.waiter = connected_fut
+ *         self.cancel_waiter = None
+ *         self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self.address = addr
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->cancel_sent_waiter);
+  __Pyx_DECREF(__pyx_v_self->cancel_sent_waiter);
+  __pyx_v_self->cancel_sent_waiter = Py_None;
+
+  /* "asyncpg/protocol/protocol.pyx":86
+ *         self.cancel_sent_waiter = None
+ * 
+ *         self.address = addr             # <<<<<<<<<<<<<<
+ *         self.settings = ConnectionSettings((self.address, con_params.database))
+ * 
+ */
+  __Pyx_INCREF(__pyx_v_addr);
+  __Pyx_GIVEREF(__pyx_v_addr);
+  __Pyx_GOTREF(__pyx_v_self->address);
+  __Pyx_DECREF(__pyx_v_self->address);
+  __pyx_v_self->address = __pyx_v_addr;
+
+  /* "asyncpg/protocol/protocol.pyx":87
+ * 
+ *         self.address = addr
+ *         self.settings = ConnectionSettings((self.address, con_params.database))             # <<<<<<<<<<<<<<
+ * 
+ *         self.statement = None
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_con_params, __pyx_n_s_database); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_v_self->address);
+  __Pyx_GIVEREF(__pyx_v_self->address);
+  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self->address);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
+  __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_ConnectionSettings), __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->settings);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->settings));
+  __pyx_v_self->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":89
+ *         self.settings = ConnectionSettings((self.address, con_params.database))
+ * 
+ *         self.statement = None             # <<<<<<<<<<<<<<
+ *         self.return_extra = False
+ * 
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->statement);
+  __Pyx_DECREF(((PyObject *)__pyx_v_self->statement));
+  __pyx_v_self->statement = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)Py_None);
+
+  /* "asyncpg/protocol/protocol.pyx":90
+ * 
+ *         self.statement = None
+ *         self.return_extra = False             # <<<<<<<<<<<<<<
+ * 
+ *         self.last_query = None
+ */
+  __pyx_v_self->return_extra = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":92
+ *         self.return_extra = False
+ * 
+ *         self.last_query = None             # <<<<<<<<<<<<<<
+ * 
+ *         self.closing = False
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->last_query);
+  __Pyx_DECREF(__pyx_v_self->last_query);
+  __pyx_v_self->last_query = ((PyObject*)Py_None);
+
+  /* "asyncpg/protocol/protocol.pyx":94
+ *         self.last_query = None
+ * 
+ *         self.closing = False             # <<<<<<<<<<<<<<
+ *         self.is_reading = True
+ *         self.writing_allowed = asyncio.Event(loop=self.loop)
+ */
+  __pyx_v_self->closing = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":95
+ * 
+ *         self.closing = False
+ *         self.is_reading = True             # <<<<<<<<<<<<<<
+ *         self.writing_allowed = asyncio.Event(loop=self.loop)
+ *         self.writing_allowed.set()
+ */
+  __pyx_v_self->is_reading = 1;
+
+  /* "asyncpg/protocol/protocol.pyx":96
+ *         self.closing = False
+ *         self.is_reading = True
+ *         self.writing_allowed = asyncio.Event(loop=self.loop)             # <<<<<<<<<<<<<<
+ *         self.writing_allowed.set()
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Event); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_loop, __pyx_v_self->loop) < 0) __PYX_ERR(0, 96, __pyx_L1_error)
+  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_writing_allowed, __pyx_t_5) < 0) __PYX_ERR(0, 96, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":97
+ *         self.is_reading = True
+ *         self.writing_allowed = asyncio.Event(loop=self.loop)
+ *         self.writing_allowed.set()             # <<<<<<<<<<<<<<
+ * 
+ *         self.timeout_handle = None
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_writing_allowed); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_set); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_1)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_1);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 97, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":99
+ *         self.writing_allowed.set()
+ * 
+ *         self.timeout_handle = None             # <<<<<<<<<<<<<<
+ *         self.timeout_callback = self._on_timeout
+ *         self.completed_callback = self._on_waiter_completed
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->timeout_handle);
+  __Pyx_DECREF(__pyx_v_self->timeout_handle);
+  __pyx_v_self->timeout_handle = Py_None;
+
+  /* "asyncpg/protocol/protocol.pyx":100
+ * 
+ *         self.timeout_handle = None
+ *         self.timeout_callback = self._on_timeout             # <<<<<<<<<<<<<<
+ *         self.completed_callback = self._on_waiter_completed
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_on_timeout); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 100, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_GIVEREF(__pyx_t_5);
+  __Pyx_GOTREF(__pyx_v_self->timeout_callback);
+  __Pyx_DECREF(__pyx_v_self->timeout_callback);
+  __pyx_v_self->timeout_callback = __pyx_t_5;
+  __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":101
+ *         self.timeout_handle = None
+ *         self.timeout_callback = self._on_timeout
+ *         self.completed_callback = self._on_waiter_completed             # <<<<<<<<<<<<<<
+ * 
+ *         self.queries_count = 0
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_on_waiter_completed); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 101, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_GIVEREF(__pyx_t_5);
+  __Pyx_GOTREF(__pyx_v_self->completed_callback);
+  __Pyx_DECREF(__pyx_v_self->completed_callback);
+  __pyx_v_self->completed_callback = __pyx_t_5;
+  __pyx_t_5 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":103
+ *         self.completed_callback = self._on_waiter_completed
+ * 
+ *         self.queries_count = 0             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+  __pyx_v_self->queries_count = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":105
+ *         self.queries_count = 0
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self.create_future = loop.create_future
+ *         except AttributeError:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
+    __Pyx_XGOTREF(__pyx_t_6);
+    __Pyx_XGOTREF(__pyx_t_7);
+    __Pyx_XGOTREF(__pyx_t_8);
+    /*try:*/ {
+
+      /* "asyncpg/protocol/protocol.pyx":106
+ * 
+ *         try:
+ *             self.create_future = loop.create_future             # <<<<<<<<<<<<<<
+ *         except AttributeError:
+ *             self.create_future = self._create_future_fallback
+ */
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_loop, __pyx_n_s_create_future); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 106, __pyx_L3_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GIVEREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_v_self->create_future);
+      __Pyx_DECREF(__pyx_v_self->create_future);
+      __pyx_v_self->create_future = __pyx_t_5;
+      __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":105
+ *         self.queries_count = 0
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self.create_future = loop.create_future
+ *         except AttributeError:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    goto __pyx_L8_try_end;
+    __pyx_L3_error:;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":107
+ *         try:
+ *             self.create_future = loop.create_future
+ *         except AttributeError:             # <<<<<<<<<<<<<<
+ *             self.create_future = self._create_future_fallback
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
+    if (__pyx_t_4) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_2, &__pyx_t_1) < 0) __PYX_ERR(0, 107, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_GOTREF(__pyx_t_1);
+
+      /* "asyncpg/protocol/protocol.pyx":108
+ *             self.create_future = loop.create_future
+ *         except AttributeError:
+ *             self.create_future = self._create_future_fallback             # <<<<<<<<<<<<<<
+ * 
+ *     def set_connection(self, connection):
+ */
+      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_create_future_fallback); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 108, __pyx_L5_except_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_GIVEREF(__pyx_t_3);
+      __Pyx_GOTREF(__pyx_v_self->create_future);
+      __Pyx_DECREF(__pyx_v_self->create_future);
+      __pyx_v_self->create_future = __pyx_t_3;
+      __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      goto __pyx_L4_exception_handled;
+    }
+    goto __pyx_L5_except_error;
+    __pyx_L5_except_error:;
+
+    /* "asyncpg/protocol/protocol.pyx":105
+ *         self.queries_count = 0
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self.create_future = loop.create_future
+ *         except AttributeError:
+ */
+    __Pyx_XGIVEREF(__pyx_t_6);
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+    goto __pyx_L1_error;
+    __pyx_L4_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_6);
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+    __pyx_L8_try_end:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":76
+ * 
+ * cdef class BaseProtocol(CoreProtocol):
+ *     def __init__(self, addr, connected_fut, con_params, loop):             # <<<<<<<<<<<<<<
+ *         # type of `con_params` is `_ConnectionParameters`
+ *         CoreProtocol.__init__(self, con_params)
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":110
+ *             self.create_future = self._create_future_fallback
+ * 
+ *     def set_connection(self, connection):             # <<<<<<<<<<<<<<
+ *         self.conref = weakref.ref(connection)
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_3set_connection(PyObject *__pyx_v_self, PyObject *__pyx_v_connection); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_3set_connection(PyObject *__pyx_v_self, PyObject *__pyx_v_connection) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("set_connection (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_2set_connection(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_connection));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_2set_connection(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_connection) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("set_connection", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":111
+ * 
+ *     def set_connection(self, connection):
+ *         self.conref = weakref.ref(connection)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef get_connection(self):
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_weakref); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ref); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_connection) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_connection);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->conref);
+  __Pyx_DECREF(__pyx_v_self->conref);
+  __pyx_v_self->conref = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":110
+ *             self.create_future = self._create_future_fallback
+ * 
+ *     def set_connection(self, connection):             # <<<<<<<<<<<<<<
+ *         self.conref = weakref.ref(connection)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.set_connection", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":113
+ *         self.conref = weakref.ref(connection)
+ * 
+ *     cdef get_connection(self):             # <<<<<<<<<<<<<<
+ *         if self.conref is not None:
+ *             return self.conref()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_get_connection(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("get_connection", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":114
+ * 
+ *     cdef get_connection(self):
+ *         if self.conref is not None:             # <<<<<<<<<<<<<<
+ *             return self.conref()
+ *         else:
+ */
+  __pyx_t_1 = (__pyx_v_self->conref != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":115
+ *     cdef get_connection(self):
+ *         if self.conref is not None:
+ *             return self.conref()             # <<<<<<<<<<<<<<
+ *         else:
+ *             return None
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_INCREF(__pyx_v_self->conref);
+    __pyx_t_4 = __pyx_v_self->conref; __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 115, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_r = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":114
+ * 
+ *     cdef get_connection(self):
+ *         if self.conref is not None:             # <<<<<<<<<<<<<<
+ *             return self.conref()
+ *         else:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":117
+ *             return self.conref()
+ *         else:
+ *             return None             # <<<<<<<<<<<<<<
+ * 
+ *     def get_server_pid(self):
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":113
+ *         self.conref = weakref.ref(connection)
+ * 
+ *     cdef get_connection(self):             # <<<<<<<<<<<<<<
+ *         if self.conref is not None:
+ *             return self.conref()
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.get_connection", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":119
+ *             return None
+ * 
+ *     def get_server_pid(self):             # <<<<<<<<<<<<<<
+ *         return self.backend_pid
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_5get_server_pid(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_5get_server_pid(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_server_pid (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_4get_server_pid(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_4get_server_pid(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("get_server_pid", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":120
+ * 
+ *     def get_server_pid(self):
+ *         return self.backend_pid             # <<<<<<<<<<<<<<
+ * 
+ *     def get_settings(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->__pyx_base.backend_pid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":119
+ *             return None
+ * 
+ *     def get_server_pid(self):             # <<<<<<<<<<<<<<
+ *         return self.backend_pid
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.get_server_pid", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":122
+ *         return self.backend_pid
+ * 
+ *     def get_settings(self):             # <<<<<<<<<<<<<<
+ *         return self.settings
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_7get_settings(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_7get_settings(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_settings (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_6get_settings(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_6get_settings(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_settings", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":123
+ * 
+ *     def get_settings(self):
+ *         return self.settings             # <<<<<<<<<<<<<<
+ * 
+ *     def is_in_transaction(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(((PyObject *)__pyx_v_self->settings));
+  __pyx_r = ((PyObject *)__pyx_v_self->settings);
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":122
+ *         return self.backend_pid
+ * 
+ *     def get_settings(self):             # <<<<<<<<<<<<<<
+ *         return self.settings
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":125
+ *         return self.settings
+ * 
+ *     def is_in_transaction(self):             # <<<<<<<<<<<<<<
+ *         # PQTRANS_INTRANS = idle, within transaction block
+ *         # PQTRANS_INERROR = idle, within failed transaction
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_9is_in_transaction(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_9is_in_transaction(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("is_in_transaction (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_8is_in_transaction(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_8is_in_transaction(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  __Pyx_RefNannySetupContext("is_in_transaction", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":128
+ *         # PQTRANS_INTRANS = idle, within transaction block
+ *         # PQTRANS_INERROR = idle, within failed transaction
+ *         return self.xact_status in (PQTRANS_INTRANS, PQTRANS_INERROR)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline resume_reading(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  switch (__pyx_v_self->__pyx_base.xact_status) {
+    case __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_INTRANS:
+    case __pyx_e_7asyncpg_8protocol_8protocol_PQTRANS_INERROR:
+    __pyx_t_1 = 1;
+    break;
+    default:
+    __pyx_t_1 = 0;
+    break;
+  }
+  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":125
+ *         return self.settings
+ * 
+ *     def is_in_transaction(self):             # <<<<<<<<<<<<<<
+ *         # PQTRANS_INTRANS = idle, within transaction block
+ *         # PQTRANS_INERROR = idle, within failed transaction
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.is_in_transaction", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":130
+ *         return self.xact_status in (PQTRANS_INTRANS, PQTRANS_INERROR)
+ * 
+ *     cdef inline resume_reading(self):             # <<<<<<<<<<<<<<
+ *         if not self.is_reading:
+ *             self.is_reading = True
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("resume_reading", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":131
+ * 
+ *     cdef inline resume_reading(self):
+ *         if not self.is_reading:             # <<<<<<<<<<<<<<
+ *             self.is_reading = True
+ *             self.transport.resume_reading()
+ */
+  __pyx_t_1 = ((!(__pyx_v_self->is_reading != 0)) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":132
+ *     cdef inline resume_reading(self):
+ *         if not self.is_reading:
+ *             self.is_reading = True             # <<<<<<<<<<<<<<
+ *             self.transport.resume_reading()
+ * 
+ */
+    __pyx_v_self->is_reading = 1;
+
+    /* "asyncpg/protocol/protocol.pyx":133
+ *         if not self.is_reading:
+ *             self.is_reading = True
+ *             self.transport.resume_reading()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline pause_reading(self):
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.transport, __pyx_n_s_resume_reading); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":131
+ * 
+ *     cdef inline resume_reading(self):
+ *         if not self.is_reading:             # <<<<<<<<<<<<<<
+ *             self.is_reading = True
+ *             self.transport.resume_reading()
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":130
+ *         return self.xact_status in (PQTRANS_INTRANS, PQTRANS_INERROR)
+ * 
+ *     cdef inline resume_reading(self):             # <<<<<<<<<<<<<<
+ *         if not self.is_reading:
+ *             self.is_reading = True
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.resume_reading", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":135
+ *             self.transport.resume_reading()
+ * 
+ *     cdef inline pause_reading(self):             # <<<<<<<<<<<<<<
+ *         if self.is_reading:
+ *             self.is_reading = False
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_pause_reading(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("pause_reading", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":136
+ * 
+ *     cdef inline pause_reading(self):
+ *         if self.is_reading:             # <<<<<<<<<<<<<<
+ *             self.is_reading = False
+ *             self.transport.pause_reading()
+ */
+  __pyx_t_1 = (__pyx_v_self->is_reading != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":137
+ *     cdef inline pause_reading(self):
+ *         if self.is_reading:
+ *             self.is_reading = False             # <<<<<<<<<<<<<<
+ *             self.transport.pause_reading()
+ * 
+ */
+    __pyx_v_self->is_reading = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":138
+ *         if self.is_reading:
+ *             self.is_reading = False
+ *             self.transport.pause_reading()             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.transport, __pyx_n_s_pause_reading); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 138, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":136
+ * 
+ *     cdef inline pause_reading(self):
+ *         if self.is_reading:             # <<<<<<<<<<<<<<
+ *             self.is_reading = False
+ *             self.transport.pause_reading()
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":135
+ *             self.transport.resume_reading()
+ * 
+ *     cdef inline pause_reading(self):             # <<<<<<<<<<<<<<
+ *         if self.is_reading:
+ *             self.is_reading = False
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.pause_reading", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_12generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":141
+ * 
+ *     @cython.iterable_coroutine
+ *     async def prepare(self, stmt_name, query, timeout,             # <<<<<<<<<<<<<<
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_11prepare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_11prepare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_stmt_name = 0;
+  PyObject *__pyx_v_query = 0;
+  PyObject *__pyx_v_timeout = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("prepare (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_stmt_name,&__pyx_n_s_query,&__pyx_n_s_timeout,&__pyx_n_s_state,0};
+    PyObject* values[4] = {0,0,0,0};
+
+    /* "asyncpg/protocol/protocol.pyx":142
+ *     @cython.iterable_coroutine
+ *     async def prepare(self, stmt_name, query, timeout,
+ *                       PreparedStatementState state=None):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+    values[3] = (PyObject *)((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)Py_None);
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stmt_name)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("prepare", 0, 3, 4, 1); __PYX_ERR(0, 141, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("prepare", 0, 3, 4, 2); __PYX_ERR(0, 141, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (kw_args > 0) {
+          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_state);
+          if (value) { values[3] = value; kw_args--; }
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "prepare") < 0)) __PYX_ERR(0, 141, __pyx_L3_error)
+      }
+    } else {
+      switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+    }
+    __pyx_v_stmt_name = values[0];
+    __pyx_v_query = values[1];
+    __pyx_v_timeout = values[2];
+    __pyx_v_state = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[3]);
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("prepare", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 141, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "state", 0))) __PYX_ERR(0, 142, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_10prepare(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_stmt_name, __pyx_v_query, __pyx_v_timeout, __pyx_v_state);
+
+  /* "asyncpg/protocol/protocol.pyx":141
+ * 
+ *     @cython.iterable_coroutine
+ *     async def prepare(self, stmt_name, query, timeout,             # <<<<<<<<<<<<<<
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:
+ */
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_10prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_stmt_name, PyObject *__pyx_v_query, PyObject *__pyx_v_timeout, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("prepare", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 141, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_stmt_name = __pyx_v_stmt_name;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_stmt_name);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_stmt_name);
+  __pyx_cur_scope->__pyx_v_query = __pyx_v_query;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_query);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_query);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  __pyx_cur_scope->__pyx_v_state = __pyx_v_state;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_12generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_prepare, __pyx_n_s_BaseProtocol_prepare, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 141, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_12generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("prepare", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L29_resume_from_await;
+    case 4: goto __pyx_L32_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 141, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":143
+ *     async def prepare(self, stmt_name, query, timeout,
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":144
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 144, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 144, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":143
+ *     async def prepare(self, stmt_name, query, timeout,
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":145
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":146
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 146, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 146, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":147
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":145
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":149
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ *         timeout = self._get_timeout_impl(timeout)
+ * 
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":150
+ * 
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timeout)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 150, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":152
+ *         timeout = self._get_timeout_impl(timeout)
+ * 
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._prepare(stmt_name, query)  # network op
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":153
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._prepare(stmt_name, query)  # network op
+ *             self.last_query = query
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":154
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._prepare(stmt_name, query)  # network op             # <<<<<<<<<<<<<<
+ *             self.last_query = query
+ *             if state is None:
+ */
+        if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_stmt_name))||((__pyx_cur_scope->__pyx_v_stmt_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_stmt_name)->tp_name), 0))) __PYX_ERR(0, 154, __pyx_L11_error)
+        if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_query))||((__pyx_cur_scope->__pyx_v_query) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_query)->tp_name), 0))) __PYX_ERR(0, 154, __pyx_L11_error)
+        __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._prepare(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject*)__pyx_cur_scope->__pyx_v_stmt_name), ((PyObject*)__pyx_cur_scope->__pyx_v_query)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L11_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":155
+ *         try:
+ *             self._prepare(stmt_name, query)  # network op
+ *             self.last_query = query             # <<<<<<<<<<<<<<
+ *             if state is None:
+ *                 state = PreparedStatementState(stmt_name, query, self)
+ */
+        if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_query))||((__pyx_cur_scope->__pyx_v_query) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_query)->tp_name), 0))) __PYX_ERR(0, 155, __pyx_L11_error)
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_query;
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __pyx_cur_scope->__pyx_v_self->last_query = ((PyObject*)__pyx_t_3);
+        __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":156
+ *             self._prepare(stmt_name, query)  # network op
+ *             self.last_query = query
+ *             if state is None:             # <<<<<<<<<<<<<<
+ *                 state = PreparedStatementState(stmt_name, query, self)
+ *             self.statement = state
+ */
+        __pyx_t_1 = (((PyObject *)__pyx_cur_scope->__pyx_v_state) == Py_None);
+        __pyx_t_2 = (__pyx_t_1 != 0);
+        if (__pyx_t_2) {
+
+          /* "asyncpg/protocol/protocol.pyx":157
+ *             self.last_query = query
+ *             if state is None:
+ *                 state = PreparedStatementState(stmt_name, query, self)             # <<<<<<<<<<<<<<
+ *             self.statement = state
+ *         except Exception as ex:
+ */
+          __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 157, __pyx_L11_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_stmt_name);
+          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_stmt_name);
+          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_stmt_name);
+          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_query);
+          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_query);
+          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_query);
+          __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
+          __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
+          PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_cur_scope->__pyx_v_self));
+          __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState), __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 157, __pyx_L11_error)
+          __Pyx_GOTREF(__pyx_t_7);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+          __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_state, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_t_7));
+          __Pyx_GIVEREF(__pyx_t_7);
+          __pyx_t_7 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":156
+ *             self._prepare(stmt_name, query)  # network op
+ *             self.last_query = query
+ *             if state is None:             # <<<<<<<<<<<<<<
+ *                 state = PreparedStatementState(stmt_name, query, self)
+ *             self.statement = state
+ */
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":158
+ *             if state is None:
+ *                 state = PreparedStatementState(stmt_name, query, self)
+ *             self.statement = state             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->statement);
+        __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_self->statement));
+        __pyx_cur_scope->__pyx_v_self->statement = __pyx_cur_scope->__pyx_v_state;
+
+        /* "asyncpg/protocol/protocol.pyx":153
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._prepare(stmt_name, query)  # network op
+ *             self.last_query = query
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L16_try_end;
+      __pyx_L11_error:;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":159
+ *                 state = PreparedStatementState(stmt_name, query, self)
+ *             self.statement = state
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_8) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_3, &__pyx_t_9) < 0) __PYX_ERR(0, 159, __pyx_L13_except_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_3;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":160
+ *             self.statement = state
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 160, __pyx_L23_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 160, __pyx_L23_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":161
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_10 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 161, __pyx_L23_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":159
+ *                 state = PreparedStatementState(stmt_name, query, self)
+ *             self.statement = state
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L24;
+          }
+          __pyx_L23_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_8 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_8; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L13_except_error;
+          }
+          __pyx_L24:;
+        }
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        goto __pyx_L12_exception_handled;
+      }
+      goto __pyx_L13_except_error;
+      __pyx_L13_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":153
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._prepare(stmt_name, query)  # network op
+ *             self.last_query = query
+ */
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L9_error;
+      __pyx_L12_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      __pyx_L16_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":163
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L29_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 163, __pyx_L1_error)
+        __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+      } else {
+        __pyx_t_9 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 163, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_4);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_4;
+          __Pyx_XGIVEREF(__pyx_t_5);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L32_resume_from_await:;
+          __pyx_t_4 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_4);
+          __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_5);
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 163, __pyx_L31_error)
+          __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+        } else {
+          __pyx_t_9 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 163, __pyx_L31_error)
+          __Pyx_GOTREF(__pyx_t_9);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = 0;
+        goto __pyx_L30_return;
+      }
+      __pyx_L30_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L31_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":141
+ * 
+ *     @cython.iterable_coroutine
+ *     async def prepare(self, stmt_name, query, timeout,             # <<<<<<<<<<<<<<
+ *                       PreparedStatementState state=None):
+ *         if self.cancel_waiter is not None:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_15generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":166
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                            str portal_name, int limit, return_extra,
+ *                            timeout):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_14bind_execute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_14bind_execute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state = 0;
+  PyObject *__pyx_v_args = 0;
+  PyObject *__pyx_v_portal_name = 0;
+  int __pyx_v_limit;
+  PyObject *__pyx_v_return_extra = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind_execute (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_state,&__pyx_n_s_args,&__pyx_n_s_portal_name,&__pyx_n_s_limit,&__pyx_n_s_return_extra,&__pyx_n_s_timeout,0};
+    PyObject* values[6] = {0,0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_state)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute", 1, 6, 6, 1); __PYX_ERR(0, 166, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_portal_name)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute", 1, 6, 6, 2); __PYX_ERR(0, 166, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_limit)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute", 1, 6, 6, 3); __PYX_ERR(0, 166, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_return_extra)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute", 1, 6, 6, 4); __PYX_ERR(0, 166, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute", 1, 6, 6, 5); __PYX_ERR(0, 166, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bind_execute") < 0)) __PYX_ERR(0, 166, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+    }
+    __pyx_v_state = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[0]);
+    __pyx_v_args = values[1];
+    __pyx_v_portal_name = ((PyObject*)values[2]);
+    __pyx_v_limit = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 167, __pyx_L3_error)
+    __pyx_v_return_extra = values[4];
+    __pyx_v_timeout = values[5];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("bind_execute", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 166, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "state", 0))) __PYX_ERR(0, 166, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_portal_name), (&PyUnicode_Type), 1, "portal_name", 1))) __PYX_ERR(0, 167, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_13bind_execute(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_state, __pyx_v_args, __pyx_v_portal_name, __pyx_v_limit, __pyx_v_return_extra, __pyx_v_timeout);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_13bind_execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_args, PyObject *__pyx_v_portal_name, int __pyx_v_limit, PyObject *__pyx_v_return_extra, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind_execute", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 166, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_state = __pyx_v_state;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __pyx_cur_scope->__pyx_v_args = __pyx_v_args;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_args);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_args);
+  __pyx_cur_scope->__pyx_v_portal_name = __pyx_v_portal_name;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __pyx_cur_scope->__pyx_v_limit = __pyx_v_limit;
+  __pyx_cur_scope->__pyx_v_return_extra = __pyx_v_return_extra;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_return_extra);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_return_extra);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_15generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_bind_execute, __pyx_n_s_BaseProtocol_bind_execute, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 166, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_15generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind_execute", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L28_resume_from_await;
+    case 4: goto __pyx_L31_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 166, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":170
+ *                            timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":171
+ * 
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 171, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 171, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":170
+ *                            timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":172
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":173
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 173, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 173, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":174
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":172
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":176
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ *         timeout = self._get_timeout_impl(timeout)
+ *         args_buf = state._encode_bind_msg(args)
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 176, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":177
+ * 
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ *         args_buf = state._encode_bind_msg(args)
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 177, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":178
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)
+ *         args_buf = state._encode_bind_msg(args)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timeout)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg(__pyx_cur_scope->__pyx_v_state, __pyx_cur_scope->__pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 178, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_args_buf = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":180
+ *         args_buf = state._encode_bind_msg(args)
+ * 
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._bind_execute(
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":181
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind_execute(
+ *                 portal_name,
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":184
+ *             self._bind_execute(
+ *                 portal_name,
+ *                 state.name,             # <<<<<<<<<<<<<<
+ *                 args_buf,
+ *                 limit)  # network op
+ */
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_state->name;
+        __Pyx_INCREF(__pyx_t_3);
+
+        /* "asyncpg/protocol/protocol.pyx":185
+ *                 portal_name,
+ *                 state.name,
+ *                 args_buf,             # <<<<<<<<<<<<<<
+ *                 limit)  # network op
+ * 
+ */
+        if (!(likely(((__pyx_cur_scope->__pyx_v_args_buf) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_args_buf, __pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer))))) __PYX_ERR(0, 185, __pyx_L11_error)
+
+        /* "asyncpg/protocol/protocol.pyx":182
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._bind_execute(             # <<<<<<<<<<<<<<
+ *                 portal_name,
+ *                 state.name,
+ */
+        __pyx_t_7 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._bind_execute(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_portal_name, ((PyObject*)__pyx_t_3), ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_args_buf), __pyx_cur_scope->__pyx_v_limit); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 182, __pyx_L11_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":188
+ *                 limit)  # network op
+ * 
+ *             self.last_query = state.query             # <<<<<<<<<<<<<<
+ *             self.statement = state
+ *             self.return_extra = return_extra
+ */
+        __pyx_t_7 = __pyx_cur_scope->__pyx_v_state->query;
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_GIVEREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __pyx_cur_scope->__pyx_v_self->last_query = ((PyObject*)__pyx_t_7);
+        __pyx_t_7 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":189
+ * 
+ *             self.last_query = state.query
+ *             self.statement = state             # <<<<<<<<<<<<<<
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1
+ */
+        __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->statement);
+        __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_self->statement));
+        __pyx_cur_scope->__pyx_v_self->statement = __pyx_cur_scope->__pyx_v_state;
+
+        /* "asyncpg/protocol/protocol.pyx":190
+ *             self.last_query = state.query
+ *             self.statement = state
+ *             self.return_extra = return_extra             # <<<<<<<<<<<<<<
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ */
+        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_return_extra); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 190, __pyx_L11_error)
+        __pyx_cur_scope->__pyx_v_self->return_extra = __pyx_t_1;
+
+        /* "asyncpg/protocol/protocol.pyx":191
+ *             self.statement = state
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __pyx_cur_scope->__pyx_v_self->queries_count = (__pyx_cur_scope->__pyx_v_self->queries_count + 1);
+
+        /* "asyncpg/protocol/protocol.pyx":181
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind_execute(
+ *                 portal_name,
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L16_try_end;
+      __pyx_L11_error:;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":192
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_8) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_3, &__pyx_t_9) < 0) __PYX_ERR(0, 192, __pyx_L13_except_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_3;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":193
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 193, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 193, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":194
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_10 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 194, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":192
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L23;
+          }
+          __pyx_L22_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_8 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_8; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L13_except_error;
+          }
+          __pyx_L23:;
+        }
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        goto __pyx_L12_exception_handled;
+      }
+      goto __pyx_L13_except_error;
+      __pyx_L13_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":181
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind_execute(
+ *                 portal_name,
+ */
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L9_error;
+      __pyx_L12_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      __pyx_L16_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":196
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L28_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 196, __pyx_L1_error)
+        __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+      } else {
+        __pyx_t_9 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 196, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_4);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_4;
+          __Pyx_XGIVEREF(__pyx_t_5);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L31_resume_from_await:;
+          __pyx_t_4 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_4);
+          __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_5);
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 196, __pyx_L30_error)
+          __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+        } else {
+          __pyx_t_9 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 196, __pyx_L30_error)
+          __Pyx_GOTREF(__pyx_t_9);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = 0;
+        goto __pyx_L29_return;
+      }
+      __pyx_L29_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L30_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":166
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                            str portal_name, int limit, return_extra,
+ *                            timeout):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("bind_execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_18generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":199
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute_many(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                                 str portal_name, timeout):
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state = 0;
+  PyObject *__pyx_v_args = 0;
+  PyObject *__pyx_v_portal_name = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind_execute_many (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_state,&__pyx_n_s_args,&__pyx_n_s_portal_name,&__pyx_n_s_timeout,0};
+    PyObject* values[4] = {0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_state)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute_many", 1, 4, 4, 1); __PYX_ERR(0, 199, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_portal_name)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute_many", 1, 4, 4, 2); __PYX_ERR(0, 199, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind_execute_many", 1, 4, 4, 3); __PYX_ERR(0, 199, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bind_execute_many") < 0)) __PYX_ERR(0, 199, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+    }
+    __pyx_v_state = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[0]);
+    __pyx_v_args = values[1];
+    __pyx_v_portal_name = ((PyObject*)values[2]);
+    __pyx_v_timeout = values[3];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("bind_execute_many", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 199, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "state", 0))) __PYX_ERR(0, 199, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_portal_name), (&PyUnicode_Type), 1, "portal_name", 1))) __PYX_ERR(0, 200, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_16bind_execute_many(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_state, __pyx_v_args, __pyx_v_portal_name, __pyx_v_timeout);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many_2generator11(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":214
+ *         # this generator expression to keep the memory pressure under
+ *         # control.
+ *         data_gen = (state._encode_bind_msg(b) for b in args)             # <<<<<<<<<<<<<<
+ *         arg_bufs = iter(data_gen)
+ * 
+ */
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many_genexpr(PyObject *__pyx_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("genexpr", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 214, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *) __pyx_self;
+  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many_2generator11, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bind_execute_many_locals_genexpr, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 214, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute_many.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many_2generator11(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *(*__pyx_t_3)(PyObject *);
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("genexpr", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L6_resume_from_yield;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 214, __pyx_L1_error)
+  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_args)) { __Pyx_RaiseClosureNameError("args"); __PYX_ERR(0, 214, __pyx_L1_error) }
+  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_args)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_args)) {
+    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_args; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+    __pyx_t_3 = NULL;
+  } else {
+    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error)
+  }
+  for (;;) {
+    if (likely(!__pyx_t_3)) {
+      if (likely(PyList_CheckExact(__pyx_t_1))) {
+        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 214, __pyx_L1_error)
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      } else {
+        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 214, __pyx_L1_error)
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      }
+    } else {
+      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
+      if (unlikely(!__pyx_t_4)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else __PYX_ERR(0, 214, __pyx_L1_error)
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_4);
+    }
+    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_b);
+    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_b, __pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_4);
+    __pyx_t_4 = 0;
+    if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_state)) { __Pyx_RaiseClosureNameError("state"); __PYX_ERR(0, 214, __pyx_L1_error) }
+    __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_state, __pyx_cur_scope->__pyx_v_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+    __pyx_cur_scope->__pyx_t_2 = __pyx_t_3;
+    __Pyx_XGIVEREF(__pyx_r);
+    __Pyx_RefNannyFinishContext();
+    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+    /* return from generator, yielding value */
+    __pyx_generator->resume_label = 1;
+    return __pyx_r;
+    __pyx_L6_resume_from_yield:;
+    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+    __pyx_cur_scope->__pyx_t_0 = 0;
+    __Pyx_XGOTREF(__pyx_t_1);
+    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+    __pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
+    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 214, __pyx_L1_error)
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* function exit code */
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":199
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute_many(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                                 str portal_name, timeout):
+ * 
+ */
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_16bind_execute_many(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_args, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind_execute_many", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 199, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_state = __pyx_v_state;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __pyx_cur_scope->__pyx_v_args = __pyx_v_args;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_args);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_args);
+  __pyx_cur_scope->__pyx_v_portal_name = __pyx_v_portal_name;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_18generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_bind_execute_many, __pyx_n_s_BaseProtocol_bind_execute_many, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 199, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_18generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind_execute_many", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L28_resume_from_await;
+    case 4: goto __pyx_L31_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 199, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":202
+ *                                 str portal_name, timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":203
+ * 
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 203, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 203, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":202
+ *                                 str portal_name, timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":204
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":205
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 205, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 205, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":206
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":204
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":208
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ *         timeout = self._get_timeout_impl(timeout)
+ * 
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":209
+ * 
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         # Make sure the argument sequence is encoded lazily with
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":214
+ *         # this generator expression to keep the memory pressure under
+ *         # control.
+ *         data_gen = (state._encode_bind_msg(b) for b in args)             # <<<<<<<<<<<<<<
+ *         arg_bufs = iter(data_gen)
+ * 
+ */
+  __pyx_t_3 = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_data_gen = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":215
+ *         # control.
+ *         data_gen = (state._encode_bind_msg(b) for b in args)
+ *         arg_bufs = iter(data_gen)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timeout)
+ */
+  __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_data_gen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 215, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_arg_bufs = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":217
+ *         arg_bufs = iter(data_gen)
+ * 
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._bind_execute_many(
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 217, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":218
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind_execute_many(
+ *                 portal_name,
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":221
+ *             self._bind_execute_many(
+ *                 portal_name,
+ *                 state.name,             # <<<<<<<<<<<<<<
+ *                 arg_bufs)  # network op
+ * 
+ */
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_state->name;
+        __Pyx_INCREF(__pyx_t_3);
+
+        /* "asyncpg/protocol/protocol.pyx":219
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._bind_execute_many(             # <<<<<<<<<<<<<<
+ *                 portal_name,
+ *                 state.name,
+ */
+        __pyx_t_7 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._bind_execute_many(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_portal_name, ((PyObject*)__pyx_t_3), __pyx_cur_scope->__pyx_v_arg_bufs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 219, __pyx_L11_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":224
+ *                 arg_bufs)  # network op
+ * 
+ *             self.last_query = state.query             # <<<<<<<<<<<<<<
+ *             self.statement = state
+ *             self.return_extra = False
+ */
+        __pyx_t_7 = __pyx_cur_scope->__pyx_v_state->query;
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_GIVEREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __pyx_cur_scope->__pyx_v_self->last_query = ((PyObject*)__pyx_t_7);
+        __pyx_t_7 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":225
+ * 
+ *             self.last_query = state.query
+ *             self.statement = state             # <<<<<<<<<<<<<<
+ *             self.return_extra = False
+ *             self.queries_count += 1
+ */
+        __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->statement);
+        __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_self->statement));
+        __pyx_cur_scope->__pyx_v_self->statement = __pyx_cur_scope->__pyx_v_state;
+
+        /* "asyncpg/protocol/protocol.pyx":226
+ *             self.last_query = state.query
+ *             self.statement = state
+ *             self.return_extra = False             # <<<<<<<<<<<<<<
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ */
+        __pyx_cur_scope->__pyx_v_self->return_extra = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":227
+ *             self.statement = state
+ *             self.return_extra = False
+ *             self.queries_count += 1             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __pyx_cur_scope->__pyx_v_self->queries_count = (__pyx_cur_scope->__pyx_v_self->queries_count + 1);
+
+        /* "asyncpg/protocol/protocol.pyx":218
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind_execute_many(
+ *                 portal_name,
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L16_try_end;
+      __pyx_L11_error:;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":228
+ *             self.return_extra = False
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_8) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_3, &__pyx_t_9) < 0) __PYX_ERR(0, 228, __pyx_L13_except_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_3;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":229
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 229, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 229, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":230
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_10 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 230, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":228
+ *             self.return_extra = False
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L23;
+          }
+          __pyx_L22_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_8 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_8; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L13_except_error;
+          }
+          __pyx_L23:;
+        }
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        goto __pyx_L12_exception_handled;
+      }
+      goto __pyx_L13_except_error;
+      __pyx_L13_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":218
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind_execute_many(
+ *                 portal_name,
+ */
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L9_error;
+      __pyx_L12_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      __pyx_L16_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":232
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L28_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 232, __pyx_L1_error)
+        __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+      } else {
+        __pyx_t_9 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 232, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_4);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_4;
+          __Pyx_XGIVEREF(__pyx_t_5);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L31_resume_from_await:;
+          __pyx_t_4 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_4);
+          __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_5);
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 232, __pyx_L30_error)
+          __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+        } else {
+          __pyx_t_9 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 232, __pyx_L30_error)
+          __Pyx_GOTREF(__pyx_t_9);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = 0;
+        goto __pyx_L29_return;
+      }
+      __pyx_L29_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L30_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":199
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind_execute_many(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                                 str portal_name, timeout):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("bind_execute_many", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_21generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":235
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                    str portal_name, timeout):
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_20bind(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_20bind(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state = 0;
+  PyObject *__pyx_v_args = 0;
+  PyObject *__pyx_v_portal_name = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_state,&__pyx_n_s_args,&__pyx_n_s_portal_name,&__pyx_n_s_timeout,0};
+    PyObject* values[4] = {0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_state)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind", 1, 4, 4, 1); __PYX_ERR(0, 235, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_portal_name)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind", 1, 4, 4, 2); __PYX_ERR(0, 235, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("bind", 1, 4, 4, 3); __PYX_ERR(0, 235, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bind") < 0)) __PYX_ERR(0, 235, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+    }
+    __pyx_v_state = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[0]);
+    __pyx_v_args = values[1];
+    __pyx_v_portal_name = ((PyObject*)values[2]);
+    __pyx_v_timeout = values[3];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("bind", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 235, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "state", 0))) __PYX_ERR(0, 235, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_portal_name), (&PyUnicode_Type), 1, "portal_name", 1))) __PYX_ERR(0, 236, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_19bind(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_state, __pyx_v_args, __pyx_v_portal_name, __pyx_v_timeout);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_19bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_args, PyObject *__pyx_v_portal_name, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 235, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_state = __pyx_v_state;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __pyx_cur_scope->__pyx_v_args = __pyx_v_args;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_args);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_args);
+  __pyx_cur_scope->__pyx_v_portal_name = __pyx_v_portal_name;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_21generator3, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_bind, __pyx_n_s_BaseProtocol_bind, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 235, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_21generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("bind", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L28_resume_from_await;
+    case 4: goto __pyx_L31_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 235, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":238
+ *                    str portal_name, timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":239
+ * 
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 239, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 239, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":238
+ *                    str portal_name, timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":240
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":241
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 241, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 241, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":242
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":240
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":244
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ *         timeout = self._get_timeout_impl(timeout)
+ *         args_buf = state._encode_bind_msg(args)
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 244, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":245
+ * 
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ *         args_buf = state._encode_bind_msg(args)
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 245, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":246
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)
+ *         args_buf = state._encode_bind_msg(args)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timeout)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg(__pyx_cur_scope->__pyx_v_state, __pyx_cur_scope->__pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 246, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_args_buf = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":248
+ *         args_buf = state._encode_bind_msg(args)
+ * 
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._bind(
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 248, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":249
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind(
+ *                 portal_name,
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":252
+ *             self._bind(
+ *                 portal_name,
+ *                 state.name,             # <<<<<<<<<<<<<<
+ *                 args_buf)  # network op
+ * 
+ */
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_state->name;
+        __Pyx_INCREF(__pyx_t_3);
+
+        /* "asyncpg/protocol/protocol.pyx":253
+ *                 portal_name,
+ *                 state.name,
+ *                 args_buf)  # network op             # <<<<<<<<<<<<<<
+ * 
+ *             self.last_query = state.query
+ */
+        if (!(likely(((__pyx_cur_scope->__pyx_v_args_buf) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_args_buf, __pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer))))) __PYX_ERR(0, 253, __pyx_L11_error)
+
+        /* "asyncpg/protocol/protocol.pyx":250
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._bind(             # <<<<<<<<<<<<<<
+ *                 portal_name,
+ *                 state.name,
+ */
+        __pyx_t_7 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._bind(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_portal_name, ((PyObject*)__pyx_t_3), ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_args_buf)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 250, __pyx_L11_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":255
+ *                 args_buf)  # network op
+ * 
+ *             self.last_query = state.query             # <<<<<<<<<<<<<<
+ *             self.statement = state
+ *         except Exception as ex:
+ */
+        __pyx_t_7 = __pyx_cur_scope->__pyx_v_state->query;
+        __Pyx_INCREF(__pyx_t_7);
+        __Pyx_GIVEREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __pyx_cur_scope->__pyx_v_self->last_query = ((PyObject*)__pyx_t_7);
+        __pyx_t_7 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":256
+ * 
+ *             self.last_query = state.query
+ *             self.statement = state             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->statement);
+        __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_self->statement));
+        __pyx_cur_scope->__pyx_v_self->statement = __pyx_cur_scope->__pyx_v_state;
+
+        /* "asyncpg/protocol/protocol.pyx":249
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind(
+ *                 portal_name,
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L16_try_end;
+      __pyx_L11_error:;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":257
+ *             self.last_query = state.query
+ *             self.statement = state
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_8) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_3, &__pyx_t_9) < 0) __PYX_ERR(0, 257, __pyx_L13_except_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_3;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":258
+ *             self.statement = state
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 258, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 258, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":259
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_10 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 259, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":257
+ *             self.last_query = state.query
+ *             self.statement = state
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L23;
+          }
+          __pyx_L22_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_8 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_8; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L13_except_error;
+          }
+          __pyx_L23:;
+        }
+        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        goto __pyx_L12_exception_handled;
+      }
+      goto __pyx_L13_except_error;
+      __pyx_L13_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":249
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._bind(
+ *                 portal_name,
+ */
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L9_error;
+      __pyx_L12_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      __pyx_L16_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":261
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L28_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 261, __pyx_L1_error)
+        __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+      } else {
+        __pyx_t_9 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 261, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_4);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_4;
+          __Pyx_XGIVEREF(__pyx_t_5);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L31_resume_from_await:;
+          __pyx_t_4 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_4);
+          __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_5);
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 261, __pyx_L30_error)
+          __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+        } else {
+          __pyx_t_9 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 261, __pyx_L30_error)
+          __Pyx_GOTREF(__pyx_t_9);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = 0;
+        goto __pyx_L29_return;
+      }
+      __pyx_L29_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L30_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":235
+ * 
+ *     @cython.iterable_coroutine
+ *     async def bind(self, PreparedStatementState state, args,             # <<<<<<<<<<<<<<
+ *                    str portal_name, timeout):
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_24generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":264
+ * 
+ *     @cython.iterable_coroutine
+ *     async def execute(self, PreparedStatementState state,             # <<<<<<<<<<<<<<
+ *                       str portal_name, int limit, return_extra,
+ *                       timeout):
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_23execute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_23execute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state = 0;
+  PyObject *__pyx_v_portal_name = 0;
+  int __pyx_v_limit;
+  PyObject *__pyx_v_return_extra = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("execute (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_state,&__pyx_n_s_portal_name,&__pyx_n_s_limit,&__pyx_n_s_return_extra,&__pyx_n_s_timeout,0};
+    PyObject* values[5] = {0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_state)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_portal_name)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("execute", 1, 5, 5, 1); __PYX_ERR(0, 264, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_limit)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("execute", 1, 5, 5, 2); __PYX_ERR(0, 264, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_return_extra)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("execute", 1, 5, 5, 3); __PYX_ERR(0, 264, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("execute", 1, 5, 5, 4); __PYX_ERR(0, 264, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "execute") < 0)) __PYX_ERR(0, 264, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+    }
+    __pyx_v_state = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[0]);
+    __pyx_v_portal_name = ((PyObject*)values[1]);
+    __pyx_v_limit = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_limit == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 265, __pyx_L3_error)
+    __pyx_v_return_extra = values[3];
+    __pyx_v_timeout = values[4];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("execute", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 264, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "state", 0))) __PYX_ERR(0, 264, __pyx_L1_error)
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_portal_name), (&PyUnicode_Type), 1, "portal_name", 1))) __PYX_ERR(0, 265, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_22execute(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_state, __pyx_v_portal_name, __pyx_v_limit, __pyx_v_return_extra, __pyx_v_timeout);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_22execute(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_portal_name, int __pyx_v_limit, PyObject *__pyx_v_return_extra, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("execute", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 264, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_state = __pyx_v_state;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __pyx_cur_scope->__pyx_v_portal_name = __pyx_v_portal_name;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_portal_name);
+  __pyx_cur_scope->__pyx_v_limit = __pyx_v_limit;
+  __pyx_cur_scope->__pyx_v_return_extra = __pyx_v_return_extra;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_return_extra);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_return_extra);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_24generator4, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_execute, __pyx_n_s_BaseProtocol_execute, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 264, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_24generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("execute", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L28_resume_from_await;
+    case 4: goto __pyx_L31_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 264, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":268
+ *                       timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":269
+ * 
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 269, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 269, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":268
+ *                       timeout):
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":270
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":271
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 271, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 271, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":272
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":270
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":274
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ *         timeout = self._get_timeout_impl(timeout)
+ * 
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 274, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":275
+ * 
+ *         self._check_state()
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timeout)
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 275, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":277
+ *         timeout = self._get_timeout_impl(timeout)
+ * 
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._execute(
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 277, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":278
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._execute(
+ *                 portal_name,
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_6);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":279
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._execute(             # <<<<<<<<<<<<<<
+ *                 portal_name,
+ *                 limit)  # network op
+ */
+        __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._execute(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_portal_name, __pyx_cur_scope->__pyx_v_limit); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 279, __pyx_L11_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":283
+ *                 limit)  # network op
+ * 
+ *             self.last_query = state.query             # <<<<<<<<<<<<<<
+ *             self.statement = state
+ *             self.return_extra = return_extra
+ */
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_state->query;
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __pyx_cur_scope->__pyx_v_self->last_query = ((PyObject*)__pyx_t_3);
+        __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":284
+ * 
+ *             self.last_query = state.query
+ *             self.statement = state             # <<<<<<<<<<<<<<
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1
+ */
+        __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_state));
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->statement);
+        __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_self->statement));
+        __pyx_cur_scope->__pyx_v_self->statement = __pyx_cur_scope->__pyx_v_state;
+
+        /* "asyncpg/protocol/protocol.pyx":285
+ *             self.last_query = state.query
+ *             self.statement = state
+ *             self.return_extra = return_extra             # <<<<<<<<<<<<<<
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ */
+        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_return_extra); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L11_error)
+        __pyx_cur_scope->__pyx_v_self->return_extra = __pyx_t_1;
+
+        /* "asyncpg/protocol/protocol.pyx":286
+ *             self.statement = state
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __pyx_cur_scope->__pyx_v_self->queries_count = (__pyx_cur_scope->__pyx_v_self->queries_count + 1);
+
+        /* "asyncpg/protocol/protocol.pyx":278
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._execute(
+ *                 portal_name,
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      goto __pyx_L16_try_end;
+      __pyx_L11_error:;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":287
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_7) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 287, __pyx_L13_except_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_GIVEREF(__pyx_t_8);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_8;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":288
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 288, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 288, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":289
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_10 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 289, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":287
+ *             self.return_extra = return_extra
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L23;
+          }
+          __pyx_L22_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_7 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L13_except_error;
+          }
+          __pyx_L23:;
+        }
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+        goto __pyx_L12_exception_handled;
+      }
+      goto __pyx_L13_except_error;
+      __pyx_L13_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":278
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._execute(
+ *                 portal_name,
+ */
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      goto __pyx_L9_error;
+      __pyx_L12_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+      __pyx_L16_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":291
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L28_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 291, __pyx_L1_error)
+        __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+      } else {
+        __pyx_t_9 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 291, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_9);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_9 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_4);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_4;
+          __Pyx_XGIVEREF(__pyx_t_5);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L31_resume_from_await:;
+          __pyx_t_4 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_4);
+          __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_5);
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 291, __pyx_L30_error)
+          __pyx_t_9 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_9);
+        } else {
+          __pyx_t_9 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_9) < 0) __PYX_ERR(0, 291, __pyx_L30_error)
+          __Pyx_GOTREF(__pyx_t_9);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_9);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __pyx_t_9 = 0;
+        goto __pyx_L29_return;
+      }
+      __pyx_L29_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L30_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":264
+ * 
+ *     @cython.iterable_coroutine
+ *     async def execute(self, PreparedStatementState state,             # <<<<<<<<<<<<<<
+ *                       str portal_name, int limit, return_extra,
+ *                       timeout):
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("execute", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_27generator5(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":294
+ * 
+ *     @cython.iterable_coroutine
+ *     async def query(self, query, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_26query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_26query(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_query = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("query (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_timeout,0};
+    PyObject* values[2] = {0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("query", 1, 2, 2, 1); __PYX_ERR(0, 294, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "query") < 0)) __PYX_ERR(0, 294, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+    }
+    __pyx_v_query = values[0];
+    __pyx_v_timeout = values[1];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("query", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 294, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_25query(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_query, __pyx_v_timeout);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_25query(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_query, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("query", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 294, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_query = __pyx_v_query;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_query);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_query);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_27generator5, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_query, __pyx_n_s_BaseProtocol_query, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 294, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_27generator5(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("query", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L28_resume_from_await;
+    case 4: goto __pyx_L31_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 294, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":295
+ *     @cython.iterable_coroutine
+ *     async def query(self, query, timeout):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":296
+ *     async def query(self, query, timeout):
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 296, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 296, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":295
+ *     @cython.iterable_coroutine
+ *     async def query(self, query, timeout):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":297
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":298
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 298, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 298, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":299
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":297
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":301
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ *         # query() needs to call _get_timeout instead of _get_timeout_impl
+ *         # for consistent validation, as it is called differently from
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 301, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":305
+ *         # for consistent validation, as it is called differently from
+ *         # prepare/bind/execute methods.
+ *         timeout = self._get_timeout(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timeout)
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_timeout); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 305, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_cur_scope->__pyx_v_timeout) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":307
+ *         timeout = self._get_timeout(timeout)
+ * 
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._simple_query(query)  # network op
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":308
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._simple_query(query)  # network op
+ *             self.last_query = query
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_8);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":309
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._simple_query(query)  # network op             # <<<<<<<<<<<<<<
+ *             self.last_query = query
+ *             self.queries_count += 1
+ */
+        if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_query))||((__pyx_cur_scope->__pyx_v_query) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_query)->tp_name), 0))) __PYX_ERR(0, 309, __pyx_L11_error)
+        __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._simple_query(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject*)__pyx_cur_scope->__pyx_v_query)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 309, __pyx_L11_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":310
+ *         try:
+ *             self._simple_query(query)  # network op
+ *             self.last_query = query             # <<<<<<<<<<<<<<
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ */
+        if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_query))||((__pyx_cur_scope->__pyx_v_query) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_query)->tp_name), 0))) __PYX_ERR(0, 310, __pyx_L11_error)
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_query;
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->last_query);
+        __pyx_cur_scope->__pyx_v_self->last_query = ((PyObject*)__pyx_t_3);
+        __pyx_t_3 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":311
+ *             self._simple_query(query)  # network op
+ *             self.last_query = query
+ *             self.queries_count += 1             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __pyx_cur_scope->__pyx_v_self->queries_count = (__pyx_cur_scope->__pyx_v_self->queries_count + 1);
+
+        /* "asyncpg/protocol/protocol.pyx":308
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._simple_query(query)  # network op
+ *             self.last_query = query
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L16_try_end;
+      __pyx_L11_error:;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":312
+ *             self.last_query = query
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_9) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 312, __pyx_L13_except_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_GIVEREF(__pyx_t_4);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_4;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":313
+ *             self.queries_count += 1
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 313, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
+            }
+          }
+          __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 313, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":314
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_10 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 314, __pyx_L22_error)
+          __Pyx_GOTREF(__pyx_t_10);
+          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":312
+ *             self.last_query = query
+ *             self.queries_count += 1
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L23;
+          }
+          __pyx_L22_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_9 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_9; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L13_except_error;
+          }
+          __pyx_L23:;
+        }
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        goto __pyx_L12_exception_handled;
+      }
+      goto __pyx_L13_except_error;
+      __pyx_L13_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":308
+ * 
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._simple_query(query)  # network op
+ *             self.last_query = query
+ */
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+      goto __pyx_L9_error;
+      __pyx_L12_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+      __pyx_L16_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":316
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L28_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 316, __pyx_L1_error)
+        __pyx_t_5 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_5);
+      } else {
+        __pyx_t_5 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_5) < 0) __PYX_ERR(0, 316, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_t_5 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6) < 0)) __Pyx_ErrFetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_7);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+          __Pyx_XGIVEREF(__pyx_t_8);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L31_resume_from_await:;
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_7);
+          __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_8);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 316, __pyx_L30_error)
+          __pyx_t_5 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_5);
+        } else {
+          __pyx_t_5 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_5) < 0) __PYX_ERR(0, 316, __pyx_L30_error)
+          __Pyx_GOTREF(__pyx_t_5);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __pyx_t_5 = 0;
+        goto __pyx_L29_return;
+      }
+      __pyx_L29_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L30_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":294
+ * 
+ *     @cython.iterable_coroutine
+ *     async def query(self, query, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_30generator6(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":319
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_out(self, copy_stmt, sink, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_29copy_out(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_29copy_out(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_copy_stmt = 0;
+  PyObject *__pyx_v_sink = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("copy_out (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_copy_stmt,&__pyx_n_s_sink,&__pyx_n_s_timeout,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_copy_stmt)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sink)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_out", 1, 3, 3, 1); __PYX_ERR(0, 319, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_out", 1, 3, 3, 2); __PYX_ERR(0, 319, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "copy_out") < 0)) __PYX_ERR(0, 319, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v_copy_stmt = values[0];
+    __pyx_v_sink = values[1];
+    __pyx_v_timeout = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("copy_out", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 319, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_28copy_out(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_copy_stmt, __pyx_v_sink, __pyx_v_timeout);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":359
+ *                         # Make asyncio shut up about unretrieved
+ *                         # QueryCanceledError
+ *                         waiter.add_done_callback(lambda f: f.exception())             # <<<<<<<<<<<<<<
+ *                         raise
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_8copy_out_lambda1(PyObject *__pyx_self, PyObject *__pyx_v_f); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_12BaseProtocol_8copy_out_lambda1 = {"lambda1", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_8copy_out_lambda1, METH_O, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_8copy_out_lambda1(PyObject *__pyx_self, PyObject *__pyx_v_f) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("lambda1 (wrapper)", 0);
+  __pyx_r = __pyx_lambda_funcdef_lambda1(__pyx_self, ((PyObject *)__pyx_v_f));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_lambda_funcdef_lambda1(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("lambda1", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_exception); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_out.lambda1", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":319
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_out(self, copy_stmt, sink, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_28copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt, PyObject *__pyx_v_sink, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("copy_out", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 319, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_copy_stmt = __pyx_v_copy_stmt;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_copy_stmt);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_copy_stmt);
+  __pyx_cur_scope->__pyx_v_sink = __pyx_v_sink;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_sink);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_sink);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_30generator6, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_copy_out, __pyx_n_s_BaseProtocol_copy_out, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 319, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_30generator6(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *(*__pyx_t_12)(PyObject *);
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  int __pyx_t_18;
+  PyObject *__pyx_t_19 = NULL;
+  int __pyx_t_20;
+  char const *__pyx_t_21;
+  PyObject *__pyx_t_22 = NULL;
+  char const *__pyx_t_23;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("copy_out", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L27_resume_from_await;
+    case 4: goto __pyx_L57_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 319, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":320
+ *     @cython.iterable_coroutine
+ *     async def copy_out(self, copy_stmt, sink, timeout):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":321
+ *     async def copy_out(self, copy_stmt, sink, timeout):
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 321, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 321, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":320
+ *     @cython.iterable_coroutine
+ *     async def copy_out(self, copy_stmt, sink, timeout):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":322
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":323
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 323, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 323, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":324
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":322
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":326
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":328
+ *         self._check_state()
+ * 
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ *         timer = Timer(timeout)
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 328, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":329
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ *         timer = Timer(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         # The copy operation is guarded by a single timeout
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_Timer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 329, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_cur_scope->__pyx_v_timeout) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_timer = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":333
+ *         # The copy operation is guarded by a single timeout
+ *         # on the top level.
+ *         waiter = self._new_waiter(timer.get_remaining_budget())             # <<<<<<<<<<<<<<
+ * 
+ *         self._copy_out(copy_stmt)
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_get_remaining_budget); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 333, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 333, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_GIVEREF(__pyx_t_4);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_4;
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":335
+ *         waiter = self._new_waiter(timer.get_remaining_budget())
+ * 
+ *         self._copy_out(copy_stmt)             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+  if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_copy_stmt))||((__pyx_cur_scope->__pyx_v_copy_stmt) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_copy_stmt)->tp_name), 0))) __PYX_ERR(0, 335, __pyx_L1_error)
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._copy_out(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject*)__pyx_cur_scope->__pyx_v_copy_stmt)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 335, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":337
+ *         self._copy_out(copy_stmt)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             while True:
+ *                 self.resume_reading()
+ */
+  /*try:*/ {
+
+    /* "asyncpg/protocol/protocol.pyx":338
+ * 
+ *         try:
+ *             while True:             # <<<<<<<<<<<<<<
+ *                 self.resume_reading()
+ * 
+ */
+    while (1) {
+
+      /* "asyncpg/protocol/protocol.pyx":339
+ *         try:
+ *             while True:
+ *                 self.resume_reading()             # <<<<<<<<<<<<<<
+ * 
+ *                 with timer:
+ */
+      __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 339, __pyx_L9_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":341
+ *                 self.resume_reading()
+ * 
+ *                 with timer:             # <<<<<<<<<<<<<<
+ *                     buffer, done, status_msg = await waiter
+ * 
+ */
+      /*with:*/ {
+        __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 341, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_enter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L13_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __pyx_t_5 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+          if (likely(__pyx_t_5)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+            __Pyx_INCREF(__pyx_t_5);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_3, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 341, __pyx_L13_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        /*try:*/ {
+          {
+            __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+            __Pyx_XGOTREF(__pyx_t_7);
+            __Pyx_XGOTREF(__pyx_t_8);
+            __Pyx_XGOTREF(__pyx_t_9);
+            /*try:*/ {
+
+              /* "asyncpg/protocol/protocol.pyx":342
+ * 
+ *                 with timer:
+ *                     buffer, done, status_msg = await waiter             # <<<<<<<<<<<<<<
+ * 
+ *                 # buffer will be empty if CopyDone was received apart from
+ */
+              __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+              __Pyx_XGOTREF(__pyx_r);
+              if (likely(__pyx_r)) {
+                __Pyx_XGIVEREF(__pyx_t_6);
+                __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+                __Pyx_XGIVEREF(__pyx_t_7);
+                __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+                __Pyx_XGIVEREF(__pyx_t_8);
+                __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+                __Pyx_XGIVEREF(__pyx_t_9);
+                __pyx_cur_scope->__pyx_t_3 = __pyx_t_9;
+                __Pyx_XGIVEREF(__pyx_r);
+                __Pyx_RefNannyFinishContext();
+                __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+                /* return from generator, awaiting value */
+                __pyx_generator->resume_label = 3;
+                return __pyx_r;
+                __pyx_L27_resume_from_await:;
+                __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+                __pyx_cur_scope->__pyx_t_0 = 0;
+                __Pyx_XGOTREF(__pyx_t_6);
+                __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+                __pyx_cur_scope->__pyx_t_1 = 0;
+                __Pyx_XGOTREF(__pyx_t_7);
+                __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+                __pyx_cur_scope->__pyx_t_2 = 0;
+                __Pyx_XGOTREF(__pyx_t_8);
+                __pyx_t_9 = __pyx_cur_scope->__pyx_t_3;
+                __pyx_cur_scope->__pyx_t_3 = 0;
+                __Pyx_XGOTREF(__pyx_t_9);
+                if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 342, __pyx_L19_error)
+                __pyx_t_4 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_4);
+              } else {
+                __pyx_t_4 = NULL;
+                if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_4) < 0) __PYX_ERR(0, 342, __pyx_L19_error)
+                __Pyx_GOTREF(__pyx_t_4);
+              }
+              if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
+                PyObject* sequence = __pyx_t_4;
+                Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
+                if (unlikely(size != 3)) {
+                  if (size > 3) __Pyx_RaiseTooManyValuesError(3);
+                  else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
+                  __PYX_ERR(0, 342, __pyx_L19_error)
+                }
+                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+                if (likely(PyTuple_CheckExact(sequence))) {
+                  __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
+                  __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
+                  __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); 
+                } else {
+                  __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
+                  __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
+                  __pyx_t_10 = PyList_GET_ITEM(sequence, 2); 
+                }
+                __Pyx_INCREF(__pyx_t_3);
+                __Pyx_INCREF(__pyx_t_5);
+                __Pyx_INCREF(__pyx_t_10);
+                #else
+                __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 342, __pyx_L19_error)
+                __Pyx_GOTREF(__pyx_t_3);
+                __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 342, __pyx_L19_error)
+                __Pyx_GOTREF(__pyx_t_5);
+                __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 342, __pyx_L19_error)
+                __Pyx_GOTREF(__pyx_t_10);
+                #endif
+                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+              } else {
+                Py_ssize_t index = -1;
+                __pyx_t_11 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 342, __pyx_L19_error)
+                __Pyx_GOTREF(__pyx_t_11);
+                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+                __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
+                index = 0; __pyx_t_3 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_3)) goto __pyx_L28_unpacking_failed;
+                __Pyx_GOTREF(__pyx_t_3);
+                index = 1; __pyx_t_5 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_5)) goto __pyx_L28_unpacking_failed;
+                __Pyx_GOTREF(__pyx_t_5);
+                index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L28_unpacking_failed;
+                __Pyx_GOTREF(__pyx_t_10);
+                if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) __PYX_ERR(0, 342, __pyx_L19_error)
+                __pyx_t_12 = NULL;
+                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                goto __pyx_L29_unpacking_done;
+                __pyx_L28_unpacking_failed:;
+                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                __pyx_t_12 = NULL;
+                if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
+                __PYX_ERR(0, 342, __pyx_L19_error)
+                __pyx_L29_unpacking_done:;
+              }
+              __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_buffer);
+              __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_buffer, __pyx_t_3);
+              __Pyx_GIVEREF(__pyx_t_3);
+              __pyx_t_3 = 0;
+              __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_done);
+              __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_done, __pyx_t_5);
+              __Pyx_GIVEREF(__pyx_t_5);
+              __pyx_t_5 = 0;
+              __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_status_msg);
+              __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_status_msg, __pyx_t_10);
+              __Pyx_GIVEREF(__pyx_t_10);
+              __pyx_t_10 = 0;
+
+              /* "asyncpg/protocol/protocol.pyx":341
+ *                 self.resume_reading()
+ * 
+ *                 with timer:             # <<<<<<<<<<<<<<
+ *                     buffer, done, status_msg = await waiter
+ * 
+ */
+            }
+            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+            goto __pyx_L26_try_end;
+            __pyx_L19_error:;
+            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+            /*except:*/ {
+              __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+              if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_10, &__pyx_t_5) < 0) __PYX_ERR(0, 341, __pyx_L21_except_error)
+              __Pyx_GOTREF(__pyx_t_4);
+              __Pyx_GOTREF(__pyx_t_10);
+              __Pyx_GOTREF(__pyx_t_5);
+              __pyx_t_3 = PyTuple_Pack(3, __pyx_t_4, __pyx_t_10, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __pyx_L21_except_error)
+              __Pyx_GOTREF(__pyx_t_3);
+              __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL);
+              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+              if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 341, __pyx_L21_except_error)
+              __Pyx_GOTREF(__pyx_t_13);
+              __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_13);
+              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+              if (__pyx_t_1 < 0) __PYX_ERR(0, 341, __pyx_L21_except_error)
+              __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
+              if (__pyx_t_2) {
+                __Pyx_GIVEREF(__pyx_t_4);
+                __Pyx_GIVEREF(__pyx_t_10);
+                __Pyx_XGIVEREF(__pyx_t_5);
+                __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_10, __pyx_t_5);
+                __pyx_t_4 = 0; __pyx_t_10 = 0; __pyx_t_5 = 0; 
+                __PYX_ERR(0, 341, __pyx_L21_except_error)
+              }
+              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+              __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+              goto __pyx_L20_exception_handled;
+            }
+            __pyx_L21_except_error:;
+            __Pyx_XGIVEREF(__pyx_t_7);
+            __Pyx_XGIVEREF(__pyx_t_8);
+            __Pyx_XGIVEREF(__pyx_t_9);
+            __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+            goto __pyx_L9_error;
+            __pyx_L20_exception_handled:;
+            __Pyx_XGIVEREF(__pyx_t_7);
+            __Pyx_XGIVEREF(__pyx_t_8);
+            __Pyx_XGIVEREF(__pyx_t_9);
+            __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+            __pyx_L26_try_end:;
+          }
+        }
+        /*finally:*/ {
+          /*normal exit:*/{
+            if (__pyx_t_6) {
+              __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__31, NULL);
+              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+              if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 341, __pyx_L9_error)
+              __Pyx_GOTREF(__pyx_t_9);
+              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+            }
+            goto __pyx_L18;
+          }
+          __pyx_L18:;
+        }
+        goto __pyx_L33;
+        __pyx_L13_error:;
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+        goto __pyx_L9_error;
+        __pyx_L33:;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":346
+ *                 # buffer will be empty if CopyDone was received apart from
+ *                 # the last CopyData message.
+ *                 if buffer:             # <<<<<<<<<<<<<<
+ *                     try:
+ *                         with timer:
+ */
+      if (unlikely(!__pyx_cur_scope->__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); __PYX_ERR(0, 346, __pyx_L9_error) }
+      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_buffer); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 346, __pyx_L9_error)
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/protocol.pyx":347
+ *                 # the last CopyData message.
+ *                 if buffer:
+ *                     try:             # <<<<<<<<<<<<<<
+ *                         with timer:
+ *                             await asyncio.wait_for(
+ */
+        {
+          __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_9, &__pyx_t_8);
+          __Pyx_XGOTREF(__pyx_t_6);
+          __Pyx_XGOTREF(__pyx_t_9);
+          __Pyx_XGOTREF(__pyx_t_8);
+          /*try:*/ {
+
+            /* "asyncpg/protocol/protocol.pyx":348
+ *                 if buffer:
+ *                     try:
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await asyncio.wait_for(
+ *                                 sink(buffer),
+ */
+            /*with:*/ {
+              __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_exit); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 348, __pyx_L35_error)
+              __Pyx_GOTREF(__pyx_t_7);
+              __pyx_t_10 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_enter); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 348, __pyx_L43_error)
+              __Pyx_GOTREF(__pyx_t_10);
+              __pyx_t_4 = NULL;
+              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
+                __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_10);
+                if (likely(__pyx_t_4)) {
+                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
+                  __Pyx_INCREF(__pyx_t_4);
+                  __Pyx_INCREF(function);
+                  __Pyx_DECREF_SET(__pyx_t_10, function);
+                }
+              }
+              __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_10);
+              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+              if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 348, __pyx_L43_error)
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+              /*try:*/ {
+                {
+                  __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
+                  __Pyx_XGOTREF(__pyx_t_13);
+                  __Pyx_XGOTREF(__pyx_t_14);
+                  __Pyx_XGOTREF(__pyx_t_15);
+                  /*try:*/ {
+
+                    /* "asyncpg/protocol/protocol.pyx":349
+ *                     try:
+ *                         with timer:
+ *                             await asyncio.wait_for(             # <<<<<<<<<<<<<<
+ *                                 sink(buffer),
+ *                                 timeout=timer.get_remaining_budget(),
+ */
+                    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 349, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_5);
+                    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_wait_for); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 349, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_10);
+                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+                    /* "asyncpg/protocol/protocol.pyx":350
+ *                         with timer:
+ *                             await asyncio.wait_for(
+ *                                 sink(buffer),             # <<<<<<<<<<<<<<
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)
+ */
+                    if (unlikely(!__pyx_cur_scope->__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); __PYX_ERR(0, 350, __pyx_L49_error) }
+                    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_sink);
+                    __pyx_t_4 = __pyx_cur_scope->__pyx_v_sink; __pyx_t_3 = NULL;
+                    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+                      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+                      if (likely(__pyx_t_3)) {
+                        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+                        __Pyx_INCREF(__pyx_t_3);
+                        __Pyx_INCREF(function);
+                        __Pyx_DECREF_SET(__pyx_t_4, function);
+                      }
+                    }
+                    __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_cur_scope->__pyx_v_buffer) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_cur_scope->__pyx_v_buffer);
+                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 350, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_5);
+                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+                    /* "asyncpg/protocol/protocol.pyx":349
+ *                     try:
+ *                         with timer:
+ *                             await asyncio.wait_for(             # <<<<<<<<<<<<<<
+ *                                 sink(buffer),
+ *                                 timeout=timer.get_remaining_budget(),
+ */
+                    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 349, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_4);
+                    __Pyx_GIVEREF(__pyx_t_5);
+                    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
+                    __pyx_t_5 = 0;
+
+                    /* "asyncpg/protocol/protocol.pyx":351
+ *                             await asyncio.wait_for(
+ *                                 sink(buffer),
+ *                                 timeout=timer.get_remaining_budget(),             # <<<<<<<<<<<<<<
+ *                                 loop=self.loop)
+ *                     except Exception as ex:
+ */
+                    __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 351, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_5);
+                    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_get_remaining_budget); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 351, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_11);
+                    __pyx_t_16 = NULL;
+                    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+                      __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_11);
+                      if (likely(__pyx_t_16)) {
+                        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+                        __Pyx_INCREF(__pyx_t_16);
+                        __Pyx_INCREF(function);
+                        __Pyx_DECREF_SET(__pyx_t_11, function);
+                      }
+                    }
+                    __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_16) : __Pyx_PyObject_CallNoArg(__pyx_t_11);
+                    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_3);
+                    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_timeout, __pyx_t_3) < 0) __PYX_ERR(0, 351, __pyx_L49_error)
+                    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+                    /* "asyncpg/protocol/protocol.pyx":352
+ *                                 sink(buffer),
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)             # <<<<<<<<<<<<<<
+ *                     except Exception as ex:
+ *                         # Abort the COPY operation on any error in
+ */
+                    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_loop, __pyx_cur_scope->__pyx_v_self->loop) < 0) __PYX_ERR(0, 351, __pyx_L49_error)
+
+                    /* "asyncpg/protocol/protocol.pyx":349
+ *                     try:
+ *                         with timer:
+ *                             await asyncio.wait_for(             # <<<<<<<<<<<<<<
+ *                                 sink(buffer),
+ *                                 timeout=timer.get_remaining_budget(),
+ */
+                    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __pyx_L49_error)
+                    __Pyx_GOTREF(__pyx_t_3);
+                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+                    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_3);
+                    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    __Pyx_XGOTREF(__pyx_r);
+                    if (likely(__pyx_r)) {
+                      __Pyx_XGIVEREF(__pyx_t_6);
+                      __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+                      __Pyx_XGIVEREF(__pyx_t_7);
+                      __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+                      __Pyx_XGIVEREF(__pyx_t_8);
+                      __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+                      __Pyx_XGIVEREF(__pyx_t_9);
+                      __pyx_cur_scope->__pyx_t_3 = __pyx_t_9;
+                      __Pyx_XGIVEREF(__pyx_t_13);
+                      __pyx_cur_scope->__pyx_t_4 = __pyx_t_13;
+                      __Pyx_XGIVEREF(__pyx_t_14);
+                      __pyx_cur_scope->__pyx_t_5 = __pyx_t_14;
+                      __Pyx_XGIVEREF(__pyx_t_15);
+                      __pyx_cur_scope->__pyx_t_6 = __pyx_t_15;
+                      __Pyx_XGIVEREF(__pyx_r);
+                      __Pyx_RefNannyFinishContext();
+                      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+                      /* return from generator, awaiting value */
+                      __pyx_generator->resume_label = 4;
+                      return __pyx_r;
+                      __pyx_L57_resume_from_await:;
+                      __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+                      __pyx_cur_scope->__pyx_t_0 = 0;
+                      __Pyx_XGOTREF(__pyx_t_6);
+                      __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+                      __pyx_cur_scope->__pyx_t_1 = 0;
+                      __Pyx_XGOTREF(__pyx_t_7);
+                      __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+                      __pyx_cur_scope->__pyx_t_2 = 0;
+                      __Pyx_XGOTREF(__pyx_t_8);
+                      __pyx_t_9 = __pyx_cur_scope->__pyx_t_3;
+                      __pyx_cur_scope->__pyx_t_3 = 0;
+                      __Pyx_XGOTREF(__pyx_t_9);
+                      __pyx_t_13 = __pyx_cur_scope->__pyx_t_4;
+                      __pyx_cur_scope->__pyx_t_4 = 0;
+                      __Pyx_XGOTREF(__pyx_t_13);
+                      __pyx_t_14 = __pyx_cur_scope->__pyx_t_5;
+                      __pyx_cur_scope->__pyx_t_5 = 0;
+                      __Pyx_XGOTREF(__pyx_t_14);
+                      __pyx_t_15 = __pyx_cur_scope->__pyx_t_6;
+                      __pyx_cur_scope->__pyx_t_6 = 0;
+                      __Pyx_XGOTREF(__pyx_t_15);
+                      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 349, __pyx_L49_error)
+                    } else {
+                      PyObject* exc_type = __Pyx_PyErr_Occurred();
+                      if (exc_type) {
+                        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+                        else __PYX_ERR(0, 349, __pyx_L49_error)
+                      }
+                    }
+
+                    /* "asyncpg/protocol/protocol.pyx":348
+ *                 if buffer:
+ *                     try:
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await asyncio.wait_for(
+ *                                 sink(buffer),
+ */
+                  }
+                  __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+                  __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                  __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
+                  goto __pyx_L56_try_end;
+                  __pyx_L49_error:;
+                  __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                  __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+                  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+                  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                  /*except:*/ {
+                    __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+                    if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 348, __pyx_L51_except_error)
+                    __Pyx_GOTREF(__pyx_t_3);
+                    __Pyx_GOTREF(__pyx_t_5);
+                    __Pyx_GOTREF(__pyx_t_4);
+                    __pyx_t_10 = PyTuple_Pack(3, __pyx_t_3, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 348, __pyx_L51_except_error)
+                    __Pyx_GOTREF(__pyx_t_10);
+                    __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, NULL);
+                    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+                    if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 348, __pyx_L51_except_error)
+                    __Pyx_GOTREF(__pyx_t_17);
+                    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_17);
+                    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
+                    if (__pyx_t_2 < 0) __PYX_ERR(0, 348, __pyx_L51_except_error)
+                    __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0);
+                    if (__pyx_t_1) {
+                      __Pyx_GIVEREF(__pyx_t_3);
+                      __Pyx_GIVEREF(__pyx_t_5);
+                      __Pyx_XGIVEREF(__pyx_t_4);
+                      __Pyx_ErrRestoreWithState(__pyx_t_3, __pyx_t_5, __pyx_t_4);
+                      __pyx_t_3 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; 
+                      __PYX_ERR(0, 348, __pyx_L51_except_error)
+                    }
+                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+                    goto __pyx_L50_exception_handled;
+                  }
+                  __pyx_L51_except_error:;
+                  __Pyx_XGIVEREF(__pyx_t_13);
+                  __Pyx_XGIVEREF(__pyx_t_14);
+                  __Pyx_XGIVEREF(__pyx_t_15);
+                  __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
+                  goto __pyx_L35_error;
+                  __pyx_L50_exception_handled:;
+                  __Pyx_XGIVEREF(__pyx_t_13);
+                  __Pyx_XGIVEREF(__pyx_t_14);
+                  __Pyx_XGIVEREF(__pyx_t_15);
+                  __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
+                  __pyx_L56_try_end:;
+                }
+              }
+              /*finally:*/ {
+                /*normal exit:*/{
+                  if (__pyx_t_7) {
+                    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__31, NULL);
+                    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+                    if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 348, __pyx_L35_error)
+                    __Pyx_GOTREF(__pyx_t_15);
+                    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+                  }
+                  goto __pyx_L48;
+                }
+                __pyx_L48:;
+              }
+              goto __pyx_L61;
+              __pyx_L43_error:;
+              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+              goto __pyx_L35_error;
+              __pyx_L61:;
+            }
+
+            /* "asyncpg/protocol/protocol.pyx":347
+ *                 # the last CopyData message.
+ *                 if buffer:
+ *                     try:             # <<<<<<<<<<<<<<
+ *                         with timer:
+ *                             await asyncio.wait_for(
+ */
+          }
+          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+          goto __pyx_L42_try_end;
+          __pyx_L35_error:;
+          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":353
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)
+ *                     except Exception as ex:             # <<<<<<<<<<<<<<
+ *                         # Abort the COPY operation on any error in
+ *                         # output sink.
+ */
+          __pyx_t_18 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+          if (__pyx_t_18) {
+            __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+            if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_3) < 0) __PYX_ERR(0, 353, __pyx_L37_except_error)
+            __Pyx_GOTREF(__pyx_t_4);
+            __Pyx_GOTREF(__pyx_t_5);
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_INCREF(__pyx_t_5);
+            __Pyx_GIVEREF(__pyx_t_5);
+            __pyx_cur_scope->__pyx_v_ex = __pyx_t_5;
+            /*try:*/ {
+
+              /* "asyncpg/protocol/protocol.pyx":356
+ *                         # Abort the COPY operation on any error in
+ *                         # output sink.
+ *                         self._request_cancel()             # <<<<<<<<<<<<<<
+ *                         # Make asyncio shut up about unretrieved
+ *                         # QueryCanceledError
+ */
+              __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_request_cancel); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 356, __pyx_L67_error)
+              __Pyx_GOTREF(__pyx_t_11);
+              __pyx_t_16 = NULL;
+              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+                __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_11);
+                if (likely(__pyx_t_16)) {
+                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+                  __Pyx_INCREF(__pyx_t_16);
+                  __Pyx_INCREF(function);
+                  __Pyx_DECREF_SET(__pyx_t_11, function);
+                }
+              }
+              __pyx_t_10 = (__pyx_t_16) ? __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_16) : __Pyx_PyObject_CallNoArg(__pyx_t_11);
+              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+              if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 356, __pyx_L67_error)
+              __Pyx_GOTREF(__pyx_t_10);
+              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+              /* "asyncpg/protocol/protocol.pyx":359
+ *                         # Make asyncio shut up about unretrieved
+ *                         # QueryCanceledError
+ *                         waiter.add_done_callback(lambda f: f.exception())             # <<<<<<<<<<<<<<
+ *                         raise
+ * 
+ */
+              __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_add_done_callback); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 359, __pyx_L67_error)
+              __Pyx_GOTREF(__pyx_t_11);
+              __pyx_t_16 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_12BaseProtocol_8copy_out_lambda1, 0, __pyx_n_s_copy_out_locals_lambda, NULL, __pyx_n_s_asyncpg_protocol_protocol, __pyx_d, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 359, __pyx_L67_error)
+              __Pyx_GOTREF(__pyx_t_16);
+              __pyx_t_19 = NULL;
+              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+                __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_11);
+                if (likely(__pyx_t_19)) {
+                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+                  __Pyx_INCREF(__pyx_t_19);
+                  __Pyx_INCREF(function);
+                  __Pyx_DECREF_SET(__pyx_t_11, function);
+                }
+              }
+              __pyx_t_10 = (__pyx_t_19) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_19, __pyx_t_16) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_16);
+              __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
+              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+              if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 359, __pyx_L67_error)
+              __Pyx_GOTREF(__pyx_t_10);
+              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+              /* "asyncpg/protocol/protocol.pyx":360
+ *                         # QueryCanceledError
+ *                         waiter.add_done_callback(lambda f: f.exception())
+ *                         raise             # <<<<<<<<<<<<<<
+ * 
+ *                 # done will be True upon receipt of CopyDone.
+ */
+              __Pyx_GIVEREF(__pyx_t_4);
+              __Pyx_GIVEREF(__pyx_t_5);
+              __Pyx_XGIVEREF(__pyx_t_3);
+              __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_5, __pyx_t_3);
+              __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_3 = 0; 
+              __PYX_ERR(0, 360, __pyx_L67_error)
+            }
+
+            /* "asyncpg/protocol/protocol.pyx":353
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)
+ *                     except Exception as ex:             # <<<<<<<<<<<<<<
+ *                         # Abort the COPY operation on any error in
+ *                         # output sink.
+ */
+            /*finally:*/ {
+              __pyx_L67_error:;
+              /*exception exit:*/{
+                __Pyx_PyThreadState_assign
+                __pyx_t_7 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_13 = 0; __pyx_t_17 = 0; __pyx_t_22 = 0;
+                __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
+                __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+                if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_17, &__pyx_t_22);
+                if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_15, &__pyx_t_14) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_15, &__pyx_t_14);
+                __Pyx_XGOTREF(__pyx_t_7);
+                __Pyx_XGOTREF(__pyx_t_15);
+                __Pyx_XGOTREF(__pyx_t_14);
+                __Pyx_XGOTREF(__pyx_t_13);
+                __Pyx_XGOTREF(__pyx_t_17);
+                __Pyx_XGOTREF(__pyx_t_22);
+                __pyx_t_18 = __pyx_lineno; __pyx_t_20 = __pyx_clineno; __pyx_t_21 = __pyx_filename;
+                {
+                  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+                  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+                  __pyx_cur_scope->__pyx_v_ex = NULL;
+                }
+                if (PY_MAJOR_VERSION >= 3) {
+                  __Pyx_XGIVEREF(__pyx_t_13);
+                  __Pyx_XGIVEREF(__pyx_t_17);
+                  __Pyx_XGIVEREF(__pyx_t_22);
+                  __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_17, __pyx_t_22);
+                }
+                __Pyx_XGIVEREF(__pyx_t_7);
+                __Pyx_XGIVEREF(__pyx_t_15);
+                __Pyx_XGIVEREF(__pyx_t_14);
+                __Pyx_ErrRestore(__pyx_t_7, __pyx_t_15, __pyx_t_14);
+                __pyx_t_7 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_13 = 0; __pyx_t_17 = 0; __pyx_t_22 = 0;
+                __pyx_lineno = __pyx_t_18; __pyx_clineno = __pyx_t_20; __pyx_filename = __pyx_t_21;
+                goto __pyx_L37_except_error;
+              }
+            }
+          }
+          goto __pyx_L37_except_error;
+          __pyx_L37_except_error:;
+
+          /* "asyncpg/protocol/protocol.pyx":347
+ *                 # the last CopyData message.
+ *                 if buffer:
+ *                     try:             # <<<<<<<<<<<<<<
+ *                         with timer:
+ *                             await asyncio.wait_for(
+ */
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __Pyx_XGIVEREF(__pyx_t_9);
+          __Pyx_XGIVEREF(__pyx_t_8);
+          __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_9, __pyx_t_8);
+          goto __pyx_L9_error;
+          __pyx_L42_try_end:;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":346
+ *                 # buffer will be empty if CopyDone was received apart from
+ *                 # the last CopyData message.
+ *                 if buffer:             # <<<<<<<<<<<<<<
+ *                     try:
+ *                         with timer:
+ */
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":363
+ * 
+ *                 # done will be True upon receipt of CopyDone.
+ *                 if done:             # <<<<<<<<<<<<<<
+ *                     break
+ * 
+ */
+      if (unlikely(!__pyx_cur_scope->__pyx_v_done)) { __Pyx_RaiseUnboundLocalError("done"); __PYX_ERR(0, 363, __pyx_L9_error) }
+      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_done); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 363, __pyx_L9_error)
+      if (__pyx_t_1) {
+
+        /* "asyncpg/protocol/protocol.pyx":364
+ *                 # done will be True upon receipt of CopyDone.
+ *                 if done:
+ *                     break             # <<<<<<<<<<<<<<
+ * 
+ *                 waiter = self._new_waiter(timer.get_remaining_budget())
+ */
+        goto __pyx_L12_break;
+
+        /* "asyncpg/protocol/protocol.pyx":363
+ * 
+ *                 # done will be True upon receipt of CopyDone.
+ *                 if done:             # <<<<<<<<<<<<<<
+ *                     break
+ * 
+ */
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":366
+ *                     break
+ * 
+ *                 waiter = self._new_waiter(timer.get_remaining_budget())             # <<<<<<<<<<<<<<
+ * 
+ *         finally:
+ */
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_get_remaining_budget); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 366, __pyx_L9_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L9_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 366, __pyx_L9_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_waiter, __pyx_t_5);
+      __Pyx_GIVEREF(__pyx_t_5);
+      __pyx_t_5 = 0;
+    }
+    __pyx_L12_break:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":369
+ * 
+ *         finally:
+ *             self.resume_reading()             # <<<<<<<<<<<<<<
+ * 
+ *         return status_msg
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __pyx_t_5 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 369, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      goto __pyx_L10;
+    }
+    __pyx_L9_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_6 = 0; __pyx_t_22 = 0; __pyx_t_17 = 0; __pyx_t_13 = 0;
+      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
+      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_22, &__pyx_t_17, &__pyx_t_13);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_8, &__pyx_t_9, &__pyx_t_6) < 0)) __Pyx_ErrFetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_22);
+      __Pyx_XGOTREF(__pyx_t_17);
+      __Pyx_XGOTREF(__pyx_t_13);
+      __pyx_t_20 = __pyx_lineno; __pyx_t_18 = __pyx_clineno; __pyx_t_23 = __pyx_filename;
+      {
+        __pyx_t_5 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 369, __pyx_L75_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_22);
+        __Pyx_XGIVEREF(__pyx_t_17);
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_17, __pyx_t_13);
+      }
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_XGIVEREF(__pyx_t_9);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ErrRestore(__pyx_t_8, __pyx_t_9, __pyx_t_6);
+      __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_6 = 0; __pyx_t_22 = 0; __pyx_t_17 = 0; __pyx_t_13 = 0;
+      __pyx_lineno = __pyx_t_20; __pyx_clineno = __pyx_t_18; __pyx_filename = __pyx_t_23;
+      goto __pyx_L1_error;
+      __pyx_L75_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_22);
+        __Pyx_XGIVEREF(__pyx_t_17);
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_17, __pyx_t_13);
+      }
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __pyx_t_22 = 0; __pyx_t_17 = 0; __pyx_t_13 = 0;
+      goto __pyx_L1_error;
+    }
+    __pyx_L10:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":371
+ *             self.resume_reading()
+ * 
+ *         return status_msg             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  __Pyx_XDECREF(__pyx_r);
+  if (unlikely(!__pyx_cur_scope->__pyx_v_status_msg)) { __Pyx_RaiseUnboundLocalError("status_msg"); __PYX_ERR(0, 371, __pyx_L1_error) }
+  __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_cur_scope->__pyx_v_status_msg);
+  goto __pyx_L0;
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":319
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_out(self, copy_stmt, sink, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_XDECREF(__pyx_t_19);
+  __Pyx_AddTraceback("copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_33generator7(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":374
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_in(self, copy_stmt, reader, data,             # <<<<<<<<<<<<<<
+ *                       records, PreparedStatementState record_stmt, timeout):
+ *         cdef:
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_32copy_in(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_32copy_in(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_copy_stmt = 0;
+  PyObject *__pyx_v_reader = 0;
+  PyObject *__pyx_v_data = 0;
+  PyObject *__pyx_v_records = 0;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_record_stmt = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("copy_in (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_copy_stmt,&__pyx_n_s_reader,&__pyx_n_s_data,&__pyx_n_s_records,&__pyx_n_s_record_stmt,&__pyx_n_s_timeout,0};
+    PyObject* values[6] = {0,0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+        CYTHON_FALLTHROUGH;
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        CYTHON_FALLTHROUGH;
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_copy_stmt)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reader)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_in", 1, 6, 6, 1); __PYX_ERR(0, 374, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_in", 1, 6, 6, 2); __PYX_ERR(0, 374, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_records)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_in", 1, 6, 6, 3); __PYX_ERR(0, 374, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  4:
+        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_record_stmt)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_in", 1, 6, 6, 4); __PYX_ERR(0, 374, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  5:
+        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("copy_in", 1, 6, 6, 5); __PYX_ERR(0, 374, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "copy_in") < 0)) __PYX_ERR(0, 374, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
+    }
+    __pyx_v_copy_stmt = values[0];
+    __pyx_v_reader = values[1];
+    __pyx_v_data = values[2];
+    __pyx_v_records = values[3];
+    __pyx_v_record_stmt = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[4]);
+    __pyx_v_timeout = values[5];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("copy_in", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 374, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_record_stmt), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "record_stmt", 0))) __PYX_ERR(0, 375, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_31copy_in(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_copy_stmt, __pyx_v_reader, __pyx_v_data, __pyx_v_records, __pyx_v_record_stmt, __pyx_v_timeout);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":483
+ *             self._request_cancel()
+ *             # Make asyncio shut up about unretrieved QueryCanceledError
+ *             waiter.add_done_callback(lambda f: f.exception())             # <<<<<<<<<<<<<<
+ *             raise
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_7copy_in_lambda2(PyObject *__pyx_self, PyObject *__pyx_v_f); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_12BaseProtocol_7copy_in_lambda2 = {"lambda2", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_7copy_in_lambda2, METH_O, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_7copy_in_lambda2(PyObject *__pyx_self, PyObject *__pyx_v_f) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("lambda2 (wrapper)", 0);
+  __pyx_r = __pyx_lambda_funcdef_lambda2(__pyx_self, ((PyObject *)__pyx_v_f));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_lambda_funcdef_lambda2(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("lambda2", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_exception); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 483, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in.lambda2", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":374
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_in(self, copy_stmt, reader, data,             # <<<<<<<<<<<<<<
+ *                       records, PreparedStatementState record_stmt, timeout):
+ *         cdef:
+ */
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_31copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_copy_stmt, PyObject *__pyx_v_reader, PyObject *__pyx_v_data, PyObject *__pyx_v_records, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_record_stmt, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("copy_in", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 374, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_copy_stmt = __pyx_v_copy_stmt;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_copy_stmt);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_copy_stmt);
+  __pyx_cur_scope->__pyx_v_reader = __pyx_v_reader;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_reader);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_reader);
+  __pyx_cur_scope->__pyx_v_data = __pyx_v_data;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_data);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_data);
+  __pyx_cur_scope->__pyx_v_records = __pyx_v_records;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_records);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_records);
+  __pyx_cur_scope->__pyx_v_record_stmt = __pyx_v_record_stmt;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_record_stmt);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_record_stmt);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_33generator7, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_copy_in, __pyx_n_s_BaseProtocol_copy_in, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 374, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_33generator7(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  Py_ssize_t __pyx_t_9;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  int __pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *(*__pyx_t_17)(PyObject *);
+  Py_ssize_t __pyx_t_18;
+  Py_ssize_t __pyx_t_19;
+  Py_ssize_t __pyx_t_20;
+  PyObject *__pyx_t_21;
+  PyObject *__pyx_t_22 = NULL;
+  PyObject *__pyx_t_23 = NULL;
+  PyObject *__pyx_t_24 = NULL;
+  PyObject *__pyx_t_25 = NULL;
+  PyObject *__pyx_t_26 = NULL;
+  PyObject *__pyx_t_27 = NULL;
+  PyObject *__pyx_t_28 = NULL;
+  PyObject *__pyx_t_29 = NULL;
+  int __pyx_t_30;
+  char const *__pyx_t_31;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("copy_in", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L40_resume_from_await;
+    case 4: goto __pyx_L75_resume_from_await;
+    case 5: goto __pyx_L94_resume_from_await;
+    case 6: goto __pyx_L99_resume_from_await;
+    case 7: goto __pyx_L110_resume_from_await;
+    case 8: goto __pyx_L124_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 374, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":381
+ *             Codec codec
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":382
+ * 
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 382, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 382, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":381
+ *             Codec codec
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":383
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":384
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 384, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 384, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":385
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":383
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":387
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 387, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":389
+ *         self._check_state()
+ * 
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ *         timer = Timer(timeout)
+ * 
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 389, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":390
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ *         timer = Timer(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         waiter = self._new_waiter(timer.get_remaining_budget())
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_Timer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 390, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_cur_scope->__pyx_v_timeout) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_timer = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":392
+ *         timer = Timer(timeout)
+ * 
+ *         waiter = self._new_waiter(timer.get_remaining_budget())             # <<<<<<<<<<<<<<
+ * 
+ *         # Initiate COPY IN.
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_get_remaining_budget); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 392, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 392, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_GIVEREF(__pyx_t_4);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_4;
+  __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":395
+ * 
+ *         # Initiate COPY IN.
+ *         self._copy_in(copy_stmt)             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+  if (!(likely(PyUnicode_CheckExact(__pyx_cur_scope->__pyx_v_copy_stmt))||((__pyx_cur_scope->__pyx_v_copy_stmt) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_cur_scope->__pyx_v_copy_stmt)->tp_name), 0))) __PYX_ERR(0, 395, __pyx_L1_error)
+  __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._copy_in(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject*)__pyx_cur_scope->__pyx_v_copy_stmt)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 395, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":397
+ *         self._copy_in(copy_stmt)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             if record_stmt is not None:
+ *                 # copy_in_records in binary mode
+ */
+  {
+    __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
+    __Pyx_XGOTREF(__pyx_t_6);
+    __Pyx_XGOTREF(__pyx_t_7);
+    __Pyx_XGOTREF(__pyx_t_8);
+    /*try:*/ {
+
+      /* "asyncpg/protocol/protocol.pyx":398
+ * 
+ *         try:
+ *             if record_stmt is not None:             # <<<<<<<<<<<<<<
+ *                 # copy_in_records in binary mode
+ *                 wbuf = WriteBuffer.new()
+ */
+      __pyx_t_1 = (((PyObject *)__pyx_cur_scope->__pyx_v_record_stmt) != Py_None);
+      __pyx_t_2 = (__pyx_t_1 != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/protocol.pyx":400
+ *             if record_stmt is not None:
+ *                 # copy_in_records in binary mode
+ *                 wbuf = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ *                 # Signature
+ *                 wbuf.write_bytes(_COPY_SIGNATURE)
+ */
+        __pyx_t_4 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 400, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_GIVEREF(__pyx_t_4);
+        __pyx_cur_scope->__pyx_v_wbuf = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_4);
+        __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":402
+ *                 wbuf = WriteBuffer.new()
+ *                 # Signature
+ *                 wbuf.write_bytes(_COPY_SIGNATURE)             # <<<<<<<<<<<<<<
+ *                 # Flags field
+ *                 wbuf.write_int32(0)
+ */
+        __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_wbuf->__pyx_vtab)->write_bytes(__pyx_cur_scope->__pyx_v_wbuf, __pyx_kp_b_PGCOPY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 402, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":404
+ *                 wbuf.write_bytes(_COPY_SIGNATURE)
+ *                 # Flags field
+ *                 wbuf.write_int32(0)             # <<<<<<<<<<<<<<
+ *                 # No header extension
+ *                 wbuf.write_int32(0)
+ */
+        __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_wbuf->__pyx_vtab)->write_int32(__pyx_cur_scope->__pyx_v_wbuf, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 404, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":406
+ *                 wbuf.write_int32(0)
+ *                 # No header extension
+ *                 wbuf.write_int32(0)             # <<<<<<<<<<<<<<
+ * 
+ *                 record_stmt._ensure_rows_decoder()
+ */
+        __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_wbuf->__pyx_vtab)->write_int32(__pyx_cur_scope->__pyx_v_wbuf, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 406, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":408
+ *                 wbuf.write_int32(0)
+ * 
+ *                 record_stmt._ensure_rows_decoder()             # <<<<<<<<<<<<<<
+ *                 codecs = record_stmt.rows_codecs
+ *                 num_cols = len(codecs)
+ */
+        __pyx_t_4 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_rows_decoder(__pyx_cur_scope->__pyx_v_record_stmt); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 408, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":409
+ * 
+ *                 record_stmt._ensure_rows_decoder()
+ *                 codecs = record_stmt.rows_codecs             # <<<<<<<<<<<<<<
+ *                 num_cols = len(codecs)
+ *                 settings = self.settings
+ */
+        __pyx_t_4 = __pyx_cur_scope->__pyx_v_record_stmt->rows_codecs;
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_GIVEREF(__pyx_t_4);
+        __pyx_cur_scope->__pyx_v_codecs = ((PyObject*)__pyx_t_4);
+        __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":410
+ *                 record_stmt._ensure_rows_decoder()
+ *                 codecs = record_stmt.rows_codecs
+ *                 num_cols = len(codecs)             # <<<<<<<<<<<<<<
+ *                 settings = self.settings
+ * 
+ */
+        if (unlikely(__pyx_cur_scope->__pyx_v_codecs == Py_None)) {
+          PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+          __PYX_ERR(0, 410, __pyx_L8_error)
+        }
+        __pyx_t_9 = PyTuple_GET_SIZE(__pyx_cur_scope->__pyx_v_codecs); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 410, __pyx_L8_error)
+        __pyx_cur_scope->__pyx_v_num_cols = __pyx_t_9;
+
+        /* "asyncpg/protocol/protocol.pyx":411
+ *                 codecs = record_stmt.rows_codecs
+ *                 num_cols = len(codecs)
+ *                 settings = self.settings             # <<<<<<<<<<<<<<
+ * 
+ *                 for codec in codecs:
+ */
+        __pyx_t_4 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->settings);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_GIVEREF(__pyx_t_4);
+        __pyx_cur_scope->__pyx_v_settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_t_4);
+        __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":413
+ *                 settings = self.settings
+ * 
+ *                 for codec in codecs:             # <<<<<<<<<<<<<<
+ *                     if (not codec.has_encoder() or
+ *                             codec.format != PG_FORMAT_BINARY):
+ */
+        if (unlikely(__pyx_cur_scope->__pyx_v_codecs == Py_None)) {
+          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+          __PYX_ERR(0, 413, __pyx_L8_error)
+        }
+        __pyx_t_4 = __pyx_cur_scope->__pyx_v_codecs; __Pyx_INCREF(__pyx_t_4); __pyx_t_9 = 0;
+        for (;;) {
+          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 413, __pyx_L8_error)
+          #else
+          __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 413, __pyx_L8_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          #endif
+          if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_7asyncpg_8protocol_8protocol_Codec))))) __PYX_ERR(0, 413, __pyx_L8_error)
+          __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_codec));
+          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+          __Pyx_GIVEREF(__pyx_t_3);
+          __pyx_t_3 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":414
+ * 
+ *                 for codec in codecs:
+ *                     if (not codec.has_encoder() or             # <<<<<<<<<<<<<<
+ *                             codec.format != PG_FORMAT_BINARY):
+ *                         raise apg_exc.InternalClientError(
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder(__pyx_cur_scope->__pyx_v_codec); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 414, __pyx_L8_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 414, __pyx_L8_error)
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __pyx_t_10 = ((!__pyx_t_1) != 0);
+          if (!__pyx_t_10) {
+          } else {
+            __pyx_t_2 = __pyx_t_10;
+            goto __pyx_L18_bool_binop_done;
+          }
+
+          /* "asyncpg/protocol/protocol.pyx":415
+ *                 for codec in codecs:
+ *                     if (not codec.has_encoder() or
+ *                             codec.format != PG_FORMAT_BINARY):             # <<<<<<<<<<<<<<
+ *                         raise apg_exc.InternalClientError(
+ *                             'no binary format encoder for '
+ */
+          __pyx_t_10 = ((__pyx_cur_scope->__pyx_v_codec->format != __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_BINARY) != 0);
+          __pyx_t_2 = __pyx_t_10;
+          __pyx_L18_bool_binop_done:;
+
+          /* "asyncpg/protocol/protocol.pyx":414
+ * 
+ *                 for codec in codecs:
+ *                     if (not codec.has_encoder() or             # <<<<<<<<<<<<<<
+ *                             codec.format != PG_FORMAT_BINARY):
+ *                         raise apg_exc.InternalClientError(
+ */
+          if (unlikely(__pyx_t_2)) {
+
+            /* "asyncpg/protocol/protocol.pyx":416
+ *                     if (not codec.has_encoder() or
+ *                             codec.format != PG_FORMAT_BINARY):
+ *                         raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                             'no binary format encoder for '
+ *                             'type {} (OID {})'.format(codec.name, codec.oid))
+ */
+            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 416, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_5);
+            __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 416, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_11);
+            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+            /* "asyncpg/protocol/protocol.pyx":418
+ *                         raise apg_exc.InternalClientError(
+ *                             'no binary format encoder for '
+ *                             'type {} (OID {})'.format(codec.name, codec.oid))             # <<<<<<<<<<<<<<
+ * 
+ *                 for row in records:
+ */
+            __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_no_binary_format_encoder_for_typ, __pyx_n_s_format); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 418, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_12);
+            __pyx_t_13 = __Pyx_PyInt_From_uint32_t(__pyx_cur_scope->__pyx_v_codec->oid); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 418, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_13);
+            __pyx_t_14 = NULL;
+            __pyx_t_15 = 0;
+            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
+              __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12);
+              if (likely(__pyx_t_14)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
+                __Pyx_INCREF(__pyx_t_14);
+                __Pyx_INCREF(function);
+                __Pyx_DECREF_SET(__pyx_t_12, function);
+                __pyx_t_15 = 1;
+              }
+            }
+            #if CYTHON_FAST_PYCALL
+            if (PyFunction_Check(__pyx_t_12)) {
+              PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_cur_scope->__pyx_v_codec->name, __pyx_t_13};
+              __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 418, __pyx_L8_error)
+              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+            } else
+            #endif
+            #if CYTHON_FAST_PYCCALL
+            if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
+              PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_cur_scope->__pyx_v_codec->name, __pyx_t_13};
+              __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 418, __pyx_L8_error)
+              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+            } else
+            #endif
+            {
+              __pyx_t_16 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 418, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_16);
+              if (__pyx_t_14) {
+                __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL;
+              }
+              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_codec->name);
+              __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_codec->name);
+              PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_15, __pyx_cur_scope->__pyx_v_codec->name);
+              __Pyx_GIVEREF(__pyx_t_13);
+              PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_15, __pyx_t_13);
+              __pyx_t_13 = 0;
+              __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_16, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 418, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+            }
+            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __pyx_t_12 = NULL;
+            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
+              __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+              if (likely(__pyx_t_12)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+                __Pyx_INCREF(__pyx_t_12);
+                __Pyx_INCREF(function);
+                __Pyx_DECREF_SET(__pyx_t_11, function);
+              }
+            }
+            __pyx_t_3 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_5);
+            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+            if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 416, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+            __PYX_ERR(0, 416, __pyx_L8_error)
+
+            /* "asyncpg/protocol/protocol.pyx":414
+ * 
+ *                 for codec in codecs:
+ *                     if (not codec.has_encoder() or             # <<<<<<<<<<<<<<
+ *                             codec.format != PG_FORMAT_BINARY):
+ *                         raise apg_exc.InternalClientError(
+ */
+          }
+
+          /* "asyncpg/protocol/protocol.pyx":413
+ *                 settings = self.settings
+ * 
+ *                 for codec in codecs:             # <<<<<<<<<<<<<<
+ *                     if (not codec.has_encoder() or
+ *                             codec.format != PG_FORMAT_BINARY):
+ */
+        }
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":420
+ *                             'type {} (OID {})'.format(codec.name, codec.oid))
+ * 
+ *                 for row in records:             # <<<<<<<<<<<<<<
+ *                     # Tuple header
+ *                     wbuf.write_int16(<int16_t>num_cols)
+ */
+        if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_records)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_records)) {
+          __pyx_t_4 = __pyx_cur_scope->__pyx_v_records; __Pyx_INCREF(__pyx_t_4); __pyx_t_9 = 0;
+          __pyx_t_17 = NULL;
+        } else {
+          __pyx_t_9 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_records); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 420, __pyx_L8_error)
+          __Pyx_GOTREF(__pyx_t_4);
+          __pyx_t_17 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 420, __pyx_L8_error)
+        }
+        for (;;) {
+          if (likely(!__pyx_t_17)) {
+            if (likely(PyList_CheckExact(__pyx_t_4))) {
+              if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_4)) break;
+              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+              __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 420, __pyx_L8_error)
+              #else
+              __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 420, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_3);
+              #endif
+            } else {
+              if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+              __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 420, __pyx_L8_error)
+              #else
+              __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 420, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_3);
+              #endif
+            }
+          } else {
+            __pyx_t_3 = __pyx_t_17(__pyx_t_4);
+            if (unlikely(!__pyx_t_3)) {
+              PyObject* exc_type = PyErr_Occurred();
+              if (exc_type) {
+                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+                else __PYX_ERR(0, 420, __pyx_L8_error)
+              }
+              break;
+            }
+            __Pyx_GOTREF(__pyx_t_3);
+          }
+          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_row);
+          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_row, __pyx_t_3);
+          __Pyx_GIVEREF(__pyx_t_3);
+          __pyx_t_3 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":422
+ *                 for row in records:
+ *                     # Tuple header
+ *                     wbuf.write_int16(<int16_t>num_cols)             # <<<<<<<<<<<<<<
+ *                     # Tuple data
+ *                     for i in range(num_cols):
+ */
+          __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_wbuf->__pyx_vtab)->write_int16(__pyx_cur_scope->__pyx_v_wbuf, ((int16_t)__pyx_cur_scope->__pyx_v_num_cols)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 422, __pyx_L8_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":424
+ *                     wbuf.write_int16(<int16_t>num_cols)
+ *                     # Tuple data
+ *                     for i in range(num_cols):             # <<<<<<<<<<<<<<
+ *                         item = row[i]
+ *                         if item is None:
+ */
+          __pyx_t_18 = __pyx_cur_scope->__pyx_v_num_cols;
+          __pyx_t_19 = __pyx_t_18;
+          for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
+            __pyx_cur_scope->__pyx_v_i = __pyx_t_20;
+
+            /* "asyncpg/protocol/protocol.pyx":425
+ *                     # Tuple data
+ *                     for i in range(num_cols):
+ *                         item = row[i]             # <<<<<<<<<<<<<<
+ *                         if item is None:
+ *                             wbuf.write_int32(-1)
+ */
+            __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_row, __pyx_cur_scope->__pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 425, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_item);
+            __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_item, __pyx_t_3);
+            __Pyx_GIVEREF(__pyx_t_3);
+            __pyx_t_3 = 0;
+
+            /* "asyncpg/protocol/protocol.pyx":426
+ *                     for i in range(num_cols):
+ *                         item = row[i]
+ *                         if item is None:             # <<<<<<<<<<<<<<
+ *                             wbuf.write_int32(-1)
+ *                         else:
+ */
+            __pyx_t_2 = (__pyx_cur_scope->__pyx_v_item == Py_None);
+            __pyx_t_10 = (__pyx_t_2 != 0);
+            if (__pyx_t_10) {
+
+              /* "asyncpg/protocol/protocol.pyx":427
+ *                         item = row[i]
+ *                         if item is None:
+ *                             wbuf.write_int32(-1)             # <<<<<<<<<<<<<<
+ *                         else:
+ *                             codec = <Codec>cpython.PyTuple_GET_ITEM(codecs, i)
+ */
+              __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_wbuf->__pyx_vtab)->write_int32(__pyx_cur_scope->__pyx_v_wbuf, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 427, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_3);
+              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+              /* "asyncpg/protocol/protocol.pyx":426
+ *                     for i in range(num_cols):
+ *                         item = row[i]
+ *                         if item is None:             # <<<<<<<<<<<<<<
+ *                             wbuf.write_int32(-1)
+ *                         else:
+ */
+              goto __pyx_L24;
+            }
+
+            /* "asyncpg/protocol/protocol.pyx":429
+ *                             wbuf.write_int32(-1)
+ *                         else:
+ *                             codec = <Codec>cpython.PyTuple_GET_ITEM(codecs, i)             # <<<<<<<<<<<<<<
+ *                             codec.encode(settings, wbuf, item)
+ * 
+ */
+            /*else*/ {
+              __pyx_t_21 = PyTuple_GET_ITEM(__pyx_cur_scope->__pyx_v_codecs, __pyx_cur_scope->__pyx_v_i);
+              __pyx_t_3 = ((PyObject *)__pyx_t_21);
+              __Pyx_INCREF(__pyx_t_3);
+              __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_codec));
+              __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_codec, ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)__pyx_t_3));
+              __Pyx_GIVEREF(__pyx_t_3);
+              __pyx_t_3 = 0;
+
+              /* "asyncpg/protocol/protocol.pyx":430
+ *                         else:
+ *                             codec = <Codec>cpython.PyTuple_GET_ITEM(codecs, i)
+ *                             codec.encode(settings, wbuf, item)             # <<<<<<<<<<<<<<
+ * 
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:
+ */
+              __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode(__pyx_cur_scope->__pyx_v_codec, __pyx_cur_scope->__pyx_v_settings, __pyx_cur_scope->__pyx_v_wbuf, __pyx_cur_scope->__pyx_v_item); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 430, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_3);
+              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+            }
+            __pyx_L24:;
+          }
+
+          /* "asyncpg/protocol/protocol.pyx":432
+ *                             codec.encode(settings, wbuf, item)
+ * 
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:             # <<<<<<<<<<<<<<
+ *                         with timer:
+ *                             await self.writing_allowed.wait()
+ */
+          __pyx_t_3 = __pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(__pyx_cur_scope->__pyx_v_wbuf); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 432, __pyx_L8_error)
+          __Pyx_GOTREF(__pyx_t_3);
+          __pyx_t_11 = PyObject_RichCompare(__pyx_t_3, __pyx_int_524288, Py_GE); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 432, __pyx_L8_error)
+          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 432, __pyx_L8_error)
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+          if (__pyx_t_10) {
+
+            /* "asyncpg/protocol/protocol.pyx":433
+ * 
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await self.writing_allowed.wait()
+ *                         self._write_copy_data_msg(wbuf)
+ */
+            /*with:*/ {
+              __pyx_t_22 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_exit); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 433, __pyx_L8_error)
+              __Pyx_GOTREF(__pyx_t_22);
+              __pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_enter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 433, __pyx_L26_error)
+              __Pyx_GOTREF(__pyx_t_3);
+              __pyx_t_5 = NULL;
+              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+                __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+                if (likely(__pyx_t_5)) {
+                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+                  __Pyx_INCREF(__pyx_t_5);
+                  __Pyx_INCREF(function);
+                  __Pyx_DECREF_SET(__pyx_t_3, function);
+                }
+              }
+              __pyx_t_11 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+              if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 433, __pyx_L26_error)
+              __Pyx_GOTREF(__pyx_t_11);
+              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+              /*try:*/ {
+                {
+                  __Pyx_ExceptionSave(&__pyx_t_23, &__pyx_t_24, &__pyx_t_25);
+                  __Pyx_XGOTREF(__pyx_t_23);
+                  __Pyx_XGOTREF(__pyx_t_24);
+                  __Pyx_XGOTREF(__pyx_t_25);
+                  /*try:*/ {
+
+                    /* "asyncpg/protocol/protocol.pyx":434
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:
+ *                         with timer:
+ *                             await self.writing_allowed.wait()             # <<<<<<<<<<<<<<
+ *                         self._write_copy_data_msg(wbuf)
+ *                         wbuf = WriteBuffer.new()
+ */
+                    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_writing_allowed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 434, __pyx_L32_error)
+                    __Pyx_GOTREF(__pyx_t_3);
+                    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wait); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 434, __pyx_L32_error)
+                    __Pyx_GOTREF(__pyx_t_5);
+                    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    __pyx_t_3 = NULL;
+                    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+                      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
+                      if (likely(__pyx_t_3)) {
+                        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+                        __Pyx_INCREF(__pyx_t_3);
+                        __Pyx_INCREF(function);
+                        __Pyx_DECREF_SET(__pyx_t_5, function);
+                      }
+                    }
+                    __pyx_t_11 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 434, __pyx_L32_error)
+                    __Pyx_GOTREF(__pyx_t_11);
+                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+                    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_11);
+                    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                    __Pyx_XGOTREF(__pyx_r);
+                    if (likely(__pyx_r)) {
+                      __Pyx_XGIVEREF(__pyx_t_4);
+                      __pyx_cur_scope->__pyx_t_0 = __pyx_t_4;
+                      __Pyx_XGIVEREF(__pyx_t_6);
+                      __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
+                      __Pyx_XGIVEREF(__pyx_t_7);
+                      __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
+                      __Pyx_XGIVEREF(__pyx_t_8);
+                      __pyx_cur_scope->__pyx_t_3 = __pyx_t_8;
+                      __pyx_cur_scope->__pyx_t_4 = __pyx_t_9;
+                      __pyx_cur_scope->__pyx_t_5 = __pyx_t_17;
+                      __Pyx_XGIVEREF(__pyx_t_22);
+                      __pyx_cur_scope->__pyx_t_6 = __pyx_t_22;
+                      __Pyx_XGIVEREF(__pyx_t_23);
+                      __pyx_cur_scope->__pyx_t_7 = __pyx_t_23;
+                      __Pyx_XGIVEREF(__pyx_t_24);
+                      __pyx_cur_scope->__pyx_t_8 = __pyx_t_24;
+                      __Pyx_XGIVEREF(__pyx_t_25);
+                      __pyx_cur_scope->__pyx_t_9 = __pyx_t_25;
+                      __Pyx_XGIVEREF(__pyx_r);
+                      __Pyx_RefNannyFinishContext();
+                      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+                      /* return from generator, awaiting value */
+                      __pyx_generator->resume_label = 3;
+                      return __pyx_r;
+                      __pyx_L40_resume_from_await:;
+                      __pyx_t_4 = __pyx_cur_scope->__pyx_t_0;
+                      __pyx_cur_scope->__pyx_t_0 = 0;
+                      __Pyx_XGOTREF(__pyx_t_4);
+                      __pyx_t_6 = __pyx_cur_scope->__pyx_t_1;
+                      __pyx_cur_scope->__pyx_t_1 = 0;
+                      __Pyx_XGOTREF(__pyx_t_6);
+                      __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
+                      __pyx_cur_scope->__pyx_t_2 = 0;
+                      __Pyx_XGOTREF(__pyx_t_7);
+                      __pyx_t_8 = __pyx_cur_scope->__pyx_t_3;
+                      __pyx_cur_scope->__pyx_t_3 = 0;
+                      __Pyx_XGOTREF(__pyx_t_8);
+                      __pyx_t_9 = __pyx_cur_scope->__pyx_t_4;
+                      __pyx_t_17 = __pyx_cur_scope->__pyx_t_5;
+                      __pyx_t_22 = __pyx_cur_scope->__pyx_t_6;
+                      __pyx_cur_scope->__pyx_t_6 = 0;
+                      __Pyx_XGOTREF(__pyx_t_22);
+                      __pyx_t_23 = __pyx_cur_scope->__pyx_t_7;
+                      __pyx_cur_scope->__pyx_t_7 = 0;
+                      __Pyx_XGOTREF(__pyx_t_23);
+                      __pyx_t_24 = __pyx_cur_scope->__pyx_t_8;
+                      __pyx_cur_scope->__pyx_t_8 = 0;
+                      __Pyx_XGOTREF(__pyx_t_24);
+                      __pyx_t_25 = __pyx_cur_scope->__pyx_t_9;
+                      __pyx_cur_scope->__pyx_t_9 = 0;
+                      __Pyx_XGOTREF(__pyx_t_25);
+                      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 434, __pyx_L32_error)
+                    } else {
+                      PyObject* exc_type = __Pyx_PyErr_Occurred();
+                      if (exc_type) {
+                        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+                        else __PYX_ERR(0, 434, __pyx_L32_error)
+                      }
+                    }
+
+                    /* "asyncpg/protocol/protocol.pyx":433
+ * 
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await self.writing_allowed.wait()
+ *                         self._write_copy_data_msg(wbuf)
+ */
+                  }
+                  __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0;
+                  __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0;
+                  __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
+                  goto __pyx_L39_try_end;
+                  __pyx_L32_error:;
+                  __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                  __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+                  __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+                  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                  /*except:*/ {
+                    __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+                    if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_5, &__pyx_t_3) < 0) __PYX_ERR(0, 433, __pyx_L34_except_error)
+                    __Pyx_GOTREF(__pyx_t_11);
+                    __Pyx_GOTREF(__pyx_t_5);
+                    __Pyx_GOTREF(__pyx_t_3);
+                    __pyx_t_12 = PyTuple_Pack(3, __pyx_t_11, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 433, __pyx_L34_except_error)
+                    __Pyx_GOTREF(__pyx_t_12);
+                    __pyx_t_26 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_t_12, NULL);
+                    __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
+                    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+                    if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 433, __pyx_L34_except_error)
+                    __Pyx_GOTREF(__pyx_t_26);
+                    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_26);
+                    __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
+                    if (__pyx_t_10 < 0) __PYX_ERR(0, 433, __pyx_L34_except_error)
+                    __pyx_t_2 = ((!(__pyx_t_10 != 0)) != 0);
+                    if (__pyx_t_2) {
+                      __Pyx_GIVEREF(__pyx_t_11);
+                      __Pyx_GIVEREF(__pyx_t_5);
+                      __Pyx_XGIVEREF(__pyx_t_3);
+                      __Pyx_ErrRestoreWithState(__pyx_t_11, __pyx_t_5, __pyx_t_3);
+                      __pyx_t_11 = 0; __pyx_t_5 = 0; __pyx_t_3 = 0; 
+                      __PYX_ERR(0, 433, __pyx_L34_except_error)
+                    }
+                    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    goto __pyx_L33_exception_handled;
+                  }
+                  __pyx_L34_except_error:;
+                  __Pyx_XGIVEREF(__pyx_t_23);
+                  __Pyx_XGIVEREF(__pyx_t_24);
+                  __Pyx_XGIVEREF(__pyx_t_25);
+                  __Pyx_ExceptionReset(__pyx_t_23, __pyx_t_24, __pyx_t_25);
+                  goto __pyx_L8_error;
+                  __pyx_L33_exception_handled:;
+                  __Pyx_XGIVEREF(__pyx_t_23);
+                  __Pyx_XGIVEREF(__pyx_t_24);
+                  __Pyx_XGIVEREF(__pyx_t_25);
+                  __Pyx_ExceptionReset(__pyx_t_23, __pyx_t_24, __pyx_t_25);
+                  __pyx_L39_try_end:;
+                }
+              }
+              /*finally:*/ {
+                /*normal exit:*/{
+                  if (__pyx_t_22) {
+                    __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_tuple__31, NULL);
+                    __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
+                    if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 433, __pyx_L8_error)
+                    __Pyx_GOTREF(__pyx_t_25);
+                    __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
+                  }
+                  goto __pyx_L31;
+                }
+                __pyx_L31:;
+              }
+              goto __pyx_L44;
+              __pyx_L26_error:;
+              __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
+              goto __pyx_L8_error;
+              __pyx_L44:;
+            }
+
+            /* "asyncpg/protocol/protocol.pyx":435
+ *                         with timer:
+ *                             await self.writing_allowed.wait()
+ *                         self._write_copy_data_msg(wbuf)             # <<<<<<<<<<<<<<
+ *                         wbuf = WriteBuffer.new()
+ * 
+ */
+            __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_data_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject *)__pyx_cur_scope->__pyx_v_wbuf)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+            /* "asyncpg/protocol/protocol.pyx":436
+ *                             await self.writing_allowed.wait()
+ *                         self._write_copy_data_msg(wbuf)
+ *                         wbuf = WriteBuffer.new()             # <<<<<<<<<<<<<<
+ * 
+ *                 # End of binary copy.
+ */
+            __pyx_t_3 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new()); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 436, __pyx_L8_error)
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_wbuf));
+            __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_wbuf, ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_3));
+            __Pyx_GIVEREF(__pyx_t_3);
+            __pyx_t_3 = 0;
+
+            /* "asyncpg/protocol/protocol.pyx":432
+ *                             codec.encode(settings, wbuf, item)
+ * 
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:             # <<<<<<<<<<<<<<
+ *                         with timer:
+ *                             await self.writing_allowed.wait()
+ */
+          }
+
+          /* "asyncpg/protocol/protocol.pyx":420
+ *                             'type {} (OID {})'.format(codec.name, codec.oid))
+ * 
+ *                 for row in records:             # <<<<<<<<<<<<<<
+ *                     # Tuple header
+ *                     wbuf.write_int16(<int16_t>num_cols)
+ */
+        }
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":439
+ * 
+ *                 # End of binary copy.
+ *                 wbuf.write_int16(-1)             # <<<<<<<<<<<<<<
+ *                 self._write_copy_data_msg(wbuf)
+ * 
+ */
+        __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_cur_scope->__pyx_v_wbuf->__pyx_vtab)->write_int16(__pyx_cur_scope->__pyx_v_wbuf, -1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 439, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":440
+ *                 # End of binary copy.
+ *                 wbuf.write_int16(-1)
+ *                 self._write_copy_data_msg(wbuf)             # <<<<<<<<<<<<<<
+ * 
+ *             elif reader is not None:
+ */
+        __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_data_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject *)__pyx_cur_scope->__pyx_v_wbuf)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 440, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":398
+ * 
+ *         try:
+ *             if record_stmt is not None:             # <<<<<<<<<<<<<<
+ *                 # copy_in_records in binary mode
+ *                 wbuf = WriteBuffer.new()
+ */
+        goto __pyx_L14;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":442
+ *                 self._write_copy_data_msg(wbuf)
+ * 
+ *             elif reader is not None:             # <<<<<<<<<<<<<<
+ *                 try:
+ *                     aiter = reader.__aiter__
+ */
+      __pyx_t_2 = (__pyx_cur_scope->__pyx_v_reader != Py_None);
+      __pyx_t_10 = (__pyx_t_2 != 0);
+      if (__pyx_t_10) {
+
+        /* "asyncpg/protocol/protocol.pyx":443
+ * 
+ *             elif reader is not None:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     aiter = reader.__aiter__
+ *                 except AttributeError:
+ */
+        {
+          __Pyx_ExceptionSave(&__pyx_t_22, &__pyx_t_25, &__pyx_t_24);
+          __Pyx_XGOTREF(__pyx_t_22);
+          __Pyx_XGOTREF(__pyx_t_25);
+          __Pyx_XGOTREF(__pyx_t_24);
+          /*try:*/ {
+
+            /* "asyncpg/protocol/protocol.pyx":444
+ *             elif reader is not None:
+ *                 try:
+ *                     aiter = reader.__aiter__             # <<<<<<<<<<<<<<
+ *                 except AttributeError:
+ *                     raise TypeError('reader is not an asynchronous iterable')
+ */
+            __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_reader, __pyx_n_s_aiter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 444, __pyx_L45_error)
+            __Pyx_GOTREF(__pyx_t_4);
+            __Pyx_GIVEREF(__pyx_t_4);
+            __pyx_cur_scope->__pyx_v_aiter = __pyx_t_4;
+            __pyx_t_4 = 0;
+
+            /* "asyncpg/protocol/protocol.pyx":443
+ * 
+ *             elif reader is not None:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     aiter = reader.__aiter__
+ *                 except AttributeError:
+ */
+          }
+
+          /* "asyncpg/protocol/protocol.pyx":448
+ *                     raise TypeError('reader is not an asynchronous iterable')
+ *                 else:
+ *                     iterator = aiter()             # <<<<<<<<<<<<<<
+ * 
+ *                 try:
+ */
+          /*else:*/ {
+            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_aiter);
+            __pyx_t_3 = __pyx_cur_scope->__pyx_v_aiter; __pyx_t_5 = NULL;
+            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+              __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+              if (likely(__pyx_t_5)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+                __Pyx_INCREF(__pyx_t_5);
+                __Pyx_INCREF(function);
+                __Pyx_DECREF_SET(__pyx_t_3, function);
+              }
+            }
+            __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+            if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 448, __pyx_L47_except_error)
+            __Pyx_GOTREF(__pyx_t_4);
+            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+            __Pyx_GIVEREF(__pyx_t_4);
+            __pyx_cur_scope->__pyx_v_iterator = __pyx_t_4;
+            __pyx_t_4 = 0;
+          }
+          __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
+          __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
+          __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0;
+          goto __pyx_L50_try_end;
+          __pyx_L45_error:;
+          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":445
+ *                 try:
+ *                     aiter = reader.__aiter__
+ *                 except AttributeError:             # <<<<<<<<<<<<<<
+ *                     raise TypeError('reader is not an asynchronous iterable')
+ *                 else:
+ */
+          __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
+          if (__pyx_t_15) {
+            __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+            if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_5) < 0) __PYX_ERR(0, 445, __pyx_L47_except_error)
+            __Pyx_GOTREF(__pyx_t_4);
+            __Pyx_GOTREF(__pyx_t_3);
+            __Pyx_GOTREF(__pyx_t_5);
+
+            /* "asyncpg/protocol/protocol.pyx":446
+ *                     aiter = reader.__aiter__
+ *                 except AttributeError:
+ *                     raise TypeError('reader is not an asynchronous iterable')             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     iterator = aiter()
+ */
+            __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 446, __pyx_L47_except_error)
+            __Pyx_GOTREF(__pyx_t_11);
+            __Pyx_Raise(__pyx_t_11, 0, 0, 0);
+            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+            __PYX_ERR(0, 446, __pyx_L47_except_error)
+          }
+          goto __pyx_L47_except_error;
+          __pyx_L47_except_error:;
+
+          /* "asyncpg/protocol/protocol.pyx":443
+ * 
+ *             elif reader is not None:
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     aiter = reader.__aiter__
+ *                 except AttributeError:
+ */
+          __Pyx_XGIVEREF(__pyx_t_22);
+          __Pyx_XGIVEREF(__pyx_t_25);
+          __Pyx_XGIVEREF(__pyx_t_24);
+          __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_25, __pyx_t_24);
+          goto __pyx_L8_error;
+          __pyx_L50_try_end:;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":450
+ *                     iterator = aiter()
+ * 
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     while True:
+ *                         # We rely on protocol flow control to moderate the
+ */
+        {
+          __Pyx_ExceptionSave(&__pyx_t_24, &__pyx_t_25, &__pyx_t_22);
+          __Pyx_XGOTREF(__pyx_t_24);
+          __Pyx_XGOTREF(__pyx_t_25);
+          __Pyx_XGOTREF(__pyx_t_22);
+          /*try:*/ {
+
+            /* "asyncpg/protocol/protocol.pyx":451
+ * 
+ *                 try:
+ *                     while True:             # <<<<<<<<<<<<<<
+ *                         # We rely on protocol flow control to moderate the
+ *                         # rate of data messages.
+ */
+            while (1) {
+
+              /* "asyncpg/protocol/protocol.pyx":454
+ *                         # We rely on protocol flow control to moderate the
+ *                         # rate of data messages.
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await self.writing_allowed.wait()
+ *                         with timer:
+ */
+              /*with:*/ {
+                __pyx_t_23 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_exit); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 454, __pyx_L53_error)
+                __Pyx_GOTREF(__pyx_t_23);
+                __pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_enter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L61_error)
+                __Pyx_GOTREF(__pyx_t_3);
+                __pyx_t_4 = NULL;
+                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+                  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+                  if (likely(__pyx_t_4)) {
+                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+                    __Pyx_INCREF(__pyx_t_4);
+                    __Pyx_INCREF(function);
+                    __Pyx_DECREF_SET(__pyx_t_3, function);
+                  }
+                }
+                __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+                __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+                if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 454, __pyx_L61_error)
+                __Pyx_GOTREF(__pyx_t_5);
+                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+                /*try:*/ {
+                  {
+                    __Pyx_ExceptionSave(&__pyx_t_26, &__pyx_t_27, &__pyx_t_28);
+                    __Pyx_XGOTREF(__pyx_t_26);
+                    __Pyx_XGOTREF(__pyx_t_27);
+                    __Pyx_XGOTREF(__pyx_t_28);
+                    /*try:*/ {
+
+                      /* "asyncpg/protocol/protocol.pyx":455
+ *                         # rate of data messages.
+ *                         with timer:
+ *                             await self.writing_allowed.wait()             # <<<<<<<<<<<<<<
+ *                         with timer:
+ *                             chunk = await asyncio.wait_for(
+ */
+                      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_writing_allowed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 455, __pyx_L67_error)
+                      __Pyx_GOTREF(__pyx_t_3);
+                      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wait); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 455, __pyx_L67_error)
+                      __Pyx_GOTREF(__pyx_t_4);
+                      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                      __pyx_t_3 = NULL;
+                      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+                        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+                        if (likely(__pyx_t_3)) {
+                          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+                          __Pyx_INCREF(__pyx_t_3);
+                          __Pyx_INCREF(function);
+                          __Pyx_DECREF_SET(__pyx_t_4, function);
+                        }
+                      }
+                      __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+                      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 455, __pyx_L67_error)
+                      __Pyx_GOTREF(__pyx_t_5);
+                      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+                      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_5);
+                      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+                      __Pyx_XGOTREF(__pyx_r);
+                      if (likely(__pyx_r)) {
+                        __Pyx_XGIVEREF(__pyx_t_6);
+                        __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+                        __Pyx_XGIVEREF(__pyx_t_7);
+                        __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+                        __Pyx_XGIVEREF(__pyx_t_8);
+                        __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+                        __Pyx_XGIVEREF(__pyx_t_22);
+                        __pyx_cur_scope->__pyx_t_3 = __pyx_t_22;
+                        __Pyx_XGIVEREF(__pyx_t_23);
+                        __pyx_cur_scope->__pyx_t_6 = __pyx_t_23;
+                        __Pyx_XGIVEREF(__pyx_t_24);
+                        __pyx_cur_scope->__pyx_t_7 = __pyx_t_24;
+                        __Pyx_XGIVEREF(__pyx_t_25);
+                        __pyx_cur_scope->__pyx_t_8 = __pyx_t_25;
+                        __Pyx_XGIVEREF(__pyx_t_26);
+                        __pyx_cur_scope->__pyx_t_9 = __pyx_t_26;
+                        __Pyx_XGIVEREF(__pyx_t_27);
+                        __pyx_cur_scope->__pyx_t_10 = __pyx_t_27;
+                        __Pyx_XGIVEREF(__pyx_t_28);
+                        __pyx_cur_scope->__pyx_t_11 = __pyx_t_28;
+                        __Pyx_XGIVEREF(__pyx_r);
+                        __Pyx_RefNannyFinishContext();
+                        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+                        /* return from generator, awaiting value */
+                        __pyx_generator->resume_label = 4;
+                        return __pyx_r;
+                        __pyx_L75_resume_from_await:;
+                        __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+                        __pyx_cur_scope->__pyx_t_0 = 0;
+                        __Pyx_XGOTREF(__pyx_t_6);
+                        __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+                        __pyx_cur_scope->__pyx_t_1 = 0;
+                        __Pyx_XGOTREF(__pyx_t_7);
+                        __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+                        __pyx_cur_scope->__pyx_t_2 = 0;
+                        __Pyx_XGOTREF(__pyx_t_8);
+                        __pyx_t_22 = __pyx_cur_scope->__pyx_t_3;
+                        __pyx_cur_scope->__pyx_t_3 = 0;
+                        __Pyx_XGOTREF(__pyx_t_22);
+                        __pyx_t_23 = __pyx_cur_scope->__pyx_t_6;
+                        __pyx_cur_scope->__pyx_t_6 = 0;
+                        __Pyx_XGOTREF(__pyx_t_23);
+                        __pyx_t_24 = __pyx_cur_scope->__pyx_t_7;
+                        __pyx_cur_scope->__pyx_t_7 = 0;
+                        __Pyx_XGOTREF(__pyx_t_24);
+                        __pyx_t_25 = __pyx_cur_scope->__pyx_t_8;
+                        __pyx_cur_scope->__pyx_t_8 = 0;
+                        __Pyx_XGOTREF(__pyx_t_25);
+                        __pyx_t_26 = __pyx_cur_scope->__pyx_t_9;
+                        __pyx_cur_scope->__pyx_t_9 = 0;
+                        __Pyx_XGOTREF(__pyx_t_26);
+                        __pyx_t_27 = __pyx_cur_scope->__pyx_t_10;
+                        __pyx_cur_scope->__pyx_t_10 = 0;
+                        __Pyx_XGOTREF(__pyx_t_27);
+                        __pyx_t_28 = __pyx_cur_scope->__pyx_t_11;
+                        __pyx_cur_scope->__pyx_t_11 = 0;
+                        __Pyx_XGOTREF(__pyx_t_28);
+                        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 455, __pyx_L67_error)
+                      } else {
+                        PyObject* exc_type = __Pyx_PyErr_Occurred();
+                        if (exc_type) {
+                          if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+                          else __PYX_ERR(0, 455, __pyx_L67_error)
+                        }
+                      }
+
+                      /* "asyncpg/protocol/protocol.pyx":454
+ *                         # We rely on protocol flow control to moderate the
+ *                         # rate of data messages.
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await self.writing_allowed.wait()
+ *                         with timer:
+ */
+                    }
+                    __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0;
+                    __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0;
+                    __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0;
+                    goto __pyx_L74_try_end;
+                    __pyx_L67_error:;
+                    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+                    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+                    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                    /*except:*/ {
+                      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+                      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3) < 0) __PYX_ERR(0, 454, __pyx_L69_except_error)
+                      __Pyx_GOTREF(__pyx_t_5);
+                      __Pyx_GOTREF(__pyx_t_4);
+                      __Pyx_GOTREF(__pyx_t_3);
+                      __pyx_t_11 = PyTuple_Pack(3, __pyx_t_5, __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 454, __pyx_L69_except_error)
+                      __Pyx_GOTREF(__pyx_t_11);
+                      __pyx_t_29 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_11, NULL);
+                      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
+                      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                      if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 454, __pyx_L69_except_error)
+                      __Pyx_GOTREF(__pyx_t_29);
+                      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_29);
+                      __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0;
+                      if (__pyx_t_10 < 0) __PYX_ERR(0, 454, __pyx_L69_except_error)
+                      __pyx_t_2 = ((!(__pyx_t_10 != 0)) != 0);
+                      if (__pyx_t_2) {
+                        __Pyx_GIVEREF(__pyx_t_5);
+                        __Pyx_GIVEREF(__pyx_t_4);
+                        __Pyx_XGIVEREF(__pyx_t_3);
+                        __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_4, __pyx_t_3);
+                        __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; 
+                        __PYX_ERR(0, 454, __pyx_L69_except_error)
+                      }
+                      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+                      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                      goto __pyx_L68_exception_handled;
+                    }
+                    __pyx_L69_except_error:;
+                    __Pyx_XGIVEREF(__pyx_t_26);
+                    __Pyx_XGIVEREF(__pyx_t_27);
+                    __Pyx_XGIVEREF(__pyx_t_28);
+                    __Pyx_ExceptionReset(__pyx_t_26, __pyx_t_27, __pyx_t_28);
+                    goto __pyx_L53_error;
+                    __pyx_L68_exception_handled:;
+                    __Pyx_XGIVEREF(__pyx_t_26);
+                    __Pyx_XGIVEREF(__pyx_t_27);
+                    __Pyx_XGIVEREF(__pyx_t_28);
+                    __Pyx_ExceptionReset(__pyx_t_26, __pyx_t_27, __pyx_t_28);
+                    __pyx_L74_try_end:;
+                  }
+                }
+                /*finally:*/ {
+                  /*normal exit:*/{
+                    if (__pyx_t_23) {
+                      __pyx_t_28 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_tuple__31, NULL);
+                      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
+                      if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 454, __pyx_L53_error)
+                      __Pyx_GOTREF(__pyx_t_28);
+                      __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
+                    }
+                    goto __pyx_L66;
+                  }
+                  __pyx_L66:;
+                }
+                goto __pyx_L79;
+                __pyx_L61_error:;
+                __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
+                goto __pyx_L53_error;
+                __pyx_L79:;
+              }
+
+              /* "asyncpg/protocol/protocol.pyx":456
+ *                         with timer:
+ *                             await self.writing_allowed.wait()
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             chunk = await asyncio.wait_for(
+ *                                 iterator.__anext__(),
+ */
+              /*with:*/ {
+                __pyx_t_23 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_exit); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 456, __pyx_L53_error)
+                __Pyx_GOTREF(__pyx_t_23);
+                __pyx_t_4 = __Pyx_PyObject_LookupSpecial(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_enter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 456, __pyx_L80_error)
+                __Pyx_GOTREF(__pyx_t_4);
+                __pyx_t_5 = NULL;
+                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+                  __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+                  if (likely(__pyx_t_5)) {
+                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+                    __Pyx_INCREF(__pyx_t_5);
+                    __Pyx_INCREF(function);
+                    __Pyx_DECREF_SET(__pyx_t_4, function);
+                  }
+                }
+                __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+                __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 456, __pyx_L80_error)
+                __Pyx_GOTREF(__pyx_t_3);
+                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                /*try:*/ {
+                  {
+                    __Pyx_ExceptionSave(&__pyx_t_28, &__pyx_t_27, &__pyx_t_26);
+                    __Pyx_XGOTREF(__pyx_t_28);
+                    __Pyx_XGOTREF(__pyx_t_27);
+                    __Pyx_XGOTREF(__pyx_t_26);
+                    /*try:*/ {
+
+                      /* "asyncpg/protocol/protocol.pyx":457
+ *                             await self.writing_allowed.wait()
+ *                         with timer:
+ *                             chunk = await asyncio.wait_for(             # <<<<<<<<<<<<<<
+ *                                 iterator.__anext__(),
+ *                                 timeout=timer.get_remaining_budget(),
+ */
+                      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 457, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_3);
+                      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wait_for); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_4);
+                      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+                      /* "asyncpg/protocol/protocol.pyx":458
+ *                         with timer:
+ *                             chunk = await asyncio.wait_for(
+ *                                 iterator.__anext__(),             # <<<<<<<<<<<<<<
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)
+ */
+                      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_iterator, __pyx_n_s_anext); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 458, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_5);
+                      __pyx_t_11 = NULL;
+                      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+                        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_5);
+                        if (likely(__pyx_t_11)) {
+                          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+                          __Pyx_INCREF(__pyx_t_11);
+                          __Pyx_INCREF(function);
+                          __Pyx_DECREF_SET(__pyx_t_5, function);
+                        }
+                      }
+                      __pyx_t_3 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+                      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_3);
+                      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+                      /* "asyncpg/protocol/protocol.pyx":457
+ *                             await self.writing_allowed.wait()
+ *                         with timer:
+ *                             chunk = await asyncio.wait_for(             # <<<<<<<<<<<<<<
+ *                                 iterator.__anext__(),
+ *                                 timeout=timer.get_remaining_budget(),
+ */
+                      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 457, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_5);
+                      __Pyx_GIVEREF(__pyx_t_3);
+                      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
+                      __pyx_t_3 = 0;
+
+                      /* "asyncpg/protocol/protocol.pyx":459
+ *                             chunk = await asyncio.wait_for(
+ *                                 iterator.__anext__(),
+ *                                 timeout=timer.get_remaining_budget(),             # <<<<<<<<<<<<<<
+ *                                 loop=self.loop)
+ *                         self._write_copy_data_msg(chunk)
+ */
+                      __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 459, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_3);
+                      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_timer, __pyx_n_s_get_remaining_budget); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 459, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_12);
+                      __pyx_t_16 = NULL;
+                      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
+                        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_12);
+                        if (likely(__pyx_t_16)) {
+                          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
+                          __Pyx_INCREF(__pyx_t_16);
+                          __Pyx_INCREF(function);
+                          __Pyx_DECREF_SET(__pyx_t_12, function);
+                        }
+                      }
+                      __pyx_t_11 = (__pyx_t_16) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_16) : __Pyx_PyObject_CallNoArg(__pyx_t_12);
+                      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                      if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 459, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_11);
+                      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+                      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_timeout, __pyx_t_11) < 0) __PYX_ERR(0, 459, __pyx_L86_error)
+                      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+                      /* "asyncpg/protocol/protocol.pyx":460
+ *                                 iterator.__anext__(),
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)             # <<<<<<<<<<<<<<
+ *                         self._write_copy_data_msg(chunk)
+ *                 except builtins.StopAsyncIteration:
+ */
+                      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_loop, __pyx_cur_scope->__pyx_v_self->loop) < 0) __PYX_ERR(0, 459, __pyx_L86_error)
+
+                      /* "asyncpg/protocol/protocol.pyx":457
+ *                             await self.writing_allowed.wait()
+ *                         with timer:
+ *                             chunk = await asyncio.wait_for(             # <<<<<<<<<<<<<<
+ *                                 iterator.__anext__(),
+ *                                 timeout=timer.get_remaining_budget(),
+ */
+                      __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 457, __pyx_L86_error)
+                      __Pyx_GOTREF(__pyx_t_11);
+                      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+                      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+                      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_11);
+                      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+                      __Pyx_XGOTREF(__pyx_r);
+                      if (likely(__pyx_r)) {
+                        __Pyx_XGIVEREF(__pyx_t_6);
+                        __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+                        __Pyx_XGIVEREF(__pyx_t_7);
+                        __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+                        __Pyx_XGIVEREF(__pyx_t_8);
+                        __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+                        __Pyx_XGIVEREF(__pyx_t_22);
+                        __pyx_cur_scope->__pyx_t_3 = __pyx_t_22;
+                        __Pyx_XGIVEREF(__pyx_t_23);
+                        __pyx_cur_scope->__pyx_t_6 = __pyx_t_23;
+                        __Pyx_XGIVEREF(__pyx_t_24);
+                        __pyx_cur_scope->__pyx_t_7 = __pyx_t_24;
+                        __Pyx_XGIVEREF(__pyx_t_25);
+                        __pyx_cur_scope->__pyx_t_8 = __pyx_t_25;
+                        __Pyx_XGIVEREF(__pyx_t_26);
+                        __pyx_cur_scope->__pyx_t_9 = __pyx_t_26;
+                        __Pyx_XGIVEREF(__pyx_t_27);
+                        __pyx_cur_scope->__pyx_t_10 = __pyx_t_27;
+                        __Pyx_XGIVEREF(__pyx_t_28);
+                        __pyx_cur_scope->__pyx_t_11 = __pyx_t_28;
+                        __Pyx_XGIVEREF(__pyx_r);
+                        __Pyx_RefNannyFinishContext();
+                        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+                        /* return from generator, awaiting value */
+                        __pyx_generator->resume_label = 5;
+                        return __pyx_r;
+                        __pyx_L94_resume_from_await:;
+                        __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+                        __pyx_cur_scope->__pyx_t_0 = 0;
+                        __Pyx_XGOTREF(__pyx_t_6);
+                        __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+                        __pyx_cur_scope->__pyx_t_1 = 0;
+                        __Pyx_XGOTREF(__pyx_t_7);
+                        __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+                        __pyx_cur_scope->__pyx_t_2 = 0;
+                        __Pyx_XGOTREF(__pyx_t_8);
+                        __pyx_t_22 = __pyx_cur_scope->__pyx_t_3;
+                        __pyx_cur_scope->__pyx_t_3 = 0;
+                        __Pyx_XGOTREF(__pyx_t_22);
+                        __pyx_t_23 = __pyx_cur_scope->__pyx_t_6;
+                        __pyx_cur_scope->__pyx_t_6 = 0;
+                        __Pyx_XGOTREF(__pyx_t_23);
+                        __pyx_t_24 = __pyx_cur_scope->__pyx_t_7;
+                        __pyx_cur_scope->__pyx_t_7 = 0;
+                        __Pyx_XGOTREF(__pyx_t_24);
+                        __pyx_t_25 = __pyx_cur_scope->__pyx_t_8;
+                        __pyx_cur_scope->__pyx_t_8 = 0;
+                        __Pyx_XGOTREF(__pyx_t_25);
+                        __pyx_t_26 = __pyx_cur_scope->__pyx_t_9;
+                        __pyx_cur_scope->__pyx_t_9 = 0;
+                        __Pyx_XGOTREF(__pyx_t_26);
+                        __pyx_t_27 = __pyx_cur_scope->__pyx_t_10;
+                        __pyx_cur_scope->__pyx_t_10 = 0;
+                        __Pyx_XGOTREF(__pyx_t_27);
+                        __pyx_t_28 = __pyx_cur_scope->__pyx_t_11;
+                        __pyx_cur_scope->__pyx_t_11 = 0;
+                        __Pyx_XGOTREF(__pyx_t_28);
+                        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 457, __pyx_L86_error)
+                        __pyx_t_11 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_11);
+                      } else {
+                        __pyx_t_11 = NULL;
+                        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_11) < 0) __PYX_ERR(0, 457, __pyx_L86_error)
+                        __Pyx_GOTREF(__pyx_t_11);
+                      }
+                      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_chunk);
+                      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_chunk, __pyx_t_11);
+                      __Pyx_GIVEREF(__pyx_t_11);
+                      __pyx_t_11 = 0;
+
+                      /* "asyncpg/protocol/protocol.pyx":456
+ *                         with timer:
+ *                             await self.writing_allowed.wait()
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             chunk = await asyncio.wait_for(
+ *                                 iterator.__anext__(),
+ */
+                    }
+                    __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0;
+                    __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0;
+                    __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0;
+                    goto __pyx_L93_try_end;
+                    __pyx_L86_error:;
+                    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+                    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+                    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+                    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                    /*except:*/ {
+                      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+                      if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_3, &__pyx_t_5) < 0) __PYX_ERR(0, 456, __pyx_L88_except_error)
+                      __Pyx_GOTREF(__pyx_t_11);
+                      __Pyx_GOTREF(__pyx_t_3);
+                      __Pyx_GOTREF(__pyx_t_5);
+                      __pyx_t_4 = PyTuple_Pack(3, __pyx_t_11, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 456, __pyx_L88_except_error)
+                      __Pyx_GOTREF(__pyx_t_4);
+                      __pyx_t_29 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_4, NULL);
+                      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
+                      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+                      if (unlikely(!__pyx_t_29)) __PYX_ERR(0, 456, __pyx_L88_except_error)
+                      __Pyx_GOTREF(__pyx_t_29);
+                      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_29);
+                      __Pyx_DECREF(__pyx_t_29); __pyx_t_29 = 0;
+                      if (__pyx_t_2 < 0) __PYX_ERR(0, 456, __pyx_L88_except_error)
+                      __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0);
+                      if (__pyx_t_10) {
+                        __Pyx_GIVEREF(__pyx_t_11);
+                        __Pyx_GIVEREF(__pyx_t_3);
+                        __Pyx_XGIVEREF(__pyx_t_5);
+                        __Pyx_ErrRestoreWithState(__pyx_t_11, __pyx_t_3, __pyx_t_5);
+                        __pyx_t_11 = 0; __pyx_t_3 = 0; __pyx_t_5 = 0; 
+                        __PYX_ERR(0, 456, __pyx_L88_except_error)
+                      }
+                      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+                      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+                      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+                      goto __pyx_L87_exception_handled;
+                    }
+                    __pyx_L88_except_error:;
+                    __Pyx_XGIVEREF(__pyx_t_28);
+                    __Pyx_XGIVEREF(__pyx_t_27);
+                    __Pyx_XGIVEREF(__pyx_t_26);
+                    __Pyx_ExceptionReset(__pyx_t_28, __pyx_t_27, __pyx_t_26);
+                    goto __pyx_L53_error;
+                    __pyx_L87_exception_handled:;
+                    __Pyx_XGIVEREF(__pyx_t_28);
+                    __Pyx_XGIVEREF(__pyx_t_27);
+                    __Pyx_XGIVEREF(__pyx_t_26);
+                    __Pyx_ExceptionReset(__pyx_t_28, __pyx_t_27, __pyx_t_26);
+                    __pyx_L93_try_end:;
+                  }
+                }
+                /*finally:*/ {
+                  /*normal exit:*/{
+                    if (__pyx_t_23) {
+                      __pyx_t_26 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_tuple__31, NULL);
+                      __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
+                      if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 456, __pyx_L53_error)
+                      __Pyx_GOTREF(__pyx_t_26);
+                      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
+                    }
+                    goto __pyx_L85;
+                  }
+                  __pyx_L85:;
+                }
+                goto __pyx_L98;
+                __pyx_L80_error:;
+                __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;
+                goto __pyx_L53_error;
+                __pyx_L98:;
+              }
+
+              /* "asyncpg/protocol/protocol.pyx":461
+ *                                 timeout=timer.get_remaining_budget(),
+ *                                 loop=self.loop)
+ *                         self._write_copy_data_msg(chunk)             # <<<<<<<<<<<<<<
+ *                 except builtins.StopAsyncIteration:
+ *                     pass
+ */
+              if (unlikely(!__pyx_cur_scope->__pyx_v_chunk)) { __Pyx_RaiseUnboundLocalError("chunk"); __PYX_ERR(0, 461, __pyx_L53_error) }
+              __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_data_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_chunk); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L53_error)
+              __Pyx_GOTREF(__pyx_t_5);
+              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+            }
+
+            /* "asyncpg/protocol/protocol.pyx":450
+ *                     iterator = aiter()
+ * 
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     while True:
+ *                         # We rely on protocol flow control to moderate the
+ */
+          }
+          __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0;
+          __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
+          __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
+          goto __pyx_L58_try_end;
+          __pyx_L53_error:;
+          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":462
+ *                                 loop=self.loop)
+ *                         self._write_copy_data_msg(chunk)
+ *                 except builtins.StopAsyncIteration:             # <<<<<<<<<<<<<<
+ *                     pass
+ *             else:
+ */
+          __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_3, &__pyx_t_11);
+          __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_builtins); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 462, __pyx_L55_except_error)
+          __Pyx_GOTREF(__pyx_t_4);
+          __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_StopAsyncIteration); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L55_except_error)
+          __Pyx_GOTREF(__pyx_t_12);
+          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+          __pyx_t_15 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_5, __pyx_t_12);
+          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_ErrRestore(__pyx_t_5, __pyx_t_3, __pyx_t_11);
+          __pyx_t_5 = 0; __pyx_t_3 = 0; __pyx_t_11 = 0;
+          if (__pyx_t_15) {
+            __Pyx_ErrRestore(0,0,0);
+            goto __pyx_L54_exception_handled;
+          }
+          goto __pyx_L55_except_error;
+          __pyx_L55_except_error:;
+
+          /* "asyncpg/protocol/protocol.pyx":450
+ *                     iterator = aiter()
+ * 
+ *                 try:             # <<<<<<<<<<<<<<
+ *                     while True:
+ *                         # We rely on protocol flow control to moderate the
+ */
+          __Pyx_XGIVEREF(__pyx_t_24);
+          __Pyx_XGIVEREF(__pyx_t_25);
+          __Pyx_XGIVEREF(__pyx_t_22);
+          __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_25, __pyx_t_22);
+          goto __pyx_L8_error;
+          __pyx_L54_exception_handled:;
+          __Pyx_XGIVEREF(__pyx_t_24);
+          __Pyx_XGIVEREF(__pyx_t_25);
+          __Pyx_XGIVEREF(__pyx_t_22);
+          __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_25, __pyx_t_22);
+          __pyx_L58_try_end:;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":442
+ *                 self._write_copy_data_msg(wbuf)
+ * 
+ *             elif reader is not None:             # <<<<<<<<<<<<<<
+ *                 try:
+ *                     aiter = reader.__aiter__
+ */
+        goto __pyx_L14;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":466
+ *             else:
+ *                 # Buffer passed in directly.
+ *                 await self.writing_allowed.wait()             # <<<<<<<<<<<<<<
+ *                 self._write_copy_data_msg(data)
+ * 
+ */
+      /*else*/ {
+        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_writing_allowed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 466, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_wait); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 466, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __pyx_t_3 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
+          if (likely(__pyx_t_3)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+            __Pyx_INCREF(__pyx_t_3);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_5, function);
+          }
+        }
+        __pyx_t_11 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 466, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_11);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_7);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+          __Pyx_XGIVEREF(__pyx_t_8);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 6;
+          return __pyx_r;
+          __pyx_L99_resume_from_await:;
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_7);
+          __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_8);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 466, __pyx_L8_error)
+        } else {
+          PyObject* exc_type = __Pyx_PyErr_Occurred();
+          if (exc_type) {
+            if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+            else __PYX_ERR(0, 466, __pyx_L8_error)
+          }
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":467
+ *                 # Buffer passed in directly.
+ *                 await self.writing_allowed.wait()
+ *                 self._write_copy_data_msg(data)             # <<<<<<<<<<<<<<
+ * 
+ *         except asyncio.TimeoutError:
+ */
+        __pyx_t_11 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_data_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_data); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 467, __pyx_L8_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+      }
+      __pyx_L14:;
+
+      /* "asyncpg/protocol/protocol.pyx":397
+ *         self._copy_in(copy_stmt)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             if record_stmt is not None:
+ *                 # copy_in_records in binary mode
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    goto __pyx_L13_try_end;
+    __pyx_L8_error:;
+    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":469
+ *                 self._write_copy_data_msg(data)
+ * 
+ *         except asyncio.TimeoutError:             # <<<<<<<<<<<<<<
+ *             self._write_copy_fail_msg('TimeoutError')
+ *             self._on_timeout(self.waiter)
+ */
+    __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_5, &__pyx_t_3);
+    __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 469, __pyx_L10_except_error)
+    __Pyx_GOTREF(__pyx_t_12);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_TimeoutError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 469, __pyx_L10_except_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+    __pyx_t_15 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_11, __pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_ErrRestore(__pyx_t_11, __pyx_t_5, __pyx_t_3);
+    __pyx_t_11 = 0; __pyx_t_5 = 0; __pyx_t_3 = 0;
+    if (__pyx_t_15) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_5, &__pyx_t_11) < 0) __PYX_ERR(0, 469, __pyx_L10_except_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_11);
+
+      /* "asyncpg/protocol/protocol.pyx":470
+ * 
+ *         except asyncio.TimeoutError:
+ *             self._write_copy_fail_msg('TimeoutError')             # <<<<<<<<<<<<<<
+ *             self._on_timeout(self.waiter)
+ *             try:
+ */
+      __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_fail_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), __pyx_n_u_TimeoutError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 470, __pyx_L10_except_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":471
+ *         except asyncio.TimeoutError:
+ *             self._write_copy_fail_msg('TimeoutError')
+ *             self._on_timeout(self.waiter)             # <<<<<<<<<<<<<<
+ *             try:
+ *                 await waiter
+ */
+      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_on_timeout); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 471, __pyx_L10_except_error)
+      __Pyx_GOTREF(__pyx_t_12);
+      __pyx_t_16 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
+        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_12);
+        if (likely(__pyx_t_16)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
+          __Pyx_INCREF(__pyx_t_16);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_12, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_16, __pyx_cur_scope->__pyx_v_self->waiter) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_cur_scope->__pyx_v_self->waiter);
+      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 471, __pyx_L10_except_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":472
+ *             self._write_copy_fail_msg('TimeoutError')
+ *             self._on_timeout(self.waiter)
+ *             try:             # <<<<<<<<<<<<<<
+ *                 await waiter
+ *             except TimeoutError:
+ */
+      {
+        __Pyx_ExceptionSave(&__pyx_t_22, &__pyx_t_25, &__pyx_t_24);
+        __Pyx_XGOTREF(__pyx_t_22);
+        __Pyx_XGOTREF(__pyx_t_25);
+        __Pyx_XGOTREF(__pyx_t_24);
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":473
+ *             self._on_timeout(self.waiter)
+ *             try:
+ *                 await waiter             # <<<<<<<<<<<<<<
+ *             except TimeoutError:
+ *                 raise
+ */
+          __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+          __Pyx_XGOTREF(__pyx_r);
+          if (likely(__pyx_r)) {
+            __Pyx_XGIVEREF(__pyx_t_3);
+            __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
+            __Pyx_XGIVEREF(__pyx_t_5);
+            __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
+            __Pyx_XGIVEREF(__pyx_t_6);
+            __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
+            __Pyx_XGIVEREF(__pyx_t_7);
+            __pyx_cur_scope->__pyx_t_3 = __pyx_t_7;
+            __Pyx_XGIVEREF(__pyx_t_8);
+            __pyx_cur_scope->__pyx_t_6 = __pyx_t_8;
+            __Pyx_XGIVEREF(__pyx_t_11);
+            __pyx_cur_scope->__pyx_t_7 = __pyx_t_11;
+            __Pyx_XGIVEREF(__pyx_t_22);
+            __pyx_cur_scope->__pyx_t_8 = __pyx_t_22;
+            __Pyx_XGIVEREF(__pyx_t_24);
+            __pyx_cur_scope->__pyx_t_9 = __pyx_t_24;
+            __Pyx_XGIVEREF(__pyx_t_25);
+            __pyx_cur_scope->__pyx_t_10 = __pyx_t_25;
+            __Pyx_XGIVEREF(__pyx_r);
+            __Pyx_RefNannyFinishContext();
+            __Pyx_Coroutine_SwapException(__pyx_generator);
+            /* return from generator, awaiting value */
+            __pyx_generator->resume_label = 7;
+            return __pyx_r;
+            __pyx_L110_resume_from_await:;
+            __pyx_t_3 = __pyx_cur_scope->__pyx_t_0;
+            __pyx_cur_scope->__pyx_t_0 = 0;
+            __Pyx_XGOTREF(__pyx_t_3);
+            __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
+            __pyx_cur_scope->__pyx_t_1 = 0;
+            __Pyx_XGOTREF(__pyx_t_5);
+            __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
+            __pyx_cur_scope->__pyx_t_2 = 0;
+            __Pyx_XGOTREF(__pyx_t_6);
+            __pyx_t_7 = __pyx_cur_scope->__pyx_t_3;
+            __pyx_cur_scope->__pyx_t_3 = 0;
+            __Pyx_XGOTREF(__pyx_t_7);
+            __pyx_t_8 = __pyx_cur_scope->__pyx_t_6;
+            __pyx_cur_scope->__pyx_t_6 = 0;
+            __Pyx_XGOTREF(__pyx_t_8);
+            __pyx_t_11 = __pyx_cur_scope->__pyx_t_7;
+            __pyx_cur_scope->__pyx_t_7 = 0;
+            __Pyx_XGOTREF(__pyx_t_11);
+            __pyx_t_22 = __pyx_cur_scope->__pyx_t_8;
+            __pyx_cur_scope->__pyx_t_8 = 0;
+            __Pyx_XGOTREF(__pyx_t_22);
+            __pyx_t_24 = __pyx_cur_scope->__pyx_t_9;
+            __pyx_cur_scope->__pyx_t_9 = 0;
+            __Pyx_XGOTREF(__pyx_t_24);
+            __pyx_t_25 = __pyx_cur_scope->__pyx_t_10;
+            __pyx_cur_scope->__pyx_t_10 = 0;
+            __Pyx_XGOTREF(__pyx_t_25);
+            if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 473, __pyx_L102_error)
+          } else {
+            PyObject* exc_type = __Pyx_PyErr_Occurred();
+            if (exc_type) {
+              if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+              else __PYX_ERR(0, 473, __pyx_L102_error)
+            }
+          }
+
+          /* "asyncpg/protocol/protocol.pyx":472
+ *             self._write_copy_fail_msg('TimeoutError')
+ *             self._on_timeout(self.waiter)
+ *             try:             # <<<<<<<<<<<<<<
+ *                 await waiter
+ *             except TimeoutError:
+ */
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":477
+ *                 raise
+ *             else:
+ *                 raise apg_exc.InternalClientError('TimoutError was not raised')             # <<<<<<<<<<<<<<
+ * 
+ *         except Exception as e:
+ */
+        /*else:*/ {
+          __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 477, __pyx_L104_except_error)
+          __Pyx_GOTREF(__pyx_t_12);
+          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 477, __pyx_L104_except_error)
+          __Pyx_GOTREF(__pyx_t_16);
+          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __pyx_t_12 = NULL;
+          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
+            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_16);
+            if (likely(__pyx_t_12)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
+              __Pyx_INCREF(__pyx_t_12);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_16, function);
+            }
+          }
+          __pyx_t_4 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_16, __pyx_t_12, __pyx_kp_u_TimoutError_was_not_raised) : __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_kp_u_TimoutError_was_not_raised);
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 477, __pyx_L104_except_error)
+          __Pyx_GOTREF(__pyx_t_4);
+          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+          __Pyx_Raise(__pyx_t_4, 0, 0, 0);
+          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+          __PYX_ERR(0, 477, __pyx_L104_except_error)
+        }
+        __pyx_L102_error:;
+        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":474
+ *             try:
+ *                 await waiter
+ *             except TimeoutError:             # <<<<<<<<<<<<<<
+ *                 raise
+ *             else:
+ */
+        __Pyx_ErrFetch(&__pyx_t_4, &__pyx_t_16, &__pyx_t_12);
+        __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_TimeoutError); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 474, __pyx_L104_except_error)
+        __Pyx_GOTREF(__pyx_t_13);
+        __pyx_t_15 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_4, __pyx_t_13);
+        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_ErrRestore(__pyx_t_4, __pyx_t_16, __pyx_t_12);
+        __pyx_t_4 = 0; __pyx_t_16 = 0; __pyx_t_12 = 0;
+        if (__pyx_t_15) {
+          __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+          if (__Pyx_GetException(&__pyx_t_12, &__pyx_t_16, &__pyx_t_4) < 0) __PYX_ERR(0, 474, __pyx_L104_except_error)
+          __Pyx_GOTREF(__pyx_t_12);
+          __Pyx_GOTREF(__pyx_t_16);
+          __Pyx_GOTREF(__pyx_t_4);
+
+          /* "asyncpg/protocol/protocol.pyx":475
+ *                 await waiter
+ *             except TimeoutError:
+ *                 raise             # <<<<<<<<<<<<<<
+ *             else:
+ *                 raise apg_exc.InternalClientError('TimoutError was not raised')
+ */
+          __Pyx_GIVEREF(__pyx_t_12);
+          __Pyx_GIVEREF(__pyx_t_16);
+          __Pyx_XGIVEREF(__pyx_t_4);
+          __Pyx_ErrRestoreWithState(__pyx_t_12, __pyx_t_16, __pyx_t_4);
+          __pyx_t_12 = 0; __pyx_t_16 = 0; __pyx_t_4 = 0; 
+          __PYX_ERR(0, 475, __pyx_L104_except_error)
+        }
+        goto __pyx_L104_except_error;
+        __pyx_L104_except_error:;
+
+        /* "asyncpg/protocol/protocol.pyx":472
+ *             self._write_copy_fail_msg('TimeoutError')
+ *             self._on_timeout(self.waiter)
+ *             try:             # <<<<<<<<<<<<<<
+ *                 await waiter
+ *             except TimeoutError:
+ */
+        __Pyx_XGIVEREF(__pyx_t_22);
+        __Pyx_XGIVEREF(__pyx_t_25);
+        __Pyx_XGIVEREF(__pyx_t_24);
+        __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_25, __pyx_t_24);
+        goto __pyx_L10_except_error;
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":479
+ *                 raise apg_exc.InternalClientError('TimoutError was not raised')
+ * 
+ *         except Exception as e:             # <<<<<<<<<<<<<<
+ *             self._write_copy_fail_msg(str(e))
+ *             self._request_cancel()
+ */
+    __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+    if (__pyx_t_15) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_5, &__pyx_t_3) < 0) __PYX_ERR(0, 479, __pyx_L10_except_error)
+      __Pyx_GOTREF(__pyx_t_11);
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_GIVEREF(__pyx_t_5);
+      __pyx_cur_scope->__pyx_v_e = __pyx_t_5;
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":480
+ * 
+ *         except Exception as e:
+ *             self._write_copy_fail_msg(str(e))             # <<<<<<<<<<<<<<
+ *             self._request_cancel()
+ *             # Make asyncio shut up about unretrieved QueryCanceledError
+ */
+        __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyUnicode_Type)), __pyx_cur_scope->__pyx_v_e); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 480, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_16 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_fail_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject*)__pyx_t_4)); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 480, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_16);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":481
+ *         except Exception as e:
+ *             self._write_copy_fail_msg(str(e))
+ *             self._request_cancel()             # <<<<<<<<<<<<<<
+ *             # Make asyncio shut up about unretrieved QueryCanceledError
+ *             waiter.add_done_callback(lambda f: f.exception())
+ */
+        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_request_cancel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 481, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_12 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
+          if (likely(__pyx_t_12)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+            __Pyx_INCREF(__pyx_t_12);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_4, function);
+          }
+        }
+        __pyx_t_16 = (__pyx_t_12) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_12) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 481, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_16);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":483
+ *             self._request_cancel()
+ *             # Make asyncio shut up about unretrieved QueryCanceledError
+ *             waiter.add_done_callback(lambda f: f.exception())             # <<<<<<<<<<<<<<
+ *             raise
+ * 
+ */
+        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_add_done_callback); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 483, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_12 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_12BaseProtocol_7copy_in_lambda2, 0, __pyx_n_s_copy_in_locals_lambda, NULL, __pyx_n_s_asyncpg_protocol_protocol, __pyx_d, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 483, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_12);
+        __pyx_t_13 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_4);
+          if (likely(__pyx_t_13)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+            __Pyx_INCREF(__pyx_t_13);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_4, function);
+          }
+        }
+        __pyx_t_16 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_13, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_12);
+        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+        if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 483, __pyx_L118_error)
+        __Pyx_GOTREF(__pyx_t_16);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":484
+ *             # Make asyncio shut up about unretrieved QueryCanceledError
+ *             waiter.add_done_callback(lambda f: f.exception())
+ *             raise             # <<<<<<<<<<<<<<
+ * 
+ *         self._write_copy_done_msg()
+ */
+        __Pyx_GIVEREF(__pyx_t_11);
+        __Pyx_GIVEREF(__pyx_t_5);
+        __Pyx_XGIVEREF(__pyx_t_3);
+        __Pyx_ErrRestoreWithState(__pyx_t_11, __pyx_t_5, __pyx_t_3);
+        __pyx_t_11 = 0; __pyx_t_5 = 0; __pyx_t_3 = 0; 
+        __PYX_ERR(0, 484, __pyx_L118_error)
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":479
+ *                 raise apg_exc.InternalClientError('TimoutError was not raised')
+ * 
+ *         except Exception as e:             # <<<<<<<<<<<<<<
+ *             self._write_copy_fail_msg(str(e))
+ *             self._request_cancel()
+ */
+      /*finally:*/ {
+        __pyx_L118_error:;
+        /*exception exit:*/{
+          __Pyx_PyThreadState_assign
+          __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_26 = 0; __pyx_t_27 = 0;
+          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
+          if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_23, &__pyx_t_26, &__pyx_t_27);
+          if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_24, &__pyx_t_25, &__pyx_t_22) < 0)) __Pyx_ErrFetch(&__pyx_t_24, &__pyx_t_25, &__pyx_t_22);
+          __Pyx_XGOTREF(__pyx_t_24);
+          __Pyx_XGOTREF(__pyx_t_25);
+          __Pyx_XGOTREF(__pyx_t_22);
+          __Pyx_XGOTREF(__pyx_t_23);
+          __Pyx_XGOTREF(__pyx_t_26);
+          __Pyx_XGOTREF(__pyx_t_27);
+          __pyx_t_15 = __pyx_lineno; __pyx_t_30 = __pyx_clineno; __pyx_t_31 = __pyx_filename;
+          {
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_e);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_e);
+            __pyx_cur_scope->__pyx_v_e = NULL;
+          }
+          if (PY_MAJOR_VERSION >= 3) {
+            __Pyx_XGIVEREF(__pyx_t_23);
+            __Pyx_XGIVEREF(__pyx_t_26);
+            __Pyx_XGIVEREF(__pyx_t_27);
+            __Pyx_ExceptionReset(__pyx_t_23, __pyx_t_26, __pyx_t_27);
+          }
+          __Pyx_XGIVEREF(__pyx_t_24);
+          __Pyx_XGIVEREF(__pyx_t_25);
+          __Pyx_XGIVEREF(__pyx_t_22);
+          __Pyx_ErrRestore(__pyx_t_24, __pyx_t_25, __pyx_t_22);
+          __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_26 = 0; __pyx_t_27 = 0;
+          __pyx_lineno = __pyx_t_15; __pyx_clineno = __pyx_t_30; __pyx_filename = __pyx_t_31;
+          goto __pyx_L10_except_error;
+        }
+      }
+    }
+    goto __pyx_L10_except_error;
+    __pyx_L10_except_error:;
+
+    /* "asyncpg/protocol/protocol.pyx":397
+ *         self._copy_in(copy_stmt)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             if record_stmt is not None:
+ *                 # copy_in_records in binary mode
+ */
+    __Pyx_XGIVEREF(__pyx_t_6);
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+    goto __pyx_L1_error;
+    __pyx_L13_try_end:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":486
+ *             raise
+ * 
+ *         self._write_copy_done_msg()             # <<<<<<<<<<<<<<
+ * 
+ *         status_msg = await waiter
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._write_copy_done_msg(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 486, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":488
+ *         self._write_copy_done_msg()
+ * 
+ *         status_msg = await waiter             # <<<<<<<<<<<<<<
+ * 
+ *         return status_msg
+ */
+  __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+  __Pyx_XGOTREF(__pyx_r);
+  if (likely(__pyx_r)) {
+    __Pyx_XGIVEREF(__pyx_r);
+    __Pyx_RefNannyFinishContext();
+    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+    /* return from generator, awaiting value */
+    __pyx_generator->resume_label = 8;
+    return __pyx_r;
+    __pyx_L124_resume_from_await:;
+    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 488, __pyx_L1_error)
+    __pyx_t_3 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_3);
+  } else {
+    __pyx_t_3 = NULL;
+    if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_3) < 0) __PYX_ERR(0, 488, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+  }
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_status_msg = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":490
+ *         status_msg = await waiter
+ * 
+ *         return status_msg             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_cur_scope->__pyx_v_status_msg);
+  goto __pyx_L0;
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":374
+ * 
+ *     @cython.iterable_coroutine
+ *     async def copy_in(self, copy_stmt, reader, data,             # <<<<<<<<<<<<<<
+ *                       records, PreparedStatementState record_stmt, timeout):
+ *         cdef:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_16);
+  __Pyx_AddTraceback("copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_36generator8(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":493
+ * 
+ *     @cython.iterable_coroutine
+ *     async def close_statement(self, PreparedStatementState state, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_35close_statement(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_35close_statement(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state = 0;
+  PyObject *__pyx_v_timeout = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("close_statement (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_state,&__pyx_n_s_timeout,0};
+    PyObject* values[2] = {0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_state)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_timeout)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("close_statement", 1, 2, 2, 1); __PYX_ERR(0, 493, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "close_statement") < 0)) __PYX_ERR(0, 493, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+    }
+    __pyx_v_state = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)values[0]);
+    __pyx_v_timeout = values[1];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("close_statement", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 493, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.close_statement", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState, 1, "state", 0))) __PYX_ERR(0, 493, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_34close_statement(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), __pyx_v_state, __pyx_v_timeout);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_34close_statement(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *__pyx_v_state, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("close_statement", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 493, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_state = __pyx_v_state;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_state);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_36generator8, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_close_statement, __pyx_n_s_BaseProtocol_close_statement, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 493, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.close_statement", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_36generator8(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  int __pyx_t_12;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("close_statement", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    case 3: goto __pyx_L29_resume_from_await;
+    case 4: goto __pyx_L32_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 493, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":494
+ *     @cython.iterable_coroutine
+ *     async def close_statement(self, PreparedStatementState state, timeout):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":495
+ *     async def close_statement(self, PreparedStatementState state, timeout):
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 495, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 495, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":494
+ *     @cython.iterable_coroutine
+ *     async def close_statement(self, PreparedStatementState state, timeout):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":496
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":497
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 497, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 497, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":498
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         self._check_state()
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":496
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":500
+ *             self.cancel_sent_waiter = None
+ * 
+ *         self._check_state()             # <<<<<<<<<<<<<<
+ * 
+ *         if state.refs != 0:
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_check_state(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":502
+ *         self._check_state()
+ * 
+ *         if state.refs != 0:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError(
+ *                 'cannot close prepared statement; refs == {} != 0'.format(
+ */
+  __pyx_t_1 = ((__pyx_cur_scope->__pyx_v_state->refs != 0) != 0);
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/protocol/protocol.pyx":503
+ * 
+ *         if state.refs != 0:
+ *             raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                 'cannot close prepared statement; refs == {} != 0'.format(
+ *                     state.refs))
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 503, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":504
+ *         if state.refs != 0:
+ *             raise apg_exc.InternalClientError(
+ *                 'cannot close prepared statement; refs == {} != 0'.format(             # <<<<<<<<<<<<<<
+ *                     state.refs))
+ * 
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_cannot_close_prepared_statement, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 504, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+
+    /* "asyncpg/protocol/protocol.pyx":505
+ *             raise apg_exc.InternalClientError(
+ *                 'cannot close prepared statement; refs == {} != 0'.format(
+ *                     state.refs))             # <<<<<<<<<<<<<<
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ */
+    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_state->refs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 505, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_8 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7);
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 504, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(0, 503, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":502
+ *         self._check_state()
+ * 
+ *         if state.refs != 0:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError(
+ *                 'cannot close prepared statement; refs == {} != 0'.format(
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":507
+ *                     state.refs))
+ * 
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 507, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":508
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ *         waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         try:
+ *             self._close(state.name, False)  # network op
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_cur_scope->__pyx_v_waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":509
+ *         timeout = self._get_timeout_impl(timeout)
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._close(state.name, False)  # network op
+ *             state.closed = True
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __Pyx_XGOTREF(__pyx_t_11);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":510
+ *         waiter = self._new_waiter(timeout)
+ *         try:
+ *             self._close(state.name, False)  # network op             # <<<<<<<<<<<<<<
+ *             state.closed = True
+ *         except Exception as ex:
+ */
+        __pyx_t_3 = __pyx_cur_scope->__pyx_v_state->name;
+        __Pyx_INCREF(__pyx_t_3);
+        __pyx_t_5 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._close(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self), ((PyObject*)__pyx_t_3), 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 510, __pyx_L12_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":511
+ *         try:
+ *             self._close(state.name, False)  # network op
+ *             state.closed = True             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ */
+        __pyx_cur_scope->__pyx_v_state->closed = 1;
+
+        /* "asyncpg/protocol/protocol.pyx":509
+ *         timeout = self._get_timeout_impl(timeout)
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._close(state.name, False)  # network op
+ *             state.closed = True
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      goto __pyx_L17_try_end;
+      __pyx_L12_error:;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":512
+ *             self._close(state.name, False)  # network op
+ *             state.closed = True
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+      __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+      if (__pyx_t_12) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.close_statement", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(0, 512, __pyx_L14_except_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_GIVEREF(__pyx_t_3);
+        __pyx_cur_scope->__pyx_v_ex = __pyx_t_3;
+        /*try:*/ {
+
+          /* "asyncpg/protocol/protocol.pyx":513
+ *             state.closed = True
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)             # <<<<<<<<<<<<<<
+ *             self._coreproto_error()
+ *         finally:
+ */
+          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 513, __pyx_L23_error)
+          __Pyx_GOTREF(__pyx_t_7);
+          __pyx_t_8 = NULL;
+          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+            if (likely(__pyx_t_8)) {
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+              __Pyx_INCREF(__pyx_t_8);
+              __Pyx_INCREF(function);
+              __Pyx_DECREF_SET(__pyx_t_7, function);
+            }
+          }
+          __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_cur_scope->__pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v_ex);
+          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 513, __pyx_L23_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+          /* "asyncpg/protocol/protocol.pyx":514
+ *         except Exception as ex:
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             return await waiter
+ */
+          __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_coreproto_error(__pyx_cur_scope->__pyx_v_self); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 514, __pyx_L23_error)
+          __Pyx_GOTREF(__pyx_t_6);
+          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":512
+ *             self._close(state.name, False)  # network op
+ *             state.closed = True
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(ex)
+ *             self._coreproto_error()
+ */
+        /*finally:*/ {
+          /*normal exit:*/{
+            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+            __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+            __pyx_cur_scope->__pyx_v_ex = NULL;
+            goto __pyx_L24;
+          }
+          __pyx_L23_error:;
+          /*exception exit:*/{
+            __Pyx_PyThreadState_assign
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+            if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+            if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_15);
+            __Pyx_XGOTREF(__pyx_t_16);
+            __Pyx_XGOTREF(__pyx_t_17);
+            __Pyx_XGOTREF(__pyx_t_18);
+            __Pyx_XGOTREF(__pyx_t_19);
+            __Pyx_XGOTREF(__pyx_t_20);
+            __pyx_t_12 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+            {
+              __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ex);
+              __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ex);
+              __pyx_cur_scope->__pyx_v_ex = NULL;
+            }
+            if (PY_MAJOR_VERSION >= 3) {
+              __Pyx_XGIVEREF(__pyx_t_18);
+              __Pyx_XGIVEREF(__pyx_t_19);
+              __Pyx_XGIVEREF(__pyx_t_20);
+              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+            }
+            __Pyx_XGIVEREF(__pyx_t_15);
+            __Pyx_XGIVEREF(__pyx_t_16);
+            __Pyx_XGIVEREF(__pyx_t_17);
+            __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+            __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+            __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+            goto __pyx_L14_except_error;
+          }
+          __pyx_L24:;
+        }
+        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        goto __pyx_L13_exception_handled;
+      }
+      goto __pyx_L14_except_error;
+      __pyx_L14_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":509
+ *         timeout = self._get_timeout_impl(timeout)
+ *         waiter = self._new_waiter(timeout)
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._close(state.name, False)  # network op
+ *             state.closed = True
+ */
+      __Pyx_XGIVEREF(__pyx_t_9);
+      __Pyx_XGIVEREF(__pyx_t_10);
+      __Pyx_XGIVEREF(__pyx_t_11);
+      __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
+      goto __pyx_L10_error;
+      __pyx_L13_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_9);
+      __Pyx_XGIVEREF(__pyx_t_10);
+      __Pyx_XGIVEREF(__pyx_t_11);
+      __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
+      __pyx_L17_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":516
+ *             self._coreproto_error()
+ *         finally:
+ *             return await waiter             # <<<<<<<<<<<<<<
+ * 
+ *     def is_closed(self):
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 3;
+        return __pyx_r;
+        __pyx_L29_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 516, __pyx_L1_error)
+        __pyx_t_4 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_4);
+      } else {
+        __pyx_t_4 = NULL;
+        if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_4) < 0) __PYX_ERR(0, 516, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+      }
+      __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = 0;
+      goto __pyx_L0;
+    }
+    __pyx_L10_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_20);
+      __Pyx_XGOTREF(__pyx_t_19);
+      __Pyx_XGOTREF(__pyx_t_18);
+      {
+        __Pyx_XDECREF(__pyx_r);
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_9);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_9;
+          __Pyx_XGIVEREF(__pyx_t_10);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_10;
+          __Pyx_XGIVEREF(__pyx_t_11);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_11;
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __pyx_cur_scope->__pyx_t_3 = __pyx_t_18;
+          __Pyx_XGIVEREF(__pyx_t_19);
+          __pyx_cur_scope->__pyx_t_4 = __pyx_t_19;
+          __Pyx_XGIVEREF(__pyx_t_20);
+          __pyx_cur_scope->__pyx_t_5 = __pyx_t_20;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 4;
+          return __pyx_r;
+          __pyx_L32_resume_from_await:;
+          __pyx_t_9 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_9);
+          __pyx_t_10 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_10);
+          __pyx_t_11 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_11);
+          __pyx_t_18 = __pyx_cur_scope->__pyx_t_3;
+          __pyx_cur_scope->__pyx_t_3 = 0;
+          __Pyx_XGOTREF(__pyx_t_18);
+          __pyx_t_19 = __pyx_cur_scope->__pyx_t_4;
+          __pyx_cur_scope->__pyx_t_4 = 0;
+          __Pyx_XGOTREF(__pyx_t_19);
+          __pyx_t_20 = __pyx_cur_scope->__pyx_t_5;
+          __pyx_cur_scope->__pyx_t_5 = 0;
+          __Pyx_XGOTREF(__pyx_t_20);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 516, __pyx_L31_error)
+          __pyx_t_4 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_4);
+        } else {
+          __pyx_t_4 = NULL;
+          if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_4) < 0) __PYX_ERR(0, 516, __pyx_L31_error)
+          __Pyx_GOTREF(__pyx_t_4);
+        }
+        __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __pyx_t_4 = 0;
+        goto __pyx_L30_return;
+      }
+      __pyx_L30_return:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L0;
+      __pyx_L31_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_20);
+        __Pyx_XGIVEREF(__pyx_t_19);
+        __Pyx_XGIVEREF(__pyx_t_18);
+        __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18);
+      }
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0;
+      goto __pyx_L1_error;
+    }
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":493
+ * 
+ *     @cython.iterable_coroutine
+ *     async def close_statement(self, PreparedStatementState state, timeout):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("close_statement", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":518
+ *             return await waiter
+ * 
+ *     def is_closed(self):             # <<<<<<<<<<<<<<
+ *         return self.closing
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_38is_closed(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_38is_closed(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("is_closed (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_37is_closed(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_37is_closed(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("is_closed", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":519
+ * 
+ *     def is_closed(self):
+ *         return self.closing             # <<<<<<<<<<<<<<
+ * 
+ *     def is_connected(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->closing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":518
+ *             return await waiter
+ * 
+ *     def is_closed(self):             # <<<<<<<<<<<<<<
+ *         return self.closing
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.is_closed", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":521
+ *         return self.closing
+ * 
+ *     def is_connected(self):             # <<<<<<<<<<<<<<
+ *         return not self.closing and self.con_status == CONNECTION_OK
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_40is_connected(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_40is_connected(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("is_connected (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_39is_connected(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_39is_connected(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("is_connected", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":522
+ * 
+ *     def is_connected(self):
+ *         return not self.closing and self.con_status == CONNECTION_OK             # <<<<<<<<<<<<<<
+ * 
+ *     def abort(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = (!(__pyx_v_self->closing != 0));
+  if (__pyx_t_2) {
+  } else {
+    __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 522, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_1 = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+  __pyx_t_2 = (__pyx_v_self->__pyx_base.con_status == __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_OK);
+  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 522, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_1 = __pyx_t_3;
+  __pyx_t_3 = 0;
+  __pyx_L3_bool_binop_done:;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":521
+ *         return self.closing
+ * 
+ *     def is_connected(self):             # <<<<<<<<<<<<<<
+ *         return not self.closing and self.con_status == CONNECTION_OK
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.is_connected", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":524
+ *         return not self.closing and self.con_status == CONNECTION_OK
+ * 
+ *     def abort(self):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             return
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_42abort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_42abort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("abort (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_41abort(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_41abort(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("abort", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":525
+ * 
+ *     def abort(self):
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             return
+ *         self.closing = True
+ */
+  __pyx_t_1 = (__pyx_v_self->closing != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":526
+ *     def abort(self):
+ *         if self.closing:
+ *             return             # <<<<<<<<<<<<<<
+ *         self.closing = True
+ *         self._handle_waiter_on_connection_lost(None)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":525
+ * 
+ *     def abort(self):
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             return
+ *         self.closing = True
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":527
+ *         if self.closing:
+ *             return
+ *         self.closing = True             # <<<<<<<<<<<<<<
+ *         self._handle_waiter_on_connection_lost(None)
+ *         self._terminate()
+ */
+  __pyx_v_self->closing = 1;
+
+  /* "asyncpg/protocol/protocol.pyx":528
+ *             return
+ *         self.closing = True
+ *         self._handle_waiter_on_connection_lost(None)             # <<<<<<<<<<<<<<
+ *         self._terminate()
+ *         self.transport.abort()
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_handle_waiter_on_connection_lost(__pyx_v_self, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":529
+ *         self.closing = True
+ *         self._handle_waiter_on_connection_lost(None)
+ *         self._terminate()             # <<<<<<<<<<<<<<
+ *         self.transport.abort()
+ * 
+ */
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._terminate(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 529, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":530
+ *         self._handle_waiter_on_connection_lost(None)
+ *         self._terminate()
+ *         self.transport.abort()             # <<<<<<<<<<<<<<
+ * 
+ *     @cython.iterable_coroutine
+ */
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.transport, __pyx_n_s_abort); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 530, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":524
+ *         return not self.closing and self.con_status == CONNECTION_OK
+ * 
+ *     def abort(self):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             return
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.abort", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_45generator9(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":533
+ * 
+ *     @cython.iterable_coroutine
+ *     async def close(self, timeout):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             return
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_44close(PyObject *__pyx_v_self, PyObject *__pyx_v_timeout); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_44close(PyObject *__pyx_v_self, PyObject *__pyx_v_timeout) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("close (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_43close(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_timeout));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_43close(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("close", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 533, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __pyx_cur_scope->__pyx_v_timeout = __pyx_v_timeout;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_timeout);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_45generator9, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_close, __pyx_n_s_BaseProtocol_close, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 533, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_45generator9(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_t_10;
+  int __pyx_t_11;
+  char const *__pyx_t_12;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("close", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L6_resume_from_await;
+    case 2: goto __pyx_L8_resume_from_await;
+    case 3: goto __pyx_L10_resume_from_await;
+    case 4: goto __pyx_L12_resume_from_await;
+    case 5: goto __pyx_L22_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 533, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":534
+ *     @cython.iterable_coroutine
+ *     async def close(self, timeout):
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->closing != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":535
+ *     async def close(self, timeout):
+ *         if self.closing:
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         self.closing = True
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = NULL;
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":534
+ *     @cython.iterable_coroutine
+ *     async def close(self, timeout):
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":537
+ *             return
+ * 
+ *         self.closing = True             # <<<<<<<<<<<<<<
+ * 
+ *         if self.cancel_sent_waiter is not None:
+ */
+  __pyx_cur_scope->__pyx_v_self->closing = 1;
+
+  /* "asyncpg/protocol/protocol.pyx":539
+ *         self.closing = True
+ * 
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":540
+ * 
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ * 
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L6_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 540, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 540, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":541
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         if self.cancel_waiter is not None:
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":539
+ *         self.closing = True
+ * 
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":543
+ *             self.cancel_sent_waiter = None
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ * 
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":544
+ * 
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ * 
+ *         if self.waiter is not None:
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L8_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 544, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 544, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":543
+ *             self.cancel_sent_waiter = None
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":546
+ *             await self.cancel_waiter
+ * 
+ *         if self.waiter is not None:             # <<<<<<<<<<<<<<
+ *             # If there is a query running, cancel it
+ *             self._request_cancel()
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":548
+ *         if self.waiter is not None:
+ *             # If there is a query running, cancel it
+ *             self._request_cancel()             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_request_cancel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 548, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 548, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":549
+ *             # If there is a query running, cancel it
+ *             self._request_cancel()
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ *             if self.cancel_waiter is not None:
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 3;
+      return __pyx_r;
+      __pyx_L10_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 549, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 549, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":550
+ *             self._request_cancel()
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ *             if self.cancel_waiter is not None:
+ *                 await self.cancel_waiter
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":551
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ *             if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *                 await self.cancel_waiter
+ * 
+ */
+    __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+    __pyx_t_1 = (__pyx_t_2 != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/protocol.pyx":552
+ *             self.cancel_sent_waiter = None
+ *             if self.cancel_waiter is not None:
+ *                 await self.cancel_waiter             # <<<<<<<<<<<<<<
+ * 
+ *         assert self.waiter is None
+ */
+      __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+      __Pyx_XGOTREF(__pyx_r);
+      if (likely(__pyx_r)) {
+        __Pyx_XGIVEREF(__pyx_r);
+        __Pyx_RefNannyFinishContext();
+        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+        /* return from generator, awaiting value */
+        __pyx_generator->resume_label = 4;
+        return __pyx_r;
+        __pyx_L12_resume_from_await:;
+        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 552, __pyx_L1_error)
+      } else {
+        PyObject* exc_type = __Pyx_PyErr_Occurred();
+        if (exc_type) {
+          if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+          else __PYX_ERR(0, 552, __pyx_L1_error)
+        }
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":551
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ *             if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *                 await self.cancel_waiter
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":546
+ *             await self.cancel_waiter
+ * 
+ *         if self.waiter is not None:             # <<<<<<<<<<<<<<
+ *             # If there is a query running, cancel it
+ *             self._request_cancel()
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":554
+ *                 await self.cancel_waiter
+ * 
+ *         assert self.waiter is None             # <<<<<<<<<<<<<<
+ * 
+ *         timeout = self._get_timeout_impl(timeout)
+ */
+  #ifndef CYTHON_WITHOUT_ASSERTIONS
+  if (unlikely(!Py_OptimizeFlag)) {
+    __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->waiter == Py_None);
+    if (unlikely(!(__pyx_t_1 != 0))) {
+      PyErr_SetNone(PyExc_AssertionError);
+      __PYX_ERR(0, 554, __pyx_L1_error)
+    }
+  }
+  #endif
+
+  /* "asyncpg/protocol/protocol.pyx":556
+ *         assert self.waiter is None
+ * 
+ *         timeout = self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         # Ask the server to terminate the connection and wait for it
+ */
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 556, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_timeout);
+  __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_timeout, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":560
+ *         # Ask the server to terminate the connection and wait for it
+ *         # to drop.
+ *         self.waiter = self._new_waiter(timeout)             # <<<<<<<<<<<<<<
+ *         self._terminate()
+ *         try:
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->_new_waiter(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->waiter);
+  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->waiter);
+  __pyx_cur_scope->__pyx_v_self->waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":561
+ *         # to drop.
+ *         self.waiter = self._new_waiter(timeout)
+ *         self._terminate()             # <<<<<<<<<<<<<<
+ *         try:
+ *             await self.waiter
+ */
+  __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._terminate(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 561, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":562
+ *         self.waiter = self._new_waiter(timeout)
+ *         self._terminate()
+ *         try:             # <<<<<<<<<<<<<<
+ *             await self.waiter
+ *         except ConnectionResetError:
+ */
+  /*try:*/ {
+    {
+      __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_8);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":563
+ *         self._terminate()
+ *         try:
+ *             await self.waiter             # <<<<<<<<<<<<<<
+ *         except ConnectionResetError:
+ *             # There appears to be a difference in behaviour of asyncio
+ */
+        __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->waiter);
+        __Pyx_XGOTREF(__pyx_r);
+        if (likely(__pyx_r)) {
+          __Pyx_XGIVEREF(__pyx_t_6);
+          __pyx_cur_scope->__pyx_t_0 = __pyx_t_6;
+          __Pyx_XGIVEREF(__pyx_t_7);
+          __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
+          __Pyx_XGIVEREF(__pyx_t_8);
+          __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
+          __Pyx_XGIVEREF(__pyx_r);
+          __Pyx_RefNannyFinishContext();
+          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+          /* return from generator, awaiting value */
+          __pyx_generator->resume_label = 5;
+          return __pyx_r;
+          __pyx_L22_resume_from_await:;
+          __pyx_t_6 = __pyx_cur_scope->__pyx_t_0;
+          __pyx_cur_scope->__pyx_t_0 = 0;
+          __Pyx_XGOTREF(__pyx_t_6);
+          __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
+          __pyx_cur_scope->__pyx_t_1 = 0;
+          __Pyx_XGOTREF(__pyx_t_7);
+          __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
+          __pyx_cur_scope->__pyx_t_2 = 0;
+          __Pyx_XGOTREF(__pyx_t_8);
+          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 563, __pyx_L16_error)
+        } else {
+          PyObject* exc_type = __Pyx_PyErr_Occurred();
+          if (exc_type) {
+            if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+            else __PYX_ERR(0, 563, __pyx_L16_error)
+          }
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":562
+ *         self.waiter = self._new_waiter(timeout)
+ *         self._terminate()
+ *         try:             # <<<<<<<<<<<<<<
+ *             await self.waiter
+ *         except ConnectionResetError:
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+      goto __pyx_L21_try_end;
+      __pyx_L16_error:;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":564
+ *         try:
+ *             await self.waiter
+ *         except ConnectionResetError:             # <<<<<<<<<<<<<<
+ *             # There appears to be a difference in behaviour of asyncio
+ *             # in Windows, where, instead of calling protocol.connection_lost()
+ */
+      __Pyx_ErrFetch(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
+      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ConnectionResetError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 564, __pyx_L18_except_error)
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_10 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_3, __pyx_t_9);
+      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_ErrRestore(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+      __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0;
+      if (__pyx_t_10) {
+        __Pyx_ErrRestore(0,0,0);
+        goto __pyx_L17_exception_handled;
+      }
+      goto __pyx_L18_except_error;
+      __pyx_L18_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":562
+ *         self.waiter = self._new_waiter(timeout)
+ *         self._terminate()
+ *         try:             # <<<<<<<<<<<<<<
+ *             await self.waiter
+ *         except ConnectionResetError:
+ */
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+      goto __pyx_L14_error;
+      __pyx_L17_exception_handled:;
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
+      __pyx_L21_try_end:;
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":570
+ *             pass
+ *         finally:
+ *             self.waiter = None             # <<<<<<<<<<<<<<
+ *         self.transport.abort()
+ * 
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_INCREF(Py_None);
+      __Pyx_GIVEREF(Py_None);
+      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->waiter);
+      __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->waiter);
+      __pyx_cur_scope->__pyx_v_self->waiter = Py_None;
+      goto __pyx_L15;
+    }
+    __pyx_L14_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_assign
+      __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6) < 0)) __Pyx_ErrFetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_8);
+      __Pyx_XGOTREF(__pyx_t_7);
+      __Pyx_XGOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_t_13);
+      __Pyx_XGOTREF(__pyx_t_14);
+      __Pyx_XGOTREF(__pyx_t_15);
+      __pyx_t_10 = __pyx_lineno; __pyx_t_11 = __pyx_clineno; __pyx_t_12 = __pyx_filename;
+      {
+        __Pyx_INCREF(Py_None);
+        __Pyx_GIVEREF(Py_None);
+        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->waiter);
+        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->waiter);
+        __pyx_cur_scope->__pyx_v_self->waiter = Py_None;
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_XGIVEREF(__pyx_t_14);
+        __Pyx_XGIVEREF(__pyx_t_15);
+        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
+      }
+      __Pyx_XGIVEREF(__pyx_t_8);
+      __Pyx_XGIVEREF(__pyx_t_7);
+      __Pyx_XGIVEREF(__pyx_t_6);
+      __Pyx_ErrRestore(__pyx_t_8, __pyx_t_7, __pyx_t_6);
+      __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
+      __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_11; __pyx_filename = __pyx_t_12;
+      goto __pyx_L1_error;
+    }
+    __pyx_L15:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":571
+ *         finally:
+ *             self.waiter = None
+ *         self.transport.abort()             # <<<<<<<<<<<<<<
+ * 
+ *     def _request_cancel(self):
+ */
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self->__pyx_base.transport, __pyx_n_s_abort); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":533
+ * 
+ *     @cython.iterable_coroutine
+ *     async def close(self, timeout):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             return
+ */
+
+  /* function exit code */
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("close", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":573
+ *         self.transport.abort()
+ * 
+ *     def _request_cancel(self):             # <<<<<<<<<<<<<<
+ *         self.cancel_waiter = self.create_future()
+ *         self.cancel_sent_waiter = self.create_future()
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_47_request_cancel(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_47_request_cancel(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_request_cancel (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_46_request_cancel(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_46_request_cancel(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_v_con = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("_request_cancel", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":574
+ * 
+ *     def _request_cancel(self):
+ *         self.cancel_waiter = self.create_future()             # <<<<<<<<<<<<<<
+ *         self.cancel_sent_waiter = self.create_future()
+ * 
+ */
+  __Pyx_INCREF(__pyx_v_self->create_future);
+  __pyx_t_2 = __pyx_v_self->create_future; __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->cancel_waiter);
+  __Pyx_DECREF(__pyx_v_self->cancel_waiter);
+  __pyx_v_self->cancel_waiter = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":575
+ *     def _request_cancel(self):
+ *         self.cancel_waiter = self.create_future()
+ *         self.cancel_sent_waiter = self.create_future()             # <<<<<<<<<<<<<<
+ * 
+ *         con = self.get_connection()
+ */
+  __Pyx_INCREF(__pyx_v_self->create_future);
+  __pyx_t_2 = __pyx_v_self->create_future; __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 575, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->cancel_sent_waiter);
+  __Pyx_DECREF(__pyx_v_self->cancel_sent_waiter);
+  __pyx_v_self->cancel_sent_waiter = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":577
+ *         self.cancel_sent_waiter = self.create_future()
+ * 
+ *         con = self.get_connection()             # <<<<<<<<<<<<<<
+ *         if con is not None:
+ *             # if 'con' is None it means that the connection object has been
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->get_connection(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_con = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":578
+ * 
+ *         con = self.get_connection()
+ *         if con is not None:             # <<<<<<<<<<<<<<
+ *             # if 'con' is None it means that the connection object has been
+ *             # garbage collected and that the transport will soon be aborted.
+ */
+  __pyx_t_4 = (__pyx_v_con != Py_None);
+  __pyx_t_5 = (__pyx_t_4 != 0);
+  if (__pyx_t_5) {
+
+    /* "asyncpg/protocol/protocol.pyx":581
+ *             # if 'con' is None it means that the connection object has been
+ *             # garbage collected and that the transport will soon be aborted.
+ *             con._cancel_current_command(self.cancel_sent_waiter)             # <<<<<<<<<<<<<<
+ *         else:
+ *             self.loop.call_exception_handler({
+ */
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_con, __pyx_n_s_cancel_current_command); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 581, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->cancel_sent_waiter) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->cancel_sent_waiter);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":578
+ * 
+ *         con = self.get_connection()
+ *         if con is not None:             # <<<<<<<<<<<<<<
+ *             # if 'con' is None it means that the connection object has been
+ *             # garbage collected and that the transport will soon be aborted.
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":583
+ *             con._cancel_current_command(self.cancel_sent_waiter)
+ *         else:
+ *             self.loop.call_exception_handler({             # <<<<<<<<<<<<<<
+ *                 'message': 'asyncpg.Protocol has no reference to its '
+ *                            'Connection object and yet a cancellation '
+ */
+  /*else*/ {
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->loop, __pyx_n_s_call_exception_handler); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+
+    /* "asyncpg/protocol/protocol.pyx":584
+ *         else:
+ *             self.loop.call_exception_handler({
+ *                 'message': 'asyncpg.Protocol has no reference to its '             # <<<<<<<<<<<<<<
+ *                            'Connection object and yet a cancellation '
+ *                            'was requested. Please report this at '
+ */
+    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 584, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    if (PyDict_SetItem(__pyx_t_3, __pyx_n_u_message, __pyx_kp_u_asyncpg_Protocol_has_no_referenc) < 0) __PYX_ERR(0, 584, __pyx_L1_error)
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":589
+ *                            'github.com/magicstack/asyncpg.'
+ *             })
+ *             self.abort()             # <<<<<<<<<<<<<<
+ * 
+ *         self._set_state(PROTOCOL_CANCELLED)
+ */
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_abort); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 589, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_3 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_3)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_3);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 589, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/protocol.pyx":591
+ *             self.abort()
+ * 
+ *         self._set_state(PROTOCOL_CANCELLED)             # <<<<<<<<<<<<<<
+ * 
+ *     def _on_timeout(self, fut):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._set_state(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self), __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CANCELLED); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 591, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":573
+ *         self.transport.abort()
+ * 
+ *     def _request_cancel(self):             # <<<<<<<<<<<<<<
+ *         self.cancel_waiter = self.create_future()
+ *         self.cancel_sent_waiter = self.create_future()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._request_cancel", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_con);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":593
+ *         self._set_state(PROTOCOL_CANCELLED)
+ * 
+ *     def _on_timeout(self, fut):             # <<<<<<<<<<<<<<
+ *         if self.waiter is not fut or fut.done() or \
+ *                 self.cancel_waiter is not None or \
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_49_on_timeout(PyObject *__pyx_v_self, PyObject *__pyx_v_fut); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_49_on_timeout(PyObject *__pyx_v_self, PyObject *__pyx_v_fut) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_on_timeout (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_48_on_timeout(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_fut));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_48_on_timeout(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_fut) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("_on_timeout", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":594
+ * 
+ *     def _on_timeout(self, fut):
+ *         if self.waiter is not fut or fut.done() or \             # <<<<<<<<<<<<<<
+ *                 self.cancel_waiter is not None or \
+ *                 self.timeout_handle is None:
+ */
+  __pyx_t_2 = (__pyx_v_self->waiter != __pyx_v_fut);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (!__pyx_t_3) {
+  } else {
+    __pyx_t_1 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_fut, __pyx_n_s_done); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 594, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 594, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 594, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (!__pyx_t_3) {
+  } else {
+    __pyx_t_1 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":595
+ *     def _on_timeout(self, fut):
+ *         if self.waiter is not fut or fut.done() or \
+ *                 self.cancel_waiter is not None or \             # <<<<<<<<<<<<<<
+ *                 self.timeout_handle is None:
+ *             return
+ */
+  __pyx_t_3 = (__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_3 != 0);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_1 = __pyx_t_2;
+    goto __pyx_L4_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":596
+ *         if self.waiter is not fut or fut.done() or \
+ *                 self.cancel_waiter is not None or \
+ *                 self.timeout_handle is None:             # <<<<<<<<<<<<<<
+ *             return
+ *         self._request_cancel()
+ */
+  __pyx_t_2 = (__pyx_v_self->timeout_handle == Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  __pyx_t_1 = __pyx_t_3;
+  __pyx_L4_bool_binop_done:;
+
+  /* "asyncpg/protocol/protocol.pyx":594
+ * 
+ *     def _on_timeout(self, fut):
+ *         if self.waiter is not fut or fut.done() or \             # <<<<<<<<<<<<<<
+ *                 self.cancel_waiter is not None or \
+ *                 self.timeout_handle is None:
+ */
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":597
+ *                 self.cancel_waiter is not None or \
+ *                 self.timeout_handle is None:
+ *             return             # <<<<<<<<<<<<<<
+ *         self._request_cancel()
+ *         self.waiter.set_exception(asyncio.TimeoutError())
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":594
+ * 
+ *     def _on_timeout(self, fut):
+ *         if self.waiter is not fut or fut.done() or \             # <<<<<<<<<<<<<<
+ *                 self.cancel_waiter is not None or \
+ *                 self.timeout_handle is None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":598
+ *                 self.timeout_handle is None:
+ *             return
+ *         self._request_cancel()             # <<<<<<<<<<<<<<
+ *         self.waiter.set_exception(asyncio.TimeoutError())
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_request_cancel); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":599
+ *             return
+ *         self._request_cancel()
+ *         self.waiter.set_exception(asyncio.TimeoutError())             # <<<<<<<<<<<<<<
+ * 
+ *     def _on_waiter_completed(self, fut):
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 599, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 599, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_TimeoutError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 599, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __pyx_t_7 = NULL;
+  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_8, function);
+    }
+  }
+  __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 599, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __pyx_t_8 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_8)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_8);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 599, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":593
+ *         self._set_state(PROTOCOL_CANCELLED)
+ * 
+ *     def _on_timeout(self, fut):             # <<<<<<<<<<<<<<
+ *         if self.waiter is not fut or fut.done() or \
+ *                 self.cancel_waiter is not None or \
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_timeout", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":601
+ *         self.waiter.set_exception(asyncio.TimeoutError())
+ * 
+ *     def _on_waiter_completed(self, fut):             # <<<<<<<<<<<<<<
+ *         if fut is not self.waiter or self.cancel_waiter is not None:
+ *             return
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_51_on_waiter_completed(PyObject *__pyx_v_self, PyObject *__pyx_v_fut); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_51_on_waiter_completed(PyObject *__pyx_v_self, PyObject *__pyx_v_fut) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_on_waiter_completed (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_50_on_waiter_completed(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_fut));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_50_on_waiter_completed(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_fut) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("_on_waiter_completed", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":602
+ * 
+ *     def _on_waiter_completed(self, fut):
+ *         if fut is not self.waiter or self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             return
+ *         if fut.cancelled():
+ */
+  __pyx_t_2 = (__pyx_v_fut != __pyx_v_self->waiter);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (!__pyx_t_3) {
+  } else {
+    __pyx_t_1 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_3 = (__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_3 != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":603
+ *     def _on_waiter_completed(self, fut):
+ *         if fut is not self.waiter or self.cancel_waiter is not None:
+ *             return             # <<<<<<<<<<<<<<
+ *         if fut.cancelled():
+ *             if self.timeout_handle:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":602
+ * 
+ *     def _on_waiter_completed(self, fut):
+ *         if fut is not self.waiter or self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             return
+ *         if fut.cancelled():
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":604
+ *         if fut is not self.waiter or self.cancel_waiter is not None:
+ *             return
+ *         if fut.cancelled():             # <<<<<<<<<<<<<<
+ *             if self.timeout_handle:
+ *                 self.timeout_handle.cancel()
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_fut, __pyx_n_s_cancelled); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 604, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":605
+ *             return
+ *         if fut.cancelled():
+ *             if self.timeout_handle:             # <<<<<<<<<<<<<<
+ *                 self.timeout_handle.cancel()
+ *                 self.timeout_handle = None
+ */
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->timeout_handle); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 605, __pyx_L1_error)
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/protocol.pyx":606
+ *         if fut.cancelled():
+ *             if self.timeout_handle:
+ *                 self.timeout_handle.cancel()             # <<<<<<<<<<<<<<
+ *                 self.timeout_handle = None
+ *             self._request_cancel()
+ */
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->timeout_handle, __pyx_n_s_cancel); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 606, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 606, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":607
+ *             if self.timeout_handle:
+ *                 self.timeout_handle.cancel()
+ *                 self.timeout_handle = None             # <<<<<<<<<<<<<<
+ *             self._request_cancel()
+ * 
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_GIVEREF(Py_None);
+      __Pyx_GOTREF(__pyx_v_self->timeout_handle);
+      __Pyx_DECREF(__pyx_v_self->timeout_handle);
+      __pyx_v_self->timeout_handle = Py_None;
+
+      /* "asyncpg/protocol/protocol.pyx":605
+ *             return
+ *         if fut.cancelled():
+ *             if self.timeout_handle:             # <<<<<<<<<<<<<<
+ *                 self.timeout_handle.cancel()
+ *                 self.timeout_handle = None
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":608
+ *                 self.timeout_handle.cancel()
+ *                 self.timeout_handle = None
+ *             self._request_cancel()             # <<<<<<<<<<<<<<
+ * 
+ *     def _create_future_fallback(self):
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_request_cancel); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 608, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 608, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":604
+ *         if fut is not self.waiter or self.cancel_waiter is not None:
+ *             return
+ *         if fut.cancelled():             # <<<<<<<<<<<<<<
+ *             if self.timeout_handle:
+ *                 self.timeout_handle.cancel()
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":601
+ *         self.waiter.set_exception(asyncio.TimeoutError())
+ * 
+ *     def _on_waiter_completed(self, fut):             # <<<<<<<<<<<<<<
+ *         if fut is not self.waiter or self.cancel_waiter is not None:
+ *             return
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_waiter_completed", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":610
+ *             self._request_cancel()
+ * 
+ *     def _create_future_fallback(self):             # <<<<<<<<<<<<<<
+ *         return asyncio.Future(loop=self.loop)
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_53_create_future_fallback(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_53_create_future_fallback(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_create_future_fallback (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_52_create_future_fallback(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_52_create_future_fallback(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_create_future_fallback", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":611
+ * 
+ *     def _create_future_fallback(self):
+ *         return asyncio.Future(loop=self.loop)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _handle_waiter_on_connection_lost(self, cause):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 611, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Future); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 611, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 611, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_loop, __pyx_v_self->loop) < 0) __PYX_ERR(0, 611, __pyx_L1_error)
+  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 611, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":610
+ *             self._request_cancel()
+ * 
+ *     def _create_future_fallback(self):             # <<<<<<<<<<<<<<
+ *         return asyncio.Future(loop=self.loop)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._create_future_fallback", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":613
+ *         return asyncio.Future(loop=self.loop)
+ * 
+ *     cdef _handle_waiter_on_connection_lost(self, cause):             # <<<<<<<<<<<<<<
+ *         if self.waiter is not None and not self.waiter.done():
+ *             exc = apg_exc.ConnectionDoesNotExistError(
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__handle_waiter_on_connection_lost(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_cause) {
+  PyObject *__pyx_v_exc = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("_handle_waiter_on_connection_lost", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":614
+ * 
+ *     cdef _handle_waiter_on_connection_lost(self, cause):
+ *         if self.waiter is not None and not self.waiter.done():             # <<<<<<<<<<<<<<
+ *             exc = apg_exc.ConnectionDoesNotExistError(
+ *                 'connection was closed in the middle of '
+ */
+  __pyx_t_2 = (__pyx_v_self->waiter != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+  } else {
+    __pyx_t_1 = __pyx_t_3;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_done); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 614, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_6)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_6);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 614, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 614, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_2 = ((!__pyx_t_3) != 0);
+  __pyx_t_1 = __pyx_t_2;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":615
+ *     cdef _handle_waiter_on_connection_lost(self, cause):
+ *         if self.waiter is not None and not self.waiter.done():
+ *             exc = apg_exc.ConnectionDoesNotExistError(             # <<<<<<<<<<<<<<
+ *                 'connection was closed in the middle of '
+ *                 'operation')
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 615, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ConnectionDoesNotExistError); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 615, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_kp_u_connection_was_closed_in_the_mid) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_kp_u_connection_was_closed_in_the_mid);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 615, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_v_exc = __pyx_t_4;
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":618
+ *                 'connection was closed in the middle of '
+ *                 'operation')
+ *             if cause is not None:             # <<<<<<<<<<<<<<
+ *                 exc.__cause__ = cause
+ *             self.waiter.set_exception(exc)
+ */
+    __pyx_t_1 = (__pyx_v_cause != Py_None);
+    __pyx_t_2 = (__pyx_t_1 != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/protocol.pyx":619
+ *                 'operation')
+ *             if cause is not None:
+ *                 exc.__cause__ = cause             # <<<<<<<<<<<<<<
+ *             self.waiter.set_exception(exc)
+ *         self.waiter = None
+ */
+      if (__Pyx_PyObject_SetAttrStr(__pyx_v_exc, __pyx_n_s_cause, __pyx_v_cause) < 0) __PYX_ERR(0, 619, __pyx_L1_error)
+
+      /* "asyncpg/protocol/protocol.pyx":618
+ *                 'connection was closed in the middle of '
+ *                 'operation')
+ *             if cause is not None:             # <<<<<<<<<<<<<<
+ *                 exc.__cause__ = cause
+ *             self.waiter.set_exception(exc)
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":620
+ *             if cause is not None:
+ *                 exc.__cause__ = cause
+ *             self.waiter.set_exception(exc)             # <<<<<<<<<<<<<<
+ *         self.waiter = None
+ * 
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 620, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_exc) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_exc);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 620, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":614
+ * 
+ *     cdef _handle_waiter_on_connection_lost(self, cause):
+ *         if self.waiter is not None and not self.waiter.done():             # <<<<<<<<<<<<<<
+ *             exc = apg_exc.ConnectionDoesNotExistError(
+ *                 'connection was closed in the middle of '
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":621
+ *                 exc.__cause__ = cause
+ *             self.waiter.set_exception(exc)
+ *         self.waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _set_server_parameter(self, name, val):
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->waiter);
+  __Pyx_DECREF(__pyx_v_self->waiter);
+  __pyx_v_self->waiter = Py_None;
+
+  /* "asyncpg/protocol/protocol.pyx":613
+ *         return asyncio.Future(loop=self.loop)
+ * 
+ *     cdef _handle_waiter_on_connection_lost(self, cause):             # <<<<<<<<<<<<<<
+ *         if self.waiter is not None and not self.waiter.done():
+ *             exc = apg_exc.ConnectionDoesNotExistError(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._handle_waiter_on_connection_lost", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_exc);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":623
+ *         self.waiter = None
+ * 
+ *     cdef _set_server_parameter(self, name, val):             # <<<<<<<<<<<<<<
+ *         self.settings.add_setting(name, val)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__set_server_parameter(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_val) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("_set_server_parameter", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":624
+ * 
+ *     cdef _set_server_parameter(self, name, val):
+ *         self.settings.add_setting(name, val)             # <<<<<<<<<<<<<<
+ * 
+ *     def _get_timeout(self, timeout):
+ */
+  if (!(likely(PyUnicode_CheckExact(__pyx_v_name))||((__pyx_v_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_name)->tp_name), 0))) __PYX_ERR(0, 624, __pyx_L1_error)
+  if (!(likely(PyUnicode_CheckExact(__pyx_v_val))||((__pyx_v_val) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_val)->tp_name), 0))) __PYX_ERR(0, 624, __pyx_L1_error)
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_setting(__pyx_v_self->settings, ((PyObject*)__pyx_v_name), ((PyObject*)__pyx_v_val)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 624, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":623
+ *         self.waiter = None
+ * 
+ *     cdef _set_server_parameter(self, name, val):             # <<<<<<<<<<<<<<
+ *         self.settings.add_setting(name, val)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._set_server_parameter", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":626
+ *         self.settings.add_setting(name, val)
+ * 
+ *     def _get_timeout(self, timeout):             # <<<<<<<<<<<<<<
+ *         if timeout is not None:
+ *             try:
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_55_get_timeout(PyObject *__pyx_v_self, PyObject *__pyx_v_timeout); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_55_get_timeout(PyObject *__pyx_v_self, PyObject *__pyx_v_timeout) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_get_timeout (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_54_get_timeout(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_timeout));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_54_get_timeout(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  __Pyx_RefNannySetupContext("_get_timeout", 0);
+  __Pyx_INCREF(__pyx_v_timeout);
+
+  /* "asyncpg/protocol/protocol.pyx":627
+ * 
+ *     def _get_timeout(self, timeout):
+ *         if timeout is not None:             # <<<<<<<<<<<<<<
+ *             try:
+ *                 if type(timeout) is bool:
+ */
+  __pyx_t_1 = (__pyx_v_timeout != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":628
+ *     def _get_timeout(self, timeout):
+ *         if timeout is not None:
+ *             try:             # <<<<<<<<<<<<<<
+ *                 if type(timeout) is bool:
+ *                     raise ValueError
+ */
+    {
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
+      __Pyx_XGOTREF(__pyx_t_3);
+      __Pyx_XGOTREF(__pyx_t_4);
+      __Pyx_XGOTREF(__pyx_t_5);
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":629
+ *         if timeout is not None:
+ *             try:
+ *                 if type(timeout) is bool:             # <<<<<<<<<<<<<<
+ *                     raise ValueError
+ *                 timeout = float(timeout)
+ */
+        __pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_timeout)) == ((PyObject*)&PyBool_Type));
+        __pyx_t_1 = (__pyx_t_2 != 0);
+        if (unlikely(__pyx_t_1)) {
+
+          /* "asyncpg/protocol/protocol.pyx":630
+ *             try:
+ *                 if type(timeout) is bool:
+ *                     raise ValueError             # <<<<<<<<<<<<<<
+ *                 timeout = float(timeout)
+ *             except ValueError:
+ */
+          __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0);
+          __PYX_ERR(0, 630, __pyx_L4_error)
+
+          /* "asyncpg/protocol/protocol.pyx":629
+ *         if timeout is not None:
+ *             try:
+ *                 if type(timeout) is bool:             # <<<<<<<<<<<<<<
+ *                     raise ValueError
+ *                 timeout = float(timeout)
+ */
+        }
+
+        /* "asyncpg/protocol/protocol.pyx":631
+ *                 if type(timeout) is bool:
+ *                     raise ValueError
+ *                 timeout = float(timeout)             # <<<<<<<<<<<<<<
+ *             except ValueError:
+ *                 raise ValueError(
+ */
+        __pyx_t_6 = __Pyx_PyNumber_Float(__pyx_v_timeout); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 631, __pyx_L4_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF_SET(__pyx_v_timeout, __pyx_t_6);
+        __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":628
+ *     def _get_timeout(self, timeout):
+ *         if timeout is not None:
+ *             try:             # <<<<<<<<<<<<<<
+ *                 if type(timeout) is bool:
+ *                     raise ValueError
+ */
+      }
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      goto __pyx_L9_try_end;
+      __pyx_L4_error:;
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":632
+ *                     raise ValueError
+ *                 timeout = float(timeout)
+ *             except ValueError:             # <<<<<<<<<<<<<<
+ *                 raise ValueError(
+ *                     'invalid timeout value: expected non-negative float '
+ */
+      __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
+      if (__pyx_t_7) {
+        __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._get_timeout", __pyx_clineno, __pyx_lineno, __pyx_filename);
+        if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 632, __pyx_L6_except_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_GOTREF(__pyx_t_9);
+
+        /* "asyncpg/protocol/protocol.pyx":635
+ *                 raise ValueError(
+ *                     'invalid timeout value: expected non-negative float '
+ *                     '(got {!r})'.format(timeout)) from None             # <<<<<<<<<<<<<<
+ * 
+ *         return self._get_timeout_impl(timeout)
+ */
+        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_timeout_value_expected_n, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 635, __pyx_L6_except_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __pyx_t_12 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
+          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
+          if (likely(__pyx_t_12)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+            __Pyx_INCREF(__pyx_t_12);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_11, function);
+          }
+        }
+        __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_v_timeout) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_timeout);
+        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+        if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 635, __pyx_L6_except_error)
+        __Pyx_GOTREF(__pyx_t_10);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":633
+ *                 timeout = float(timeout)
+ *             except ValueError:
+ *                 raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'invalid timeout value: expected non-negative float '
+ *                     '(got {!r})'.format(timeout)) from None
+ */
+        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 633, __pyx_L6_except_error)
+        __Pyx_GOTREF(__pyx_t_11);
+        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":635
+ *                 raise ValueError(
+ *                     'invalid timeout value: expected non-negative float '
+ *                     '(got {!r})'.format(timeout)) from None             # <<<<<<<<<<<<<<
+ * 
+ *         return self._get_timeout_impl(timeout)
+ */
+        __Pyx_Raise(__pyx_t_11, 0, 0, Py_None);
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __PYX_ERR(0, 633, __pyx_L6_except_error)
+      }
+      goto __pyx_L6_except_error;
+      __pyx_L6_except_error:;
+
+      /* "asyncpg/protocol/protocol.pyx":628
+ *     def _get_timeout(self, timeout):
+ *         if timeout is not None:
+ *             try:             # <<<<<<<<<<<<<<
+ *                 if type(timeout) is bool:
+ *                     raise ValueError
+ */
+      __Pyx_XGIVEREF(__pyx_t_3);
+      __Pyx_XGIVEREF(__pyx_t_4);
+      __Pyx_XGIVEREF(__pyx_t_5);
+      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+      goto __pyx_L1_error;
+      __pyx_L9_try_end:;
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":627
+ * 
+ *     def _get_timeout(self, timeout):
+ *         if timeout is not None:             # <<<<<<<<<<<<<<
+ *             try:
+ *                 if type(timeout) is bool:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":637
+ *                     '(got {!r})'.format(timeout)) from None
+ * 
+ *         return self._get_timeout_impl(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _get_timeout_impl(self, timeout):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_9 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(__pyx_v_self, __pyx_v_timeout); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 637, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+  __pyx_r = __pyx_t_9;
+  __pyx_t_9 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":626
+ *         self.settings.add_setting(name, val)
+ * 
+ *     def _get_timeout(self, timeout):             # <<<<<<<<<<<<<<
+ *         if timeout is not None:
+ *             try:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._get_timeout", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_timeout);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":639
+ *         return self._get_timeout_impl(timeout)
+ * 
+ *     cdef inline _get_timeout_impl(self, timeout):             # <<<<<<<<<<<<<<
+ *         if timeout is None:
+ *             timeout = self.get_connection()._config.command_timeout
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("_get_timeout_impl", 0);
+  __Pyx_INCREF(__pyx_v_timeout);
+
+  /* "asyncpg/protocol/protocol.pyx":640
+ * 
+ *     cdef inline _get_timeout_impl(self, timeout):
+ *         if timeout is None:             # <<<<<<<<<<<<<<
+ *             timeout = self.get_connection()._config.command_timeout
+ *         elif timeout is NO_TIMEOUT:
+ */
+  __pyx_t_1 = (__pyx_v_timeout == Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":641
+ *     cdef inline _get_timeout_impl(self, timeout):
+ *         if timeout is None:
+ *             timeout = self.get_connection()._config.command_timeout             # <<<<<<<<<<<<<<
+ *         elif timeout is NO_TIMEOUT:
+ *             timeout = None
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->get_connection(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 641, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_config); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 641, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_command_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 641, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF_SET(__pyx_v_timeout, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":640
+ * 
+ *     cdef inline _get_timeout_impl(self, timeout):
+ *         if timeout is None:             # <<<<<<<<<<<<<<
+ *             timeout = self.get_connection()._config.command_timeout
+ *         elif timeout is NO_TIMEOUT:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":642
+ *         if timeout is None:
+ *             timeout = self.get_connection()._config.command_timeout
+ *         elif timeout is NO_TIMEOUT:             # <<<<<<<<<<<<<<
+ *             timeout = None
+ *         else:
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_NO_TIMEOUT); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 642, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_2 = (__pyx_v_timeout == __pyx_t_3);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":643
+ *             timeout = self.get_connection()._config.command_timeout
+ *         elif timeout is NO_TIMEOUT:
+ *             timeout = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             timeout = float(timeout)
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_DECREF_SET(__pyx_v_timeout, Py_None);
+
+    /* "asyncpg/protocol/protocol.pyx":642
+ *         if timeout is None:
+ *             timeout = self.get_connection()._config.command_timeout
+ *         elif timeout is NO_TIMEOUT:             # <<<<<<<<<<<<<<
+ *             timeout = None
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":645
+ *             timeout = None
+ *         else:
+ *             timeout = float(timeout)             # <<<<<<<<<<<<<<
+ * 
+ *         if timeout is not None and timeout <= 0:
+ */
+  /*else*/ {
+    __pyx_t_3 = __Pyx_PyNumber_Float(__pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 645, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF_SET(__pyx_v_timeout, __pyx_t_3);
+    __pyx_t_3 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/protocol.pyx":647
+ *             timeout = float(timeout)
+ * 
+ *         if timeout is not None and timeout <= 0:             # <<<<<<<<<<<<<<
+ *             raise asyncio.TimeoutError()
+ *         return timeout
+ */
+  __pyx_t_2 = (__pyx_v_timeout != Py_None);
+  __pyx_t_5 = (__pyx_t_2 != 0);
+  if (__pyx_t_5) {
+  } else {
+    __pyx_t_1 = __pyx_t_5;
+    goto __pyx_L5_bool_binop_done;
+  }
+  __pyx_t_3 = PyObject_RichCompare(__pyx_v_timeout, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 647, __pyx_L1_error)
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 647, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_1 = __pyx_t_5;
+  __pyx_L5_bool_binop_done:;
+  if (unlikely(__pyx_t_1)) {
+
+    /* "asyncpg/protocol/protocol.pyx":648
+ * 
+ *         if timeout is not None and timeout <= 0:
+ *             raise asyncio.TimeoutError()             # <<<<<<<<<<<<<<
+ *         return timeout
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 648, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_TimeoutError); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 648, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 648, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(0, 648, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":647
+ *             timeout = float(timeout)
+ * 
+ *         if timeout is not None and timeout <= 0:             # <<<<<<<<<<<<<<
+ *             raise asyncio.TimeoutError()
+ *         return timeout
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":649
+ *         if timeout is not None and timeout <= 0:
+ *             raise asyncio.TimeoutError()
+ *         return timeout             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _check_state(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_timeout);
+  __pyx_r = __pyx_v_timeout;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":639
+ *         return self._get_timeout_impl(timeout)
+ * 
+ *     cdef inline _get_timeout_impl(self, timeout):             # <<<<<<<<<<<<<<
+ *         if timeout is None:
+ *             timeout = self.get_connection()._config.command_timeout
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._get_timeout_impl", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_timeout);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":651
+ *         return timeout
+ * 
+ *     cdef _check_state(self):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             raise apg_exc.InterfaceError(
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__check_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  __Pyx_RefNannySetupContext("_check_state", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":652
+ * 
+ *     cdef _check_state(self):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is cancelling')
+ */
+  __pyx_t_1 = (__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/protocol.pyx":653
+ *     cdef _check_state(self):
+ *         if self.cancel_waiter is not None:
+ *             raise apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'cannot perform operation: another operation is cancelling')
+ *         if self.closing:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 653, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_cannot_perform_operation_another) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_cannot_perform_operation_another);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 653, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(0, 653, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":652
+ * 
+ *     cdef _check_state(self):
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is cancelling')
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":655
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is cancelling')
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: connection is closed')
+ */
+  __pyx_t_2 = (__pyx_v_self->closing != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/protocol.pyx":656
+ *                 'cannot perform operation: another operation is cancelling')
+ *         if self.closing:
+ *             raise apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'cannot perform operation: connection is closed')
+ *         if self.waiter is not None or self.timeout_handle is not None:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 656, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 656, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_kp_u_cannot_perform_operation_connect) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_cannot_perform_operation_connect);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 656, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(0, 656, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":655
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is cancelling')
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: connection is closed')
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":658
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: connection is closed')
+ *         if self.waiter is not None or self.timeout_handle is not None:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is in progress')
+ */
+  __pyx_t_1 = (__pyx_v_self->waiter != Py_None);
+  __pyx_t_6 = (__pyx_t_1 != 0);
+  if (!__pyx_t_6) {
+  } else {
+    __pyx_t_2 = __pyx_t_6;
+    goto __pyx_L6_bool_binop_done;
+  }
+  __pyx_t_6 = (__pyx_v_self->timeout_handle != Py_None);
+  __pyx_t_1 = (__pyx_t_6 != 0);
+  __pyx_t_2 = __pyx_t_1;
+  __pyx_L6_bool_binop_done:;
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/protocol.pyx":659
+ *                 'cannot perform operation: connection is closed')
+ *         if self.waiter is not None or self.timeout_handle is not None:
+ *             raise apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'cannot perform operation: another operation is in progress')
+ * 
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 659, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 659, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_cannot_perform_operation_another_2) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_cannot_perform_operation_another_2);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 659, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(0, 659, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":658
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: connection is closed')
+ *         if self.waiter is not None or self.timeout_handle is not None:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is in progress')
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":651
+ *         return timeout
+ * 
+ *     cdef _check_state(self):             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             raise apg_exc.InterfaceError(
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._check_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":662
+ *                 'cannot perform operation: another operation is in progress')
+ * 
+ *     def _is_cancelling(self):             # <<<<<<<<<<<<<<
+ *         return (
+ *             self.cancel_waiter is not None or
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_57_is_cancelling(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_57_is_cancelling(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_is_cancelling (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_56_is_cancelling(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_56_is_cancelling(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_is_cancelling", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":663
+ * 
+ *     def _is_cancelling(self):
+ *         return (             # <<<<<<<<<<<<<<
+ *             self.cancel_waiter is not None or
+ *             self.cancel_sent_waiter is not None
+ */
+  __Pyx_XDECREF(__pyx_r);
+
+  /* "asyncpg/protocol/protocol.pyx":664
+ *     def _is_cancelling(self):
+ *         return (
+ *             self.cancel_waiter is not None or             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter is not None
+ *         )
+ */
+  __pyx_t_2 = (__pyx_v_self->cancel_waiter != Py_None);
+  if (!__pyx_t_2) {
+  } else {
+    __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_1 = __pyx_t_3;
+    __pyx_t_3 = 0;
+    goto __pyx_L3_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":665
+ *         return (
+ *             self.cancel_waiter is not None or
+ *             self.cancel_sent_waiter is not None             # <<<<<<<<<<<<<<
+ *         )
+ * 
+ */
+  __pyx_t_2 = (__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 665, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_1 = __pyx_t_3;
+  __pyx_t_3 = 0;
+  __pyx_L3_bool_binop_done:;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":662
+ *                 'cannot perform operation: another operation is in progress')
+ * 
+ *     def _is_cancelling(self):             # <<<<<<<<<<<<<<
+ *         return (
+ *             self.cancel_waiter is not None or
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._is_cancelling", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_60generator10(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */
+
+/* "asyncpg/protocol/protocol.pyx":669
+ * 
+ *     @cython.iterable_coroutine
+ *     async def _wait_for_cancellation(self):             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_59_wait_for_cancellation(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_59_wait_for_cancellation(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_wait_for_cancellation (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_58_wait_for_cancellation(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_58_wait_for_cancellation(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_wait_for_cancellation", 0);
+  __pyx_cur_scope = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *)__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation(__pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *)Py_None);
+    __Pyx_INCREF(Py_None);
+    __PYX_ERR(0, 669, __pyx_L1_error)
+  } else {
+    __Pyx_GOTREF(__pyx_cur_scope);
+  }
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_IterableCoroutine_New((__pyx_coroutine_body_t) __pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_60generator10, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_wait_for_cancellation, __pyx_n_s_BaseProtocol__wait_for_cancellat, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!gen)) __PYX_ERR(0, 669, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._wait_for_cancellation", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_7asyncpg_8protocol_8protocol_12BaseProtocol_60generator10(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *__pyx_cur_scope = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  int __pyx_t_1;
+  int __pyx_t_2;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_wait_for_cancellation", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L5_resume_from_await;
+    case 2: goto __pyx_L7_resume_from_await;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 669, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":670
+ *     @cython.iterable_coroutine
+ *     async def _wait_for_cancellation(self):
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":671
+ *     async def _wait_for_cancellation(self):
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter             # <<<<<<<<<<<<<<
+ *             self.cancel_sent_waiter = None
+ *         if self.cancel_waiter is not None:
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 1;
+      return __pyx_r;
+      __pyx_L5_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 671, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 671, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":672
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None             # <<<<<<<<<<<<<<
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->cancel_sent_waiter);
+    __pyx_cur_scope->__pyx_v_self->cancel_sent_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":670
+ *     @cython.iterable_coroutine
+ *     async def _wait_for_cancellation(self):
+ *         if self.cancel_sent_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":673
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ * 
+ */
+  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":674
+ *             self.cancel_sent_waiter = None
+ *         if self.cancel_waiter is not None:
+ *             await self.cancel_waiter             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _coreproto_error(self):
+ */
+    __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_cur_scope->__pyx_v_self->cancel_waiter);
+    __Pyx_XGOTREF(__pyx_r);
+    if (likely(__pyx_r)) {
+      __Pyx_XGIVEREF(__pyx_r);
+      __Pyx_RefNannyFinishContext();
+      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+      /* return from generator, awaiting value */
+      __pyx_generator->resume_label = 2;
+      return __pyx_r;
+      __pyx_L7_resume_from_await:;
+      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 674, __pyx_L1_error)
+    } else {
+      PyObject* exc_type = __Pyx_PyErr_Occurred();
+      if (exc_type) {
+        if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();
+        else __PYX_ERR(0, 674, __pyx_L1_error)
+      }
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":673
+ *             await self.cancel_sent_waiter
+ *             self.cancel_sent_waiter = None
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             await self.cancel_waiter
+ * 
+ */
+  }
+  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+
+  /* "asyncpg/protocol/protocol.pyx":669
+ * 
+ *     @cython.iterable_coroutine
+ *     async def _wait_for_cancellation(self):             # <<<<<<<<<<<<<<
+ *         if self.cancel_sent_waiter is not None:
+ *             await self.cancel_sent_waiter
+ */
+
+  /* function exit code */
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("_wait_for_cancellation", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  #if !CYTHON_USE_EXC_INFO_STACK
+  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
+  #endif
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":676
+ *             await self.cancel_waiter
+ * 
+ *     cdef _coreproto_error(self):             # <<<<<<<<<<<<<<
+ *         try:
+ *             if self.waiter is not None:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__coreproto_error(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  int __pyx_t_7;
+  char const *__pyx_t_8;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  __Pyx_RefNannySetupContext("_coreproto_error", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":677
+ * 
+ *     cdef _coreproto_error(self):
+ *         try:             # <<<<<<<<<<<<<<
+ *             if self.waiter is not None:
+ *                 if not self.waiter.done():
+ */
+  /*try:*/ {
+
+    /* "asyncpg/protocol/protocol.pyx":678
+ *     cdef _coreproto_error(self):
+ *         try:
+ *             if self.waiter is not None:             # <<<<<<<<<<<<<<
+ *                 if not self.waiter.done():
+ *                     raise apg_exc.InternalClientError(
+ */
+    __pyx_t_1 = (__pyx_v_self->waiter != Py_None);
+    __pyx_t_2 = (__pyx_t_1 != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/protocol.pyx":679
+ *         try:
+ *             if self.waiter is not None:
+ *                 if not self.waiter.done():             # <<<<<<<<<<<<<<
+ *                     raise apg_exc.InternalClientError(
+ *                         'waiter is not done while handling critical '
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_done); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 679, __pyx_L4_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_5)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_5);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 679, __pyx_L4_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 679, __pyx_L4_error)
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __pyx_t_1 = ((!__pyx_t_2) != 0);
+      if (unlikely(__pyx_t_1)) {
+
+        /* "asyncpg/protocol/protocol.pyx":680
+ *             if self.waiter is not None:
+ *                 if not self.waiter.done():
+ *                     raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                         'waiter is not done while handling critical '
+ *                         'protocol error')
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 680, __pyx_L4_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 680, __pyx_L4_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __pyx_t_4 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+          if (likely(__pyx_t_4)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+            __Pyx_INCREF(__pyx_t_4);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_5, function);
+          }
+        }
+        __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_waiter_is_not_done_while_handlin) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_waiter_is_not_done_while_handlin);
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 680, __pyx_L4_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+        __PYX_ERR(0, 680, __pyx_L4_error)
+
+        /* "asyncpg/protocol/protocol.pyx":679
+ *         try:
+ *             if self.waiter is not None:
+ *                 if not self.waiter.done():             # <<<<<<<<<<<<<<
+ *                     raise apg_exc.InternalClientError(
+ *                         'waiter is not done while handling critical '
+ */
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":683
+ *                         'waiter is not done while handling critical '
+ *                         'protocol error')
+ *                 self.waiter = None             # <<<<<<<<<<<<<<
+ *         finally:
+ *             self.abort()
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_GIVEREF(Py_None);
+      __Pyx_GOTREF(__pyx_v_self->waiter);
+      __Pyx_DECREF(__pyx_v_self->waiter);
+      __pyx_v_self->waiter = Py_None;
+
+      /* "asyncpg/protocol/protocol.pyx":678
+ *     cdef _coreproto_error(self):
+ *         try:
+ *             if self.waiter is not None:             # <<<<<<<<<<<<<<
+ *                 if not self.waiter.done():
+ *                     raise apg_exc.InternalClientError(
+ */
+    }
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":685
+ *                 self.waiter = None
+ *         finally:
+ *             self.abort()             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _new_waiter(self, timeout):
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_abort); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 685, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      goto __pyx_L5;
+    }
+    __pyx_L4_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_9);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __Pyx_XGOTREF(__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_12);
+      __Pyx_XGOTREF(__pyx_t_13);
+      __Pyx_XGOTREF(__pyx_t_14);
+      __pyx_t_6 = __pyx_lineno; __pyx_t_7 = __pyx_clineno; __pyx_t_8 = __pyx_filename;
+      {
+        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_abort); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 685, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __pyx_t_4 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+          if (likely(__pyx_t_4)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+            __Pyx_INCREF(__pyx_t_4);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_5, function);
+          }
+        }
+        __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 685, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_3);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_XGIVEREF(__pyx_t_14);
+        __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
+      }
+      __Pyx_XGIVEREF(__pyx_t_9);
+      __Pyx_XGIVEREF(__pyx_t_10);
+      __Pyx_XGIVEREF(__pyx_t_11);
+      __Pyx_ErrRestore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
+      __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
+      __pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_7; __pyx_filename = __pyx_t_8;
+      goto __pyx_L1_error;
+      __pyx_L9_error:;
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_12);
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_XGIVEREF(__pyx_t_14);
+        __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
+      }
+      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+      __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
+      goto __pyx_L1_error;
+    }
+    __pyx_L5:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":676
+ *             await self.cancel_waiter
+ * 
+ *     cdef _coreproto_error(self):             # <<<<<<<<<<<<<<
+ *         try:
+ *             if self.waiter is not None:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._coreproto_error", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":687
+ *             self.abort()
+ * 
+ *     cdef _new_waiter(self, timeout):             # <<<<<<<<<<<<<<
+ *         if self.waiter is not None:
+ *             raise apg_exc.InterfaceError(
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__new_waiter(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_timeout) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("_new_waiter", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":688
+ * 
+ *     cdef _new_waiter(self, timeout):
+ *         if self.waiter is not None:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is in progress')
+ */
+  __pyx_t_1 = (__pyx_v_self->waiter != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (unlikely(__pyx_t_2)) {
+
+    /* "asyncpg/protocol/protocol.pyx":689
+ *     cdef _new_waiter(self, timeout):
+ *         if self.waiter is not None:
+ *             raise apg_exc.InterfaceError(             # <<<<<<<<<<<<<<
+ *                 'cannot perform operation: another operation is in progress')
+ *         self.waiter = self.create_future()
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 689, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InterfaceError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 689, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_cannot_perform_operation_another_2) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_cannot_perform_operation_another_2);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 689, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(0, 689, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":688
+ * 
+ *     cdef _new_waiter(self, timeout):
+ *         if self.waiter is not None:             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is in progress')
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":691
+ *             raise apg_exc.InterfaceError(
+ *                 'cannot perform operation: another operation is in progress')
+ *         self.waiter = self.create_future()             # <<<<<<<<<<<<<<
+ *         if timeout is not None:
+ *             self.timeout_handle = self.loop.call_later(
+ */
+  __Pyx_INCREF(__pyx_v_self->create_future);
+  __pyx_t_5 = __pyx_v_self->create_future; __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 691, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_GIVEREF(__pyx_t_3);
+  __Pyx_GOTREF(__pyx_v_self->waiter);
+  __Pyx_DECREF(__pyx_v_self->waiter);
+  __pyx_v_self->waiter = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":692
+ *                 'cannot perform operation: another operation is in progress')
+ *         self.waiter = self.create_future()
+ *         if timeout is not None:             # <<<<<<<<<<<<<<
+ *             self.timeout_handle = self.loop.call_later(
+ *                 timeout, self.timeout_callback, self.waiter)
+ */
+  __pyx_t_2 = (__pyx_v_timeout != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":693
+ *         self.waiter = self.create_future()
+ *         if timeout is not None:
+ *             self.timeout_handle = self.loop.call_later(             # <<<<<<<<<<<<<<
+ *                 timeout, self.timeout_callback, self.waiter)
+ *         self.waiter.add_done_callback(self.completed_callback)
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->loop, __pyx_n_s_call_later); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 693, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+
+    /* "asyncpg/protocol/protocol.pyx":694
+ *         if timeout is not None:
+ *             self.timeout_handle = self.loop.call_later(
+ *                 timeout, self.timeout_callback, self.waiter)             # <<<<<<<<<<<<<<
+ *         self.waiter.add_done_callback(self.completed_callback)
+ *         return self.waiter
+ */
+    __pyx_t_4 = NULL;
+    __pyx_t_6 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+        __pyx_t_6 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_timeout, __pyx_v_self->timeout_callback, __pyx_v_self->waiter};
+      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 693, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_timeout, __pyx_v_self->timeout_callback, __pyx_v_self->waiter};
+      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 693, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_GOTREF(__pyx_t_3);
+    } else
+    #endif
+    {
+      __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 693, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      if (__pyx_t_4) {
+        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_timeout);
+      __Pyx_GIVEREF(__pyx_v_timeout);
+      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_timeout);
+      __Pyx_INCREF(__pyx_v_self->timeout_callback);
+      __Pyx_GIVEREF(__pyx_v_self->timeout_callback);
+      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_self->timeout_callback);
+      __Pyx_INCREF(__pyx_v_self->waiter);
+      __Pyx_GIVEREF(__pyx_v_self->waiter);
+      PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_self->waiter);
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 693, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":693
+ *         self.waiter = self.create_future()
+ *         if timeout is not None:
+ *             self.timeout_handle = self.loop.call_later(             # <<<<<<<<<<<<<<
+ *                 timeout, self.timeout_callback, self.waiter)
+ *         self.waiter.add_done_callback(self.completed_callback)
+ */
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_self->timeout_handle);
+    __Pyx_DECREF(__pyx_v_self->timeout_handle);
+    __pyx_v_self->timeout_handle = __pyx_t_3;
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":692
+ *                 'cannot perform operation: another operation is in progress')
+ *         self.waiter = self.create_future()
+ *         if timeout is not None:             # <<<<<<<<<<<<<<
+ *             self.timeout_handle = self.loop.call_later(
+ *                 timeout, self.timeout_callback, self.waiter)
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":695
+ *             self.timeout_handle = self.loop.call_later(
+ *                 timeout, self.timeout_callback, self.waiter)
+ *         self.waiter.add_done_callback(self.completed_callback)             # <<<<<<<<<<<<<<
+ *         return self.waiter
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_add_done_callback); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 695, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_7 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_7)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_v_self->completed_callback) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_self->completed_callback);
+  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 695, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":696
+ *                 timeout, self.timeout_callback, self.waiter)
+ *         self.waiter.add_done_callback(self.completed_callback)
+ *         return self.waiter             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__connect(self, object waiter):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->waiter);
+  __pyx_r = __pyx_v_self->waiter;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":687
+ *             self.abort()
+ * 
+ *     cdef _new_waiter(self, timeout):             # <<<<<<<<<<<<<<
+ *         if self.waiter is not None:
+ *             raise apg_exc.InterfaceError(
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._new_waiter", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":698
+ *         return self.waiter
+ * 
+ *     cdef _on_result__connect(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(True)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__connect(CYTHON_UNUSED struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__connect", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":699
+ * 
+ *     cdef _on_result__connect(self, object waiter):
+ *         waiter.set_result(True)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__prepare(self, object waiter):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 699, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, Py_True) : __Pyx_PyObject_CallOneArg(__pyx_t_2, Py_True);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 699, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":698
+ *         return self.waiter
+ * 
+ *     cdef _on_result__connect(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(True)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__connect", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":701
+ *         waiter.set_result(True)
+ * 
+ *     cdef _on_result__prepare(self, object waiter):             # <<<<<<<<<<<<<<
+ *         if PG_DEBUG:
+ *             if self.statement is None:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__prepare(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__prepare", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":702
+ * 
+ *     cdef _on_result__prepare(self, object waiter):
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if self.statement is None:
+ *                 raise apg_exc.InternalClientError(
+ */
+  __pyx_t_1 = (PG_DEBUG != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":703
+ *     cdef _on_result__prepare(self, object waiter):
+ *         if PG_DEBUG:
+ *             if self.statement is None:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_on_result__prepare: statement is None')
+ */
+    __pyx_t_1 = (((PyObject *)__pyx_v_self->statement) == Py_None);
+    __pyx_t_2 = (__pyx_t_1 != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/protocol.pyx":704
+ *         if PG_DEBUG:
+ *             if self.statement is None:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     '_on_result__prepare: statement is None')
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 704, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 704, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_on_result__prepare_statement_is) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_on_result__prepare_statement_is);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 704, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(0, 704, __pyx_L1_error)
+
+      /* "asyncpg/protocol/protocol.pyx":703
+ *     cdef _on_result__prepare(self, object waiter):
+ *         if PG_DEBUG:
+ *             if self.statement is None:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_on_result__prepare: statement is None')
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":702
+ * 
+ *     cdef _on_result__prepare(self, object waiter):
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if self.statement is None:
+ *                 raise apg_exc.InternalClientError(
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":707
+ *                     '_on_result__prepare: statement is None')
+ * 
+ *         if self.result_param_desc is not None:             # <<<<<<<<<<<<<<
+ *             self.statement._set_args_desc(self.result_param_desc)
+ *         if self.result_row_desc is not None:
+ */
+  __pyx_t_2 = (__pyx_v_self->__pyx_base.result_param_desc != ((PyObject*)Py_None));
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":708
+ * 
+ *         if self.result_param_desc is not None:
+ *             self.statement._set_args_desc(self.result_param_desc)             # <<<<<<<<<<<<<<
+ *         if self.result_row_desc is not None:
+ *             self.statement._set_row_desc(self.result_row_desc)
+ */
+    __pyx_t_3 = __pyx_v_self->__pyx_base.result_param_desc;
+    __Pyx_INCREF(__pyx_t_3);
+    __pyx_t_5 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_args_desc(__pyx_v_self->statement, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 708, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":707
+ *                     '_on_result__prepare: statement is None')
+ * 
+ *         if self.result_param_desc is not None:             # <<<<<<<<<<<<<<
+ *             self.statement._set_args_desc(self.result_param_desc)
+ *         if self.result_row_desc is not None:
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":709
+ *         if self.result_param_desc is not None:
+ *             self.statement._set_args_desc(self.result_param_desc)
+ *         if self.result_row_desc is not None:             # <<<<<<<<<<<<<<
+ *             self.statement._set_row_desc(self.result_row_desc)
+ *         waiter.set_result(self.statement)
+ */
+  __pyx_t_1 = (__pyx_v_self->__pyx_base.result_row_desc != ((PyObject*)Py_None));
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":710
+ *             self.statement._set_args_desc(self.result_param_desc)
+ *         if self.result_row_desc is not None:
+ *             self.statement._set_row_desc(self.result_row_desc)             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.statement)
+ * 
+ */
+    __pyx_t_5 = __pyx_v_self->__pyx_base.result_row_desc;
+    __Pyx_INCREF(__pyx_t_5);
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_row_desc(__pyx_v_self->statement, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 710, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":709
+ *         if self.result_param_desc is not None:
+ *             self.statement._set_args_desc(self.result_param_desc)
+ *         if self.result_row_desc is not None:             # <<<<<<<<<<<<<<
+ *             self.statement._set_row_desc(self.result_row_desc)
+ *         waiter.set_result(self.statement)
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":711
+ *         if self.result_row_desc is not None:
+ *             self.statement._set_row_desc(self.result_row_desc)
+ *         waiter.set_result(self.statement)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__bind_and_exec(self, object waiter):
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 711, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, ((PyObject *)__pyx_v_self->statement)) : __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_self->statement));
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 711, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":701
+ *         waiter.set_result(True)
+ * 
+ *     cdef _on_result__prepare(self, object waiter):             # <<<<<<<<<<<<<<
+ *         if PG_DEBUG:
+ *             if self.statement is None:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__prepare", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":713
+ *         waiter.set_result(self.statement)
+ * 
+ *     cdef _on_result__bind_and_exec(self, object waiter):             # <<<<<<<<<<<<<<
+ *         if self.return_extra:
+ *             waiter.set_result((
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__bind_and_exec(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__bind_and_exec", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":714
+ * 
+ *     cdef _on_result__bind_and_exec(self, object waiter):
+ *         if self.return_extra:             # <<<<<<<<<<<<<<
+ *             waiter.set_result((
+ *                 self.result,
+ */
+  __pyx_t_1 = (__pyx_v_self->return_extra != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":715
+ *     cdef _on_result__bind_and_exec(self, object waiter):
+ *         if self.return_extra:
+ *             waiter.set_result((             # <<<<<<<<<<<<<<
+ *                 self.result,
+ *                 self.result_status_msg,
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 715, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+
+    /* "asyncpg/protocol/protocol.pyx":718
+ *                 self.result,
+ *                 self.result_status_msg,
+ *                 self.result_execute_completed))             # <<<<<<<<<<<<<<
+ *         else:
+ *             waiter.set_result(self.result)
+ */
+    __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_self->__pyx_base.result_execute_completed); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 718, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+
+    /* "asyncpg/protocol/protocol.pyx":716
+ *         if self.return_extra:
+ *             waiter.set_result((
+ *                 self.result,             # <<<<<<<<<<<<<<
+ *                 self.result_status_msg,
+ *                 self.result_execute_completed))
+ */
+    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 716, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_INCREF(__pyx_v_self->__pyx_base.result);
+    __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result);
+    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_self->__pyx_base.result);
+    __Pyx_INCREF(__pyx_v_self->__pyx_base.result_status_msg);
+    __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result_status_msg);
+    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_self->__pyx_base.result_status_msg);
+    __Pyx_GIVEREF(__pyx_t_4);
+    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
+    __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":714
+ * 
+ *     cdef _on_result__bind_and_exec(self, object waiter):
+ *         if self.return_extra:             # <<<<<<<<<<<<<<
+ *             waiter.set_result((
+ *                 self.result,
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":720
+ *                 self.result_execute_completed))
+ *         else:
+ *             waiter.set_result(self.result)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__bind(self, object waiter):
+ */
+  /*else*/ {
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 720, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_v_self->__pyx_base.result) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->__pyx_base.result);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 720, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/protocol.pyx":713
+ *         waiter.set_result(self.statement)
+ * 
+ *     cdef _on_result__bind_and_exec(self, object waiter):             # <<<<<<<<<<<<<<
+ *         if self.return_extra:
+ *             waiter.set_result((
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__bind_and_exec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":722
+ *             waiter.set_result(self.result)
+ * 
+ *     cdef _on_result__bind(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.result)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__bind(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__bind", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":723
+ * 
+ *     cdef _on_result__bind(self, object waiter):
+ *         waiter.set_result(self.result)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__close_stmt_or_portal(self, object waiter):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->__pyx_base.result) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->__pyx_base.result);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 723, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":722
+ *             waiter.set_result(self.result)
+ * 
+ *     cdef _on_result__bind(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.result)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__bind", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":725
+ *         waiter.set_result(self.result)
+ * 
+ *     cdef _on_result__close_stmt_or_portal(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.result)
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__close_stmt_or_portal(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__close_stmt_or_portal", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":726
+ * 
+ *     cdef _on_result__close_stmt_or_portal(self, object waiter):
+ *         waiter.set_result(self.result)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__simple_query(self, object waiter):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->__pyx_base.result) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->__pyx_base.result);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":725
+ *         waiter.set_result(self.result)
+ * 
+ *     cdef _on_result__close_stmt_or_portal(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.result)
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__close_stmt_or_portal", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":728
+ *         waiter.set_result(self.result)
+ * 
+ *     cdef _on_result__simple_query(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.result_status_msg.decode(self.encoding))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__simple_query(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__simple_query", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":729
+ * 
+ *     cdef _on_result__simple_query(self, object waiter):
+ *         waiter.set_result(self.result_status_msg.decode(self.encoding))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__copy_out(self, object waiter):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.result_status_msg, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 729, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+    if (likely(__pyx_t_5)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+      __Pyx_INCREF(__pyx_t_5);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_4, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_self->__pyx_base.encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->__pyx_base.encoding);
+  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 729, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 729, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":728
+ *         waiter.set_result(self.result)
+ * 
+ *     cdef _on_result__simple_query(self, object waiter):             # <<<<<<<<<<<<<<
+ *         waiter.set_result(self.result_status_msg.decode(self.encoding))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__simple_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":731
+ *         waiter.set_result(self.result_status_msg.decode(self.encoding))
+ * 
+ *     cdef _on_result__copy_out(self, object waiter):             # <<<<<<<<<<<<<<
+ *         cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE
+ *         if copy_done:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__copy_out(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  int __pyx_v_copy_done;
+  PyObject *__pyx_v_status_msg = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__copy_out", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":732
+ * 
+ *     cdef _on_result__copy_out(self, object waiter):
+ *         cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE             # <<<<<<<<<<<<<<
+ *         if copy_done:
+ *             status_msg = self.result_status_msg.decode(self.encoding)
+ */
+  __pyx_v_copy_done = (__pyx_v_self->__pyx_base.state == __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DONE);
+
+  /* "asyncpg/protocol/protocol.pyx":733
+ *     cdef _on_result__copy_out(self, object waiter):
+ *         cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE
+ *         if copy_done:             # <<<<<<<<<<<<<<
+ *             status_msg = self.result_status_msg.decode(self.encoding)
+ *         else:
+ */
+  __pyx_t_1 = (__pyx_v_copy_done != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":734
+ *         cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE
+ *         if copy_done:
+ *             status_msg = self.result_status_msg.decode(self.encoding)             # <<<<<<<<<<<<<<
+ *         else:
+ *             status_msg = None
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.result_status_msg, __pyx_n_s_decode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 734, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+      }
+    }
+    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_self->__pyx_base.encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->__pyx_base.encoding);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 734, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_v_status_msg = __pyx_t_2;
+    __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":733
+ *     cdef _on_result__copy_out(self, object waiter):
+ *         cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE
+ *         if copy_done:             # <<<<<<<<<<<<<<
+ *             status_msg = self.result_status_msg.decode(self.encoding)
+ *         else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":736
+ *             status_msg = self.result_status_msg.decode(self.encoding)
+ *         else:
+ *             status_msg = None             # <<<<<<<<<<<<<<
+ * 
+ *         # We need to put some backpressure on Postgres
+ */
+  /*else*/ {
+    __Pyx_INCREF(Py_None);
+    __pyx_v_status_msg = Py_None;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/protocol.pyx":740
+ *         # We need to put some backpressure on Postgres
+ *         # here in case the sink is slow to process the output.
+ *         self.pause_reading()             # <<<<<<<<<<<<<<
+ * 
+ *         waiter.set_result((self.result, copy_done, status_msg))
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_pause_reading(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 740, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":742
+ *         self.pause_reading()
+ * 
+ *         waiter.set_result((self.result, copy_done, status_msg))             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result__copy_in(self, object waiter):
+ */
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 742, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_copy_done); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 742, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 742, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.result);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result);
+  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_self->__pyx_base.result);
+  __Pyx_GIVEREF(__pyx_t_4);
+  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
+  __Pyx_INCREF(__pyx_v_status_msg);
+  __Pyx_GIVEREF(__pyx_v_status_msg);
+  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_status_msg);
+  __pyx_t_4 = 0;
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":731
+ *         waiter.set_result(self.result_status_msg.decode(self.encoding))
+ * 
+ *     cdef _on_result__copy_out(self, object waiter):             # <<<<<<<<<<<<<<
+ *         cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE
+ *         if copy_done:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__copy_out", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_status_msg);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":744
+ *         waiter.set_result((self.result, copy_done, status_msg))
+ * 
+ *     cdef _on_result__copy_in(self, object waiter):             # <<<<<<<<<<<<<<
+ *         status_msg = self.result_status_msg.decode(self.encoding)
+ *         waiter.set_result(status_msg)
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__copy_in(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_waiter) {
+  PyObject *__pyx_v_status_msg = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("_on_result__copy_in", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":745
+ * 
+ *     cdef _on_result__copy_in(self, object waiter):
+ *         status_msg = self.result_status_msg.decode(self.encoding)             # <<<<<<<<<<<<<<
+ *         waiter.set_result(status_msg)
+ * 
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.result_status_msg, __pyx_n_s_decode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 745, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_self->__pyx_base.encoding) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->__pyx_base.encoding);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 745, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_status_msg = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":746
+ *     cdef _on_result__copy_in(self, object waiter):
+ *         status_msg = self.result_status_msg.decode(self.encoding)
+ *         waiter.set_result(status_msg)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 746, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_status_msg) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_status_msg);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 746, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":744
+ *         waiter.set_result((self.result, copy_done, status_msg))
+ * 
+ *     cdef _on_result__copy_in(self, object waiter):             # <<<<<<<<<<<<<<
+ *         status_msg = self.result_status_msg.decode(self.encoding)
+ *         waiter.set_result(status_msg)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result__copy_in", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_status_msg);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":748
+ *         waiter.set_result(status_msg)
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):             # <<<<<<<<<<<<<<
+ *         if PG_DEBUG:
+ *             if self.statement is None:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__decode_row(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, char const *__pyx_v_buf, Py_ssize_t __pyx_v_buf_len) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("_decode_row", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":749
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if self.statement is None:
+ *                 raise apg_exc.InternalClientError(
+ */
+  __pyx_t_1 = (PG_DEBUG != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":750
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):
+ *         if PG_DEBUG:
+ *             if self.statement is None:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_decode_row: statement is None')
+ */
+    __pyx_t_1 = (((PyObject *)__pyx_v_self->statement) == Py_None);
+    __pyx_t_2 = (__pyx_t_1 != 0);
+    if (unlikely(__pyx_t_2)) {
+
+      /* "asyncpg/protocol/protocol.pyx":751
+ *         if PG_DEBUG:
+ *             if self.statement is None:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     '_decode_row: statement is None')
+ * 
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 751, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_decode_row_statement_is_None) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_decode_row_statement_is_None);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 751, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __PYX_ERR(0, 751, __pyx_L1_error)
+
+      /* "asyncpg/protocol/protocol.pyx":750
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):
+ *         if PG_DEBUG:
+ *             if self.statement is None:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError(
+ *                     '_decode_row: statement is None')
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":749
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if self.statement is None:
+ *                 raise apg_exc.InternalClientError(
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":754
+ *                     '_decode_row: statement is None')
+ * 
+ *         return self.statement._decode_row(buf, buf_len)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _dispatch_result(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__decode_row(__pyx_v_self->statement, __pyx_v_buf, __pyx_v_buf_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 754, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":748
+ *         waiter.set_result(status_msg)
+ * 
+ *     cdef _decode_row(self, const char* buf, ssize_t buf_len):             # <<<<<<<<<<<<<<
+ *         if PG_DEBUG:
+ *             if self.statement is None:
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._decode_row", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":756
+ *         return self.statement._decode_row(buf, buf_len)
+ * 
+ *     cdef _dispatch_result(self):             # <<<<<<<<<<<<<<
+ *         waiter = self.waiter
+ *         self.waiter = None
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__dispatch_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_v_waiter = NULL;
+  PyObject *__pyx_v_exc = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  int __pyx_t_12;
+  int __pyx_t_13;
+  char const *__pyx_t_14;
+  PyObject *__pyx_t_15 = NULL;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  __Pyx_RefNannySetupContext("_dispatch_result", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":757
+ * 
+ *     cdef _dispatch_result(self):
+ *         waiter = self.waiter             # <<<<<<<<<<<<<<
+ *         self.waiter = None
+ * 
+ */
+  __pyx_t_1 = __pyx_v_self->waiter;
+  __Pyx_INCREF(__pyx_t_1);
+  __pyx_v_waiter = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":758
+ *     cdef _dispatch_result(self):
+ *         waiter = self.waiter
+ *         self.waiter = None             # <<<<<<<<<<<<<<
+ * 
+ *         if PG_DEBUG:
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->waiter);
+  __Pyx_DECREF(__pyx_v_self->waiter);
+  __pyx_v_self->waiter = Py_None;
+
+  /* "asyncpg/protocol/protocol.pyx":760
+ *         self.waiter = None
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if waiter is None:
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')
+ */
+  __pyx_t_2 = (PG_DEBUG != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":761
+ * 
+ *         if PG_DEBUG:
+ *             if waiter is None:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')
+ * 
+ */
+    __pyx_t_2 = (__pyx_v_waiter == Py_None);
+    __pyx_t_3 = (__pyx_t_2 != 0);
+    if (unlikely(__pyx_t_3)) {
+
+      /* "asyncpg/protocol/protocol.pyx":762
+ *         if PG_DEBUG:
+ *             if waiter is None:
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')             # <<<<<<<<<<<<<<
+ * 
+ *         if waiter.cancelled():
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 762, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 762, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __pyx_t_4 = NULL;
+      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_4)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_4);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_kp_u_on_result_waiter_is_None) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_kp_u_on_result_waiter_is_None);
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __PYX_ERR(0, 762, __pyx_L1_error)
+
+      /* "asyncpg/protocol/protocol.pyx":761
+ * 
+ *         if PG_DEBUG:
+ *             if waiter is None:             # <<<<<<<<<<<<<<
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":760
+ *         self.waiter = None
+ * 
+ *         if PG_DEBUG:             # <<<<<<<<<<<<<<
+ *             if waiter is None:
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":764
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')
+ * 
+ *         if waiter.cancelled():             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_cancelled); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 764, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 764, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 764, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/protocol.pyx":765
+ * 
+ *         if waiter.cancelled():
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         if waiter.done():
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":764
+ *                 raise apg_exc.InternalClientError('_on_result: waiter is None')
+ * 
+ *         if waiter.cancelled():             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":767
+ *             return
+ * 
+ *         if waiter.done():             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError('_on_result: waiter is done')
+ * 
+ */
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_done); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 767, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_5, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 767, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (unlikely(__pyx_t_3)) {
+
+    /* "asyncpg/protocol/protocol.pyx":768
+ * 
+ *         if waiter.done():
+ *             raise apg_exc.InternalClientError('_on_result: waiter is done')             # <<<<<<<<<<<<<<
+ * 
+ *         if self.result_type == RESULT_FAILED:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 768, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 768, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_kp_u_on_result_waiter_is_done) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_kp_u_on_result_waiter_is_done);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 768, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __PYX_ERR(0, 768, __pyx_L1_error)
+
+    /* "asyncpg/protocol/protocol.pyx":767
+ *             return
+ * 
+ *         if waiter.done():             # <<<<<<<<<<<<<<
+ *             raise apg_exc.InternalClientError('_on_result: waiter is done')
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":770
+ *             raise apg_exc.InternalClientError('_on_result: waiter is done')
+ * 
+ *         if self.result_type == RESULT_FAILED:             # <<<<<<<<<<<<<<
+ *             if isinstance(self.result, dict):
+ *                 exc = apg_exc_base.PostgresError.new(
+ */
+  __pyx_t_3 = ((__pyx_v_self->__pyx_base.result_type == __pyx_e_7asyncpg_8protocol_8protocol_RESULT_FAILED) != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/protocol.pyx":771
+ * 
+ *         if self.result_type == RESULT_FAILED:
+ *             if isinstance(self.result, dict):             # <<<<<<<<<<<<<<
+ *                 exc = apg_exc_base.PostgresError.new(
+ *                     self.result, query=self.last_query)
+ */
+    __pyx_t_1 = __pyx_v_self->__pyx_base.result;
+    __Pyx_INCREF(__pyx_t_1);
+    __pyx_t_3 = PyDict_Check(__pyx_t_1); 
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_2 = (__pyx_t_3 != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/protocol.pyx":772
+ *         if self.result_type == RESULT_FAILED:
+ *             if isinstance(self.result, dict):
+ *                 exc = apg_exc_base.PostgresError.new(             # <<<<<<<<<<<<<<
+ *                     self.result, query=self.last_query)
+ *             else:
+ */
+      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_apg_exc_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 772, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_PostgresError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 772, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_new); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 772, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":773
+ *             if isinstance(self.result, dict):
+ *                 exc = apg_exc_base.PostgresError.new(
+ *                     self.result, query=self.last_query)             # <<<<<<<<<<<<<<
+ *             else:
+ *                 exc = self.result
+ */
+      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 772, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_INCREF(__pyx_v_self->__pyx_base.result);
+      __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result);
+      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->__pyx_base.result);
+      __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 773, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_query, __pyx_v_self->last_query) < 0) __PYX_ERR(0, 773, __pyx_L1_error)
+
+      /* "asyncpg/protocol/protocol.pyx":772
+ *         if self.result_type == RESULT_FAILED:
+ *             if isinstance(self.result, dict):
+ *                 exc = apg_exc_base.PostgresError.new(             # <<<<<<<<<<<<<<
+ *                     self.result, query=self.last_query)
+ *             else:
+ */
+      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 772, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __pyx_v_exc = __pyx_t_6;
+      __pyx_t_6 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":771
+ * 
+ *         if self.result_type == RESULT_FAILED:
+ *             if isinstance(self.result, dict):             # <<<<<<<<<<<<<<
+ *                 exc = apg_exc_base.PostgresError.new(
+ *                     self.result, query=self.last_query)
+ */
+      goto __pyx_L8;
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":775
+ *                     self.result, query=self.last_query)
+ *             else:
+ *                 exc = self.result             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(exc)
+ *             return
+ */
+    /*else*/ {
+      __pyx_t_6 = __pyx_v_self->__pyx_base.result;
+      __Pyx_INCREF(__pyx_t_6);
+      __pyx_v_exc = __pyx_t_6;
+      __pyx_t_6 = 0;
+    }
+    __pyx_L8:;
+
+    /* "asyncpg/protocol/protocol.pyx":776
+ *             else:
+ *                 exc = self.result
+ *             waiter.set_exception(exc)             # <<<<<<<<<<<<<<
+ *             return
+ * 
+ */
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 776, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_6 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_exc) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_exc);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 776, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":777
+ *                 exc = self.result
+ *             waiter.set_exception(exc)
+ *             return             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+    goto __pyx_L0;
+
+    /* "asyncpg/protocol/protocol.pyx":770
+ *             raise apg_exc.InternalClientError('_on_result: waiter is done')
+ * 
+ *         if self.result_type == RESULT_FAILED:             # <<<<<<<<<<<<<<
+ *             if isinstance(self.result, dict):
+ *                 exc = apg_exc_base.PostgresError.new(
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":779
+ *             return
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             if self.state == PROTOCOL_AUTH:
+ *                 self._on_result__connect(waiter)
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+    __Pyx_XGOTREF(__pyx_t_7);
+    __Pyx_XGOTREF(__pyx_t_8);
+    __Pyx_XGOTREF(__pyx_t_9);
+    /*try:*/ {
+
+      /* "asyncpg/protocol/protocol.pyx":780
+ * 
+ *         try:
+ *             if self.state == PROTOCOL_AUTH:             # <<<<<<<<<<<<<<
+ *                 self._on_result__connect(waiter)
+ * 
+ */
+      switch (__pyx_v_self->__pyx_base.state) {
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_AUTH:
+
+        /* "asyncpg/protocol/protocol.pyx":781
+ *         try:
+ *             if self.state == PROTOCOL_AUTH:
+ *                 self._on_result__connect(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_PREPARE:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__connect(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 781, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":780
+ * 
+ *         try:
+ *             if self.state == PROTOCOL_AUTH:             # <<<<<<<<<<<<<<
+ *                 self._on_result__connect(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_PREPARE:
+
+        /* "asyncpg/protocol/protocol.pyx":784
+ * 
+ *             elif self.state == PROTOCOL_PREPARE:
+ *                 self._on_result__prepare(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_BIND_EXECUTE:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__prepare(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 784, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":783
+ *                 self._on_result__connect(waiter)
+ * 
+ *             elif self.state == PROTOCOL_PREPARE:             # <<<<<<<<<<<<<<
+ *                 self._on_result__prepare(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE:
+
+        /* "asyncpg/protocol/protocol.pyx":787
+ * 
+ *             elif self.state == PROTOCOL_BIND_EXECUTE:
+ *                 self._on_result__bind_and_exec(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_BIND_EXECUTE_MANY:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__bind_and_exec(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 787, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":786
+ *                 self._on_result__prepare(waiter)
+ * 
+ *             elif self.state == PROTOCOL_BIND_EXECUTE:             # <<<<<<<<<<<<<<
+ *                 self._on_result__bind_and_exec(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND_EXECUTE_MANY:
+
+        /* "asyncpg/protocol/protocol.pyx":790
+ * 
+ *             elif self.state == PROTOCOL_BIND_EXECUTE_MANY:
+ *                 self._on_result__bind_and_exec(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_EXECUTE:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__bind_and_exec(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 790, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":789
+ *                 self._on_result__bind_and_exec(waiter)
+ * 
+ *             elif self.state == PROTOCOL_BIND_EXECUTE_MANY:             # <<<<<<<<<<<<<<
+ *                 self._on_result__bind_and_exec(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_EXECUTE:
+
+        /* "asyncpg/protocol/protocol.pyx":793
+ * 
+ *             elif self.state == PROTOCOL_EXECUTE:
+ *                 self._on_result__bind_and_exec(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_BIND:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__bind_and_exec(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 793, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":792
+ *                 self._on_result__bind_and_exec(waiter)
+ * 
+ *             elif self.state == PROTOCOL_EXECUTE:             # <<<<<<<<<<<<<<
+ *                 self._on_result__bind_and_exec(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_BIND:
+
+        /* "asyncpg/protocol/protocol.pyx":796
+ * 
+ *             elif self.state == PROTOCOL_BIND:
+ *                 self._on_result__bind(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_CLOSE_STMT_PORTAL:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__bind(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 796, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":795
+ *                 self._on_result__bind_and_exec(waiter)
+ * 
+ *             elif self.state == PROTOCOL_BIND:             # <<<<<<<<<<<<<<
+ *                 self._on_result__bind(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_CLOSE_STMT_PORTAL:
+
+        /* "asyncpg/protocol/protocol.pyx":799
+ * 
+ *             elif self.state == PROTOCOL_CLOSE_STMT_PORTAL:
+ *                 self._on_result__close_stmt_or_portal(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_SIMPLE_QUERY:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__close_stmt_or_portal(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 799, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":798
+ *                 self._on_result__bind(waiter)
+ * 
+ *             elif self.state == PROTOCOL_CLOSE_STMT_PORTAL:             # <<<<<<<<<<<<<<
+ *                 self._on_result__close_stmt_or_portal(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_SIMPLE_QUERY:
+
+        /* "asyncpg/protocol/protocol.pyx":802
+ * 
+ *             elif self.state == PROTOCOL_SIMPLE_QUERY:
+ *                 self._on_result__simple_query(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA or
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__simple_query(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 802, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":801
+ *                 self._on_result__close_stmt_or_portal(waiter)
+ * 
+ *             elif self.state == PROTOCOL_SIMPLE_QUERY:             # <<<<<<<<<<<<<<
+ *                 self._on_result__simple_query(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DATA:
+
+        /* "asyncpg/protocol/protocol.pyx":804
+ *                 self._on_result__simple_query(waiter)
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA or             # <<<<<<<<<<<<<<
+ *                     self.state == PROTOCOL_COPY_OUT_DONE):
+ *                 self._on_result__copy_out(waiter)
+ */
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_OUT_DONE:
+
+        /* "asyncpg/protocol/protocol.pyx":806
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA or
+ *                     self.state == PROTOCOL_COPY_OUT_DONE):
+ *                 self._on_result__copy_out(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_COPY_IN_DATA:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__copy_out(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 806, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":804
+ *                 self._on_result__simple_query(waiter)
+ * 
+ *             elif (self.state == PROTOCOL_COPY_OUT_DATA or             # <<<<<<<<<<<<<<
+ *                     self.state == PROTOCOL_COPY_OUT_DONE):
+ *                 self._on_result__copy_out(waiter)
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_COPY_IN_DATA:
+
+        /* "asyncpg/protocol/protocol.pyx":809
+ * 
+ *             elif self.state == PROTOCOL_COPY_IN_DATA:
+ *                 self._on_result__copy_in(waiter)             # <<<<<<<<<<<<<<
+ * 
+ *             elif self.state == PROTOCOL_TERMINATING:
+ */
+        __pyx_t_6 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_on_result__copy_in(__pyx_v_self, __pyx_v_waiter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 809, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":808
+ *                 self._on_result__copy_out(waiter)
+ * 
+ *             elif self.state == PROTOCOL_COPY_IN_DATA:             # <<<<<<<<<<<<<<
+ *                 self._on_result__copy_in(waiter)
+ * 
+ */
+        break;
+        case __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_TERMINATING:
+
+        /* "asyncpg/protocol/protocol.pyx":811
+ *                 self._on_result__copy_in(waiter)
+ * 
+ *             elif self.state == PROTOCOL_TERMINATING:             # <<<<<<<<<<<<<<
+ *                 # We are waiting for the connection to drop, so
+ *                 # ignore any stray results at this point.
+ */
+        break;
+        default:
+
+        /* "asyncpg/protocol/protocol.pyx":817
+ * 
+ *             else:
+ *                 raise apg_exc.InternalClientError(             # <<<<<<<<<<<<<<
+ *                     'got result for unknown protocol state {}'.
+ *                     format(self.state))
+ */
+        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_apg_exc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 817, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_InternalClientError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 817, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":818
+ *             else:
+ *                 raise apg_exc.InternalClientError(
+ *                     'got result for unknown protocol state {}'.             # <<<<<<<<<<<<<<
+ *                     format(self.state))
+ * 
+ */
+        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_got_result_for_unknown_protocol, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 818, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_1);
+
+        /* "asyncpg/protocol/protocol.pyx":819
+ *                 raise apg_exc.InternalClientError(
+ *                     'got result for unknown protocol state {}'.
+ *                     format(self.state))             # <<<<<<<<<<<<<<
+ * 
+ *         except Exception as exc:
+ */
+        __pyx_t_10 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_self->__pyx_base.state); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 819, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_10);
+        __pyx_t_11 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
+          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1);
+          if (likely(__pyx_t_11)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
+            __Pyx_INCREF(__pyx_t_11);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_1, function);
+          }
+        }
+        __pyx_t_5 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_11, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_10);
+        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 819, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+        __pyx_t_1 = NULL;
+        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
+          if (likely(__pyx_t_1)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+            __Pyx_INCREF(__pyx_t_1);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_4, function);
+          }
+        }
+        __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
+        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 817, __pyx_L9_error)
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+        __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+        __PYX_ERR(0, 817, __pyx_L9_error)
+        break;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":779
+ *             return
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             if self.state == PROTOCOL_AUTH:
+ *                 self._on_result__connect(waiter)
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+    goto __pyx_L14_try_end;
+    __pyx_L9_error:;
+    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":821
+ *                     format(self.state))
+ * 
+ *         except Exception as exc:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(exc)
+ * 
+ */
+    __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+    if (__pyx_t_12) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._dispatch_result", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 821, __pyx_L11_except_error)
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_GOTREF(__pyx_t_5);
+      __Pyx_INCREF(__pyx_t_4);
+      __pyx_v_exc = __pyx_t_4;
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":822
+ * 
+ *         except Exception as exc:
+ *             waiter.set_exception(exc)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_result(self):
+ */
+        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 822, __pyx_L20_error)
+        __Pyx_GOTREF(__pyx_t_10);
+        __pyx_t_11 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
+          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10);
+          if (likely(__pyx_t_11)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
+            __Pyx_INCREF(__pyx_t_11);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_10, function);
+          }
+        }
+        __pyx_t_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_v_exc) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_exc);
+        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 822, __pyx_L20_error)
+        __Pyx_GOTREF(__pyx_t_1);
+        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":821
+ *                     format(self.state))
+ * 
+ *         except Exception as exc:             # <<<<<<<<<<<<<<
+ *             waiter.set_exception(exc)
+ * 
+ */
+      /*finally:*/ {
+        /*normal exit:*/{
+          __Pyx_DECREF(__pyx_v_exc);
+          __pyx_v_exc = NULL;
+          goto __pyx_L21;
+        }
+        __pyx_L20_error:;
+        /*exception exit:*/{
+          __Pyx_PyThreadState_declare
+          __Pyx_PyThreadState_assign
+          __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+          if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
+          if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
+          __Pyx_XGOTREF(__pyx_t_15);
+          __Pyx_XGOTREF(__pyx_t_16);
+          __Pyx_XGOTREF(__pyx_t_17);
+          __Pyx_XGOTREF(__pyx_t_18);
+          __Pyx_XGOTREF(__pyx_t_19);
+          __Pyx_XGOTREF(__pyx_t_20);
+          __pyx_t_12 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
+          {
+            __Pyx_DECREF(__pyx_v_exc);
+            __pyx_v_exc = NULL;
+          }
+          if (PY_MAJOR_VERSION >= 3) {
+            __Pyx_XGIVEREF(__pyx_t_18);
+            __Pyx_XGIVEREF(__pyx_t_19);
+            __Pyx_XGIVEREF(__pyx_t_20);
+            __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
+          }
+          __Pyx_XGIVEREF(__pyx_t_15);
+          __Pyx_XGIVEREF(__pyx_t_16);
+          __Pyx_XGIVEREF(__pyx_t_17);
+          __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
+          __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
+          __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
+          goto __pyx_L11_except_error;
+        }
+        __pyx_L21:;
+      }
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      goto __pyx_L10_exception_handled;
+    }
+    goto __pyx_L11_except_error;
+    __pyx_L11_except_error:;
+
+    /* "asyncpg/protocol/protocol.pyx":779
+ *             return
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             if self.state == PROTOCOL_AUTH:
+ *                 self._on_result__connect(waiter)
+ */
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+    goto __pyx_L1_error;
+    __pyx_L10_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_7);
+    __Pyx_XGIVEREF(__pyx_t_8);
+    __Pyx_XGIVEREF(__pyx_t_9);
+    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+    __pyx_L14_try_end:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":756
+ *         return self.statement._decode_row(buf, buf_len)
+ * 
+ *     cdef _dispatch_result(self):             # <<<<<<<<<<<<<<
+ *         waiter = self.waiter
+ *         self.waiter = None
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._dispatch_result", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_waiter);
+  __Pyx_XDECREF(__pyx_v_exc);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":824
+ *             waiter.set_exception(exc)
+ * 
+ *     cdef _on_result(self):             # <<<<<<<<<<<<<<
+ *         if self.timeout_handle is not None:
+ *             self.timeout_handle.cancel()
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  int __pyx_t_7;
+  int __pyx_t_8;
+  char const *__pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  __Pyx_RefNannySetupContext("_on_result", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":825
+ * 
+ *     cdef _on_result(self):
+ *         if self.timeout_handle is not None:             # <<<<<<<<<<<<<<
+ *             self.timeout_handle.cancel()
+ *             self.timeout_handle = None
+ */
+  __pyx_t_1 = (__pyx_v_self->timeout_handle != Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":826
+ *     cdef _on_result(self):
+ *         if self.timeout_handle is not None:
+ *             self.timeout_handle.cancel()             # <<<<<<<<<<<<<<
+ *             self.timeout_handle = None
+ * 
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->timeout_handle, __pyx_n_s_cancel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 826, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 826, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":827
+ *         if self.timeout_handle is not None:
+ *             self.timeout_handle.cancel()
+ *             self.timeout_handle = None             # <<<<<<<<<<<<<<
+ * 
+ *         if self.cancel_waiter is not None:
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_v_self->timeout_handle);
+    __Pyx_DECREF(__pyx_v_self->timeout_handle);
+    __pyx_v_self->timeout_handle = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":825
+ * 
+ *     cdef _on_result(self):
+ *         if self.timeout_handle is not None:             # <<<<<<<<<<<<<<
+ *             self.timeout_handle.cancel()
+ *             self.timeout_handle = None
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":829
+ *             self.timeout_handle = None
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             # We have received the result of a cancelled command.
+ *             if not self.cancel_waiter.done():
+ */
+  __pyx_t_2 = (__pyx_v_self->cancel_waiter != Py_None);
+  __pyx_t_1 = (__pyx_t_2 != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":831
+ *         if self.cancel_waiter is not None:
+ *             # We have received the result of a cancelled command.
+ *             if not self.cancel_waiter.done():             # <<<<<<<<<<<<<<
+ *                 # The cancellation future might have been cancelled
+ *                 # by the cancellation of the entire task running the query.
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->cancel_waiter, __pyx_n_s_done); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 831, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 831, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_2 = ((!__pyx_t_1) != 0);
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/protocol.pyx":834
+ *                 # The cancellation future might have been cancelled
+ *                 # by the cancellation of the entire task running the query.
+ *                 self.cancel_waiter.set_result(None)             # <<<<<<<<<<<<<<
+ *             self.cancel_waiter = None
+ *             if self.waiter is not None and self.waiter.done():
+ */
+      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->cancel_waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 834, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __pyx_t_5 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+        if (likely(__pyx_t_5)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+          __Pyx_INCREF(__pyx_t_5);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_4, function);
+        }
+      }
+      __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, Py_None) : __Pyx_PyObject_CallOneArg(__pyx_t_4, Py_None);
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 834, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":831
+ *         if self.cancel_waiter is not None:
+ *             # We have received the result of a cancelled command.
+ *             if not self.cancel_waiter.done():             # <<<<<<<<<<<<<<
+ *                 # The cancellation future might have been cancelled
+ *                 # by the cancellation of the entire task running the query.
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":835
+ *                 # by the cancellation of the entire task running the query.
+ *                 self.cancel_waiter.set_result(None)
+ *             self.cancel_waiter = None             # <<<<<<<<<<<<<<
+ *             if self.waiter is not None and self.waiter.done():
+ *                 self.waiter = None
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_v_self->cancel_waiter);
+    __Pyx_DECREF(__pyx_v_self->cancel_waiter);
+    __pyx_v_self->cancel_waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":836
+ *                 self.cancel_waiter.set_result(None)
+ *             self.cancel_waiter = None
+ *             if self.waiter is not None and self.waiter.done():             # <<<<<<<<<<<<<<
+ *                 self.waiter = None
+ *             if self.waiter is None:
+ */
+    __pyx_t_1 = (__pyx_v_self->waiter != Py_None);
+    __pyx_t_6 = (__pyx_t_1 != 0);
+    if (__pyx_t_6) {
+    } else {
+      __pyx_t_2 = __pyx_t_6;
+      goto __pyx_L7_bool_binop_done;
+    }
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_done); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 836, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 836, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 836, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_t_2 = __pyx_t_6;
+    __pyx_L7_bool_binop_done:;
+    if (__pyx_t_2) {
+
+      /* "asyncpg/protocol/protocol.pyx":837
+ *             self.cancel_waiter = None
+ *             if self.waiter is not None and self.waiter.done():
+ *                 self.waiter = None             # <<<<<<<<<<<<<<
+ *             if self.waiter is None:
+ *                 return
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_GIVEREF(Py_None);
+      __Pyx_GOTREF(__pyx_v_self->waiter);
+      __Pyx_DECREF(__pyx_v_self->waiter);
+      __pyx_v_self->waiter = Py_None;
+
+      /* "asyncpg/protocol/protocol.pyx":836
+ *                 self.cancel_waiter.set_result(None)
+ *             self.cancel_waiter = None
+ *             if self.waiter is not None and self.waiter.done():             # <<<<<<<<<<<<<<
+ *                 self.waiter = None
+ *             if self.waiter is None:
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":838
+ *             if self.waiter is not None and self.waiter.done():
+ *                 self.waiter = None
+ *             if self.waiter is None:             # <<<<<<<<<<<<<<
+ *                 return
+ * 
+ */
+    __pyx_t_2 = (__pyx_v_self->waiter == Py_None);
+    __pyx_t_6 = (__pyx_t_2 != 0);
+    if (__pyx_t_6) {
+
+      /* "asyncpg/protocol/protocol.pyx":839
+ *                 self.waiter = None
+ *             if self.waiter is None:
+ *                 return             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+      __Pyx_XDECREF(__pyx_r);
+      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+      goto __pyx_L0;
+
+      /* "asyncpg/protocol/protocol.pyx":838
+ *             if self.waiter is not None and self.waiter.done():
+ *                 self.waiter = None
+ *             if self.waiter is None:             # <<<<<<<<<<<<<<
+ *                 return
+ * 
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":829
+ *             self.timeout_handle = None
+ * 
+ *         if self.cancel_waiter is not None:             # <<<<<<<<<<<<<<
+ *             # We have received the result of a cancelled command.
+ *             if not self.cancel_waiter.done():
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":841
+ *                 return
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._dispatch_result()
+ *         finally:
+ */
+  /*try:*/ {
+
+    /* "asyncpg/protocol/protocol.pyx":842
+ * 
+ *         try:
+ *             self._dispatch_result()             # <<<<<<<<<<<<<<
+ *         finally:
+ *             self.statement = None
+ */
+    __pyx_t_3 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_dispatch_result(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 842, __pyx_L11_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":844
+ *             self._dispatch_result()
+ *         finally:
+ *             self.statement = None             # <<<<<<<<<<<<<<
+ *             self.last_query = None
+ *             self.return_extra = False
+ */
+  /*finally:*/ {
+    /*normal exit:*/{
+      __Pyx_INCREF(Py_None);
+      __Pyx_GIVEREF(Py_None);
+      __Pyx_GOTREF(__pyx_v_self->statement);
+      __Pyx_DECREF(((PyObject *)__pyx_v_self->statement));
+      __pyx_v_self->statement = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)Py_None);
+
+      /* "asyncpg/protocol/protocol.pyx":845
+ *         finally:
+ *             self.statement = None
+ *             self.last_query = None             # <<<<<<<<<<<<<<
+ *             self.return_extra = False
+ * 
+ */
+      __Pyx_INCREF(Py_None);
+      __Pyx_GIVEREF(Py_None);
+      __Pyx_GOTREF(__pyx_v_self->last_query);
+      __Pyx_DECREF(__pyx_v_self->last_query);
+      __pyx_v_self->last_query = ((PyObject*)Py_None);
+
+      /* "asyncpg/protocol/protocol.pyx":846
+ *             self.statement = None
+ *             self.last_query = None
+ *             self.return_extra = False             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_notice(self, parsed):
+ */
+      __pyx_v_self->return_extra = 0;
+      goto __pyx_L12;
+    }
+    __pyx_L11_error:;
+    /*exception exit:*/{
+      __Pyx_PyThreadState_declare
+      __Pyx_PyThreadState_assign
+      __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
+      if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12) < 0)) __Pyx_ErrFetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
+      __Pyx_XGOTREF(__pyx_t_10);
+      __Pyx_XGOTREF(__pyx_t_11);
+      __Pyx_XGOTREF(__pyx_t_12);
+      __Pyx_XGOTREF(__pyx_t_13);
+      __Pyx_XGOTREF(__pyx_t_14);
+      __Pyx_XGOTREF(__pyx_t_15);
+      __pyx_t_7 = __pyx_lineno; __pyx_t_8 = __pyx_clineno; __pyx_t_9 = __pyx_filename;
+      {
+
+        /* "asyncpg/protocol/protocol.pyx":844
+ *             self._dispatch_result()
+ *         finally:
+ *             self.statement = None             # <<<<<<<<<<<<<<
+ *             self.last_query = None
+ *             self.return_extra = False
+ */
+        __Pyx_INCREF(Py_None);
+        __Pyx_GIVEREF(Py_None);
+        __Pyx_GOTREF(__pyx_v_self->statement);
+        __Pyx_DECREF(((PyObject *)__pyx_v_self->statement));
+        __pyx_v_self->statement = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)Py_None);
+
+        /* "asyncpg/protocol/protocol.pyx":845
+ *         finally:
+ *             self.statement = None
+ *             self.last_query = None             # <<<<<<<<<<<<<<
+ *             self.return_extra = False
+ * 
+ */
+        __Pyx_INCREF(Py_None);
+        __Pyx_GIVEREF(Py_None);
+        __Pyx_GOTREF(__pyx_v_self->last_query);
+        __Pyx_DECREF(__pyx_v_self->last_query);
+        __pyx_v_self->last_query = ((PyObject*)Py_None);
+
+        /* "asyncpg/protocol/protocol.pyx":846
+ *             self.statement = None
+ *             self.last_query = None
+ *             self.return_extra = False             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_notice(self, parsed):
+ */
+        __pyx_v_self->return_extra = 0;
+      }
+      if (PY_MAJOR_VERSION >= 3) {
+        __Pyx_XGIVEREF(__pyx_t_13);
+        __Pyx_XGIVEREF(__pyx_t_14);
+        __Pyx_XGIVEREF(__pyx_t_15);
+        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
+      }
+      __Pyx_XGIVEREF(__pyx_t_10);
+      __Pyx_XGIVEREF(__pyx_t_11);
+      __Pyx_XGIVEREF(__pyx_t_12);
+      __Pyx_ErrRestore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+      __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
+      __pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_8; __pyx_filename = __pyx_t_9;
+      goto __pyx_L1_error;
+    }
+    __pyx_L12:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":824
+ *             waiter.set_exception(exc)
+ * 
+ *     cdef _on_result(self):             # <<<<<<<<<<<<<<
+ *         if self.timeout_handle is not None:
+ *             self.timeout_handle.cancel()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_result", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":848
+ *             self.return_extra = False
+ * 
+ *     cdef _on_notice(self, parsed):             # <<<<<<<<<<<<<<
+ *         con = self.get_connection()
+ *         if con is not None:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_notice(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_parsed) {
+  PyObject *__pyx_v_con = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("_on_notice", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":849
+ * 
+ *     cdef _on_notice(self, parsed):
+ *         con = self.get_connection()             # <<<<<<<<<<<<<<
+ *         if con is not None:
+ *             con._process_log_message(parsed, self.last_query)
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->get_connection(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_con = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":850
+ *     cdef _on_notice(self, parsed):
+ *         con = self.get_connection()
+ *         if con is not None:             # <<<<<<<<<<<<<<
+ *             con._process_log_message(parsed, self.last_query)
+ * 
+ */
+  __pyx_t_2 = (__pyx_v_con != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/protocol.pyx":851
+ *         con = self.get_connection()
+ *         if con is not None:
+ *             con._process_log_message(parsed, self.last_query)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_notification(self, pid, channel, payload):
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_con, __pyx_n_s_process_log_message); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 851, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    __pyx_t_6 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+        __pyx_t_6 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_parsed, __pyx_v_self->last_query};
+      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 851, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_GOTREF(__pyx_t_1);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_parsed, __pyx_v_self->last_query};
+      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 851, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_GOTREF(__pyx_t_1);
+    } else
+    #endif
+    {
+      __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 851, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      if (__pyx_t_5) {
+        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_parsed);
+      __Pyx_GIVEREF(__pyx_v_parsed);
+      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_parsed);
+      __Pyx_INCREF(__pyx_v_self->last_query);
+      __Pyx_GIVEREF(__pyx_v_self->last_query);
+      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_self->last_query);
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 851, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":850
+ *     cdef _on_notice(self, parsed):
+ *         con = self.get_connection()
+ *         if con is not None:             # <<<<<<<<<<<<<<
+ *             con._process_log_message(parsed, self.last_query)
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":848
+ *             self.return_extra = False
+ * 
+ *     cdef _on_notice(self, parsed):             # <<<<<<<<<<<<<<
+ *         con = self.get_connection()
+ *         if con is not None:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_notice", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_con);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":853
+ *             con._process_log_message(parsed, self.last_query)
+ * 
+ *     cdef _on_notification(self, pid, channel, payload):             # <<<<<<<<<<<<<<
+ *         con = self.get_connection()
+ *         if con is not None:
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_notification(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_pid, PyObject *__pyx_v_channel, PyObject *__pyx_v_payload) {
+  PyObject *__pyx_v_con = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  __Pyx_RefNannySetupContext("_on_notification", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":854
+ * 
+ *     cdef _on_notification(self, pid, channel, payload):
+ *         con = self.get_connection()             # <<<<<<<<<<<<<<
+ *         if con is not None:
+ *             con._process_notification(pid, channel, payload)
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->get_connection(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 854, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_v_con = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":855
+ *     cdef _on_notification(self, pid, channel, payload):
+ *         con = self.get_connection()
+ *         if con is not None:             # <<<<<<<<<<<<<<
+ *             con._process_notification(pid, channel, payload)
+ * 
+ */
+  __pyx_t_2 = (__pyx_v_con != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/protocol.pyx":856
+ *         con = self.get_connection()
+ *         if con is not None:
+ *             con._process_notification(pid, channel, payload)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _on_connection_lost(self, exc):
+ */
+    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_con, __pyx_n_s_process_notification); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 856, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = NULL;
+    __pyx_t_6 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_4, function);
+        __pyx_t_6 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_pid, __pyx_v_channel, __pyx_v_payload};
+      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 856, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_GOTREF(__pyx_t_1);
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_pid, __pyx_v_channel, __pyx_v_payload};
+      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 856, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_GOTREF(__pyx_t_1);
+    } else
+    #endif
+    {
+      __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 856, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      if (__pyx_t_5) {
+        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
+      }
+      __Pyx_INCREF(__pyx_v_pid);
+      __Pyx_GIVEREF(__pyx_v_pid);
+      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_pid);
+      __Pyx_INCREF(__pyx_v_channel);
+      __Pyx_GIVEREF(__pyx_v_channel);
+      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_channel);
+      __Pyx_INCREF(__pyx_v_payload);
+      __Pyx_GIVEREF(__pyx_v_payload);
+      PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_payload);
+      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 856, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_1);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":855
+ *     cdef _on_notification(self, pid, channel, payload):
+ *         con = self.get_connection()
+ *         if con is not None:             # <<<<<<<<<<<<<<
+ *             con._process_notification(pid, channel, payload)
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":853
+ *             con._process_log_message(parsed, self.last_query)
+ * 
+ *     cdef _on_notification(self, pid, channel, payload):             # <<<<<<<<<<<<<<
+ *         con = self.get_connection()
+ *         if con is not None:
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_notification", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_con);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":858
+ *             con._process_notification(pid, channel, payload)
+ * 
+ *     cdef _on_connection_lost(self, exc):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             # The connection was lost because
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_connection_lost(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_exc) {
+  PyObject *__pyx_v_con = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("_on_connection_lost", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":859
+ * 
+ *     cdef _on_connection_lost(self, exc):
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             # The connection was lost because
+ *             # Protocol.close() was called
+ */
+  __pyx_t_1 = (__pyx_v_self->closing != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/protocol/protocol.pyx":862
+ *             # The connection was lost because
+ *             # Protocol.close() was called
+ *             if self.waiter is not None and not self.waiter.done():             # <<<<<<<<<<<<<<
+ *                 if exc is None:
+ *                     self.waiter.set_result(None)
+ */
+    __pyx_t_2 = (__pyx_v_self->waiter != Py_None);
+    __pyx_t_3 = (__pyx_t_2 != 0);
+    if (__pyx_t_3) {
+    } else {
+      __pyx_t_1 = __pyx_t_3;
+      goto __pyx_L5_bool_binop_done;
+    }
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_done); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 862, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_6)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_6);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 862, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 862, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_2 = ((!__pyx_t_3) != 0);
+    __pyx_t_1 = __pyx_t_2;
+    __pyx_L5_bool_binop_done:;
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/protocol.pyx":863
+ *             # Protocol.close() was called
+ *             if self.waiter is not None and not self.waiter.done():
+ *                 if exc is None:             # <<<<<<<<<<<<<<
+ *                     self.waiter.set_result(None)
+ *                 else:
+ */
+      __pyx_t_1 = (__pyx_v_exc == Py_None);
+      __pyx_t_2 = (__pyx_t_1 != 0);
+      if (__pyx_t_2) {
+
+        /* "asyncpg/protocol/protocol.pyx":864
+ *             if self.waiter is not None and not self.waiter.done():
+ *                 if exc is None:
+ *                     self.waiter.set_result(None)             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     self.waiter.set_exception(exc)
+ */
+        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_set_result); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 864, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __pyx_t_6 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+          if (likely(__pyx_t_6)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+            __Pyx_INCREF(__pyx_t_6);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_5, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, Py_None) : __Pyx_PyObject_CallOneArg(__pyx_t_5, Py_None);
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 864, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":863
+ *             # Protocol.close() was called
+ *             if self.waiter is not None and not self.waiter.done():
+ *                 if exc is None:             # <<<<<<<<<<<<<<
+ *                     self.waiter.set_result(None)
+ *                 else:
+ */
+        goto __pyx_L7;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":866
+ *                     self.waiter.set_result(None)
+ *                 else:
+ *                     self.waiter.set_exception(exc)             # <<<<<<<<<<<<<<
+ *             self.waiter = None
+ *         else:
+ */
+      /*else*/ {
+        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->waiter, __pyx_n_s_set_exception); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_5);
+        __pyx_t_6 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+          if (likely(__pyx_t_6)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+            __Pyx_INCREF(__pyx_t_6);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_5, function);
+          }
+        }
+        __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_v_exc) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_exc);
+        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 866, __pyx_L1_error)
+        __Pyx_GOTREF(__pyx_t_4);
+        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+      }
+      __pyx_L7:;
+
+      /* "asyncpg/protocol/protocol.pyx":862
+ *             # The connection was lost because
+ *             # Protocol.close() was called
+ *             if self.waiter is not None and not self.waiter.done():             # <<<<<<<<<<<<<<
+ *                 if exc is None:
+ *                     self.waiter.set_result(None)
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":867
+ *                 else:
+ *                     self.waiter.set_exception(exc)
+ *             self.waiter = None             # <<<<<<<<<<<<<<
+ *         else:
+ *             # The connection was lost because it was
+ */
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    __Pyx_GOTREF(__pyx_v_self->waiter);
+    __Pyx_DECREF(__pyx_v_self->waiter);
+    __pyx_v_self->waiter = Py_None;
+
+    /* "asyncpg/protocol/protocol.pyx":859
+ * 
+ *     cdef _on_connection_lost(self, exc):
+ *         if self.closing:             # <<<<<<<<<<<<<<
+ *             # The connection was lost because
+ *             # Protocol.close() was called
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":872
+ *             # terminated or due to another error;
+ *             # Throw an error in any awaiting waiter.
+ *             self.closing = True             # <<<<<<<<<<<<<<
+ *             # Cleanup the connection resources, including, possibly,
+ *             # releasing the pool holder.
+ */
+  /*else*/ {
+    __pyx_v_self->closing = 1;
+
+    /* "asyncpg/protocol/protocol.pyx":875
+ *             # Cleanup the connection resources, including, possibly,
+ *             # releasing the pool holder.
+ *             con = self.get_connection()             # <<<<<<<<<<<<<<
+ *             if con is not None:
+ *                 con._cleanup()
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->get_connection(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 875, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_v_con = __pyx_t_4;
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":876
+ *             # releasing the pool holder.
+ *             con = self.get_connection()
+ *             if con is not None:             # <<<<<<<<<<<<<<
+ *                 con._cleanup()
+ *             self._handle_waiter_on_connection_lost(exc)
+ */
+    __pyx_t_2 = (__pyx_v_con != Py_None);
+    __pyx_t_1 = (__pyx_t_2 != 0);
+    if (__pyx_t_1) {
+
+      /* "asyncpg/protocol/protocol.pyx":877
+ *             con = self.get_connection()
+ *             if con is not None:
+ *                 con._cleanup()             # <<<<<<<<<<<<<<
+ *             self._handle_waiter_on_connection_lost(exc)
+ * 
+ */
+      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_con, __pyx_n_s_cleanup); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 877, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_5);
+      __pyx_t_6 = NULL;
+      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+        if (likely(__pyx_t_6)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+          __Pyx_INCREF(__pyx_t_6);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_5, function);
+        }
+      }
+      __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 877, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_4);
+      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":876
+ *             # releasing the pool holder.
+ *             con = self.get_connection()
+ *             if con is not None:             # <<<<<<<<<<<<<<
+ *                 con._cleanup()
+ *             self._handle_waiter_on_connection_lost(exc)
+ */
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":878
+ *             if con is not None:
+ *                 con._cleanup()
+ *             self._handle_waiter_on_connection_lost(exc)             # <<<<<<<<<<<<<<
+ * 
+ *     cdef _write(self, buf):
+ */
+    __pyx_t_4 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->_handle_waiter_on_connection_lost(__pyx_v_self, __pyx_v_exc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 878, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/protocol.pyx":858
+ *             con._process_notification(pid, channel, payload)
+ * 
+ *     cdef _on_connection_lost(self, exc):             # <<<<<<<<<<<<<<
+ *         if self.closing:
+ *             # The connection was lost because
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._on_connection_lost", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_con);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":880
+ *             self._handle_waiter_on_connection_lost(exc)
+ * 
+ *     cdef _write(self, buf):             # <<<<<<<<<<<<<<
+ *         self.transport.write(memoryview(buf))
+ * 
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__write(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_buf) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  __Pyx_RefNannySetupContext("_write", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":881
+ * 
+ *     cdef _write(self, buf):
+ *         self.transport.write(memoryview(buf))             # <<<<<<<<<<<<<<
+ * 
+ *     # asyncio callbacks:
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base.transport, __pyx_n_s_write); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 881, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_memoryview); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 881, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_buf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 881, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":880
+ *             self._handle_waiter_on_connection_lost(exc)
+ * 
+ *     cdef _write(self, buf):             # <<<<<<<<<<<<<<
+ *         self.transport.write(memoryview(buf))
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol._write", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":885
+ *     # asyncio callbacks:
+ * 
+ *     def data_received(self, data):             # <<<<<<<<<<<<<<
+ *         self.buffer.feed_data(data)
+ *         self._read_server_messages()
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_62data_received(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_62data_received(PyObject *__pyx_v_self, PyObject *__pyx_v_data) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("data_received (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_61data_received(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_data));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_61data_received(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_data) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("data_received", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":886
+ * 
+ *     def data_received(self, data):
+ *         self.buffer.feed_data(data)             # <<<<<<<<<<<<<<
+ *         self._read_server_messages()
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->__pyx_base.buffer->__pyx_vtab)->feed_data(__pyx_v_self->__pyx_base.buffer, __pyx_v_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":887
+ *     def data_received(self, data):
+ *         self.buffer.feed_data(data)
+ *         self._read_server_messages()             # <<<<<<<<<<<<<<
+ * 
+ *     def connection_made(self, transport):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._read_server_messages(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":885
+ *     # asyncio callbacks:
+ * 
+ *     def data_received(self, data):             # <<<<<<<<<<<<<<
+ *         self.buffer.feed_data(data)
+ *         self._read_server_messages()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.data_received", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":889
+ *         self._read_server_messages()
+ * 
+ *     def connection_made(self, transport):             # <<<<<<<<<<<<<<
+ *         self.transport = transport
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_64connection_made(PyObject *__pyx_v_self, PyObject *__pyx_v_transport); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_64connection_made(PyObject *__pyx_v_self, PyObject *__pyx_v_transport) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("connection_made (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_63connection_made(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_transport));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_63connection_made(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_transport) {
+  PyObject *__pyx_v_sock = NULL;
+  PyObject *__pyx_v_ex = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  int __pyx_t_6;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  int __pyx_t_9;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  int __pyx_t_14;
+  char const *__pyx_t_15;
+  PyObject *__pyx_t_16 = NULL;
+  PyObject *__pyx_t_17 = NULL;
+  PyObject *__pyx_t_18 = NULL;
+  PyObject *__pyx_t_19 = NULL;
+  PyObject *__pyx_t_20 = NULL;
+  PyObject *__pyx_t_21 = NULL;
+  __Pyx_RefNannySetupContext("connection_made", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":890
+ * 
+ *     def connection_made(self, transport):
+ *         self.transport = transport             # <<<<<<<<<<<<<<
+ * 
+ *         sock = transport.get_extra_info('socket')
+ */
+  __Pyx_INCREF(__pyx_v_transport);
+  __Pyx_GIVEREF(__pyx_v_transport);
+  __Pyx_GOTREF(__pyx_v_self->__pyx_base.transport);
+  __Pyx_DECREF(__pyx_v_self->__pyx_base.transport);
+  __pyx_v_self->__pyx_base.transport = __pyx_v_transport;
+
+  /* "asyncpg/protocol/protocol.pyx":892
+ *         self.transport = transport
+ * 
+ *         sock = transport.get_extra_info('socket')             # <<<<<<<<<<<<<<
+ *         if (sock is not None and
+ *               (not hasattr(socket, 'AF_UNIX')
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_transport, __pyx_n_s_get_extra_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 892, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_3)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_3);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_u_socket) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_u_socket);
+  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 892, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v_sock = __pyx_t_1;
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":893
+ * 
+ *         sock = transport.get_extra_info('socket')
+ *         if (sock is not None and             # <<<<<<<<<<<<<<
+ *               (not hasattr(socket, 'AF_UNIX')
+ *                or sock.family != socket.AF_UNIX)):
+ */
+  __pyx_t_5 = (__pyx_v_sock != Py_None);
+  __pyx_t_6 = (__pyx_t_5 != 0);
+  if (__pyx_t_6) {
+  } else {
+    __pyx_t_4 = __pyx_t_6;
+    goto __pyx_L4_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":894
+ *         sock = transport.get_extra_info('socket')
+ *         if (sock is not None and
+ *               (not hasattr(socket, 'AF_UNIX')             # <<<<<<<<<<<<<<
+ *                or sock.family != socket.AF_UNIX)):
+ *             sock.setsockopt(socket.IPPROTO_TCP,
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_socket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 894, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_6 = __Pyx_HasAttr(__pyx_t_1, __pyx_n_u_AF_UNIX); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 894, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_5 = ((!(__pyx_t_6 != 0)) != 0);
+  if (!__pyx_t_5) {
+  } else {
+    __pyx_t_4 = __pyx_t_5;
+    goto __pyx_L4_bool_binop_done;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":895
+ *         if (sock is not None and
+ *               (not hasattr(socket, 'AF_UNIX')
+ *                or sock.family != socket.AF_UNIX)):             # <<<<<<<<<<<<<<
+ *             sock.setsockopt(socket.IPPROTO_TCP,
+ *                             socket.TCP_NODELAY, 1)
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_sock, __pyx_n_s_family); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 895, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_socket); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 895, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_AF_UNIX); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 895, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 895, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 895, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_4 = __pyx_t_5;
+  __pyx_L4_bool_binop_done:;
+
+  /* "asyncpg/protocol/protocol.pyx":893
+ * 
+ *         sock = transport.get_extra_info('socket')
+ *         if (sock is not None and             # <<<<<<<<<<<<<<
+ *               (not hasattr(socket, 'AF_UNIX')
+ *                or sock.family != socket.AF_UNIX)):
+ */
+  if (__pyx_t_4) {
+
+    /* "asyncpg/protocol/protocol.pyx":896
+ *               (not hasattr(socket, 'AF_UNIX')
+ *                or sock.family != socket.AF_UNIX)):
+ *             sock.setsockopt(socket.IPPROTO_TCP,             # <<<<<<<<<<<<<<
+ *                             socket.TCP_NODELAY, 1)
+ * 
+ */
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_sock, __pyx_n_s_setsockopt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 896, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_socket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 896, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_IPPROTO_TCP); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 896, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":897
+ *                or sock.family != socket.AF_UNIX)):
+ *             sock.setsockopt(socket.IPPROTO_TCP,
+ *                             socket.TCP_NODELAY, 1)             # <<<<<<<<<<<<<<
+ * 
+ *         try:
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_socket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 897, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_TCP_NODELAY); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 897, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_8);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_t_1 = NULL;
+    __pyx_t_9 = 0;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
+      if (likely(__pyx_t_1)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+        __Pyx_INCREF(__pyx_t_1);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_3, function);
+        __pyx_t_9 = 1;
+      }
+    }
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(__pyx_t_3)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_t_7, __pyx_t_8, __pyx_int_1};
+      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
+      PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_t_7, __pyx_t_8, __pyx_int_1};
+      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
+      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    } else
+    #endif
+    {
+      __pyx_t_10 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 896, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_10);
+      if (__pyx_t_1) {
+        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_7);
+      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_7);
+      __Pyx_GIVEREF(__pyx_t_8);
+      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_8);
+      __Pyx_INCREF(__pyx_int_1);
+      __Pyx_GIVEREF(__pyx_int_1);
+      PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_int_1);
+      __pyx_t_7 = 0;
+      __pyx_t_8 = 0;
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    }
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":893
+ * 
+ *         sock = transport.get_extra_info('socket')
+ *         if (sock is not None and             # <<<<<<<<<<<<<<
+ *               (not hasattr(socket, 'AF_UNIX')
+ *                or sock.family != socket.AF_UNIX)):
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":899
+ *                             socket.TCP_NODELAY, 1)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._connect()
+ *         except Exception as ex:
+ */
+  {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
+    __Pyx_XGOTREF(__pyx_t_11);
+    __Pyx_XGOTREF(__pyx_t_12);
+    __Pyx_XGOTREF(__pyx_t_13);
+    /*try:*/ {
+
+      /* "asyncpg/protocol/protocol.pyx":900
+ * 
+ *         try:
+ *             self._connect()             # <<<<<<<<<<<<<<
+ *         except Exception as ex:
+ *             transport.abort()
+ */
+      __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._connect(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 900, __pyx_L7_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+      /* "asyncpg/protocol/protocol.pyx":899
+ *                             socket.TCP_NODELAY, 1)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._connect()
+ *         except Exception as ex:
+ */
+    }
+    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
+    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+    goto __pyx_L12_try_end;
+    __pyx_L7_error:;
+    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":901
+ *         try:
+ *             self._connect()
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             transport.abort()
+ *             self.con_status = CONNECTION_BAD
+ */
+    __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0])));
+    if (__pyx_t_9) {
+      __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.connection_made", __pyx_clineno, __pyx_lineno, __pyx_filename);
+      if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_10) < 0) __PYX_ERR(0, 901, __pyx_L9_except_error)
+      __Pyx_GOTREF(__pyx_t_2);
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_GOTREF(__pyx_t_10);
+      __Pyx_INCREF(__pyx_t_3);
+      __pyx_v_ex = __pyx_t_3;
+      /*try:*/ {
+
+        /* "asyncpg/protocol/protocol.pyx":902
+ *             self._connect()
+ *         except Exception as ex:
+ *             transport.abort()             # <<<<<<<<<<<<<<
+ *             self.con_status = CONNECTION_BAD
+ *             self._set_state(PROTOCOL_FAILED)
+ */
+        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_transport, __pyx_n_s_abort); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 902, __pyx_L18_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __pyx_t_1 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
+          if (likely(__pyx_t_1)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+            __Pyx_INCREF(__pyx_t_1);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_7, function);
+          }
+        }
+        __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
+        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 902, __pyx_L18_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":903
+ *         except Exception as ex:
+ *             transport.abort()
+ *             self.con_status = CONNECTION_BAD             # <<<<<<<<<<<<<<
+ *             self._set_state(PROTOCOL_FAILED)
+ *             self._on_error(ex)
+ */
+        __pyx_v_self->__pyx_base.con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD;
+
+        /* "asyncpg/protocol/protocol.pyx":904
+ *             transport.abort()
+ *             self.con_status = CONNECTION_BAD
+ *             self._set_state(PROTOCOL_FAILED)             # <<<<<<<<<<<<<<
+ *             self._on_error(ex)
+ * 
+ */
+        __pyx_t_8 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._set_state(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self), __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 904, __pyx_L18_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+
+        /* "asyncpg/protocol/protocol.pyx":905
+ *             self.con_status = CONNECTION_BAD
+ *             self._set_state(PROTOCOL_FAILED)
+ *             self._on_error(ex)             # <<<<<<<<<<<<<<
+ * 
+ *     def connection_lost(self, exc):
+ */
+        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_on_error); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 905, __pyx_L18_error)
+        __Pyx_GOTREF(__pyx_t_7);
+        __pyx_t_1 = NULL;
+        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
+          if (likely(__pyx_t_1)) {
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+            __Pyx_INCREF(__pyx_t_1);
+            __Pyx_INCREF(function);
+            __Pyx_DECREF_SET(__pyx_t_7, function);
+          }
+        }
+        __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_v_ex) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_ex);
+        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 905, __pyx_L18_error)
+        __Pyx_GOTREF(__pyx_t_8);
+        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+      }
+
+      /* "asyncpg/protocol/protocol.pyx":901
+ *         try:
+ *             self._connect()
+ *         except Exception as ex:             # <<<<<<<<<<<<<<
+ *             transport.abort()
+ *             self.con_status = CONNECTION_BAD
+ */
+      /*finally:*/ {
+        /*normal exit:*/{
+          __Pyx_DECREF(__pyx_v_ex);
+          __pyx_v_ex = NULL;
+          goto __pyx_L19;
+        }
+        __pyx_L18_error:;
+        /*exception exit:*/{
+          __Pyx_PyThreadState_declare
+          __Pyx_PyThreadState_assign
+          __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0;
+          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+          if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21);
+          if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18) < 0)) __Pyx_ErrFetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
+          __Pyx_XGOTREF(__pyx_t_16);
+          __Pyx_XGOTREF(__pyx_t_17);
+          __Pyx_XGOTREF(__pyx_t_18);
+          __Pyx_XGOTREF(__pyx_t_19);
+          __Pyx_XGOTREF(__pyx_t_20);
+          __Pyx_XGOTREF(__pyx_t_21);
+          __pyx_t_9 = __pyx_lineno; __pyx_t_14 = __pyx_clineno; __pyx_t_15 = __pyx_filename;
+          {
+            __Pyx_DECREF(__pyx_v_ex);
+            __pyx_v_ex = NULL;
+          }
+          if (PY_MAJOR_VERSION >= 3) {
+            __Pyx_XGIVEREF(__pyx_t_19);
+            __Pyx_XGIVEREF(__pyx_t_20);
+            __Pyx_XGIVEREF(__pyx_t_21);
+            __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21);
+          }
+          __Pyx_XGIVEREF(__pyx_t_16);
+          __Pyx_XGIVEREF(__pyx_t_17);
+          __Pyx_XGIVEREF(__pyx_t_18);
+          __Pyx_ErrRestore(__pyx_t_16, __pyx_t_17, __pyx_t_18);
+          __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0;
+          __pyx_lineno = __pyx_t_9; __pyx_clineno = __pyx_t_14; __pyx_filename = __pyx_t_15;
+          goto __pyx_L9_except_error;
+        }
+        __pyx_L19:;
+      }
+      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+      goto __pyx_L8_exception_handled;
+    }
+    goto __pyx_L9_except_error;
+    __pyx_L9_except_error:;
+
+    /* "asyncpg/protocol/protocol.pyx":899
+ *                             socket.TCP_NODELAY, 1)
+ * 
+ *         try:             # <<<<<<<<<<<<<<
+ *             self._connect()
+ *         except Exception as ex:
+ */
+    __Pyx_XGIVEREF(__pyx_t_11);
+    __Pyx_XGIVEREF(__pyx_t_12);
+    __Pyx_XGIVEREF(__pyx_t_13);
+    __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
+    goto __pyx_L1_error;
+    __pyx_L8_exception_handled:;
+    __Pyx_XGIVEREF(__pyx_t_11);
+    __Pyx_XGIVEREF(__pyx_t_12);
+    __Pyx_XGIVEREF(__pyx_t_13);
+    __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
+    __pyx_L12_try_end:;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":889
+ *         self._read_server_messages()
+ * 
+ *     def connection_made(self, transport):             # <<<<<<<<<<<<<<
+ *         self.transport = transport
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.connection_made", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_sock);
+  __Pyx_XDECREF(__pyx_v_ex);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":907
+ *             self._on_error(ex)
+ * 
+ *     def connection_lost(self, exc):             # <<<<<<<<<<<<<<
+ *         self.con_status = CONNECTION_BAD
+ *         self._set_state(PROTOCOL_FAILED)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_66connection_lost(PyObject *__pyx_v_self, PyObject *__pyx_v_exc); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_66connection_lost(PyObject *__pyx_v_self, PyObject *__pyx_v_exc) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("connection_lost (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_65connection_lost(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v_exc));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_65connection_lost(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v_exc) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("connection_lost", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":908
+ * 
+ *     def connection_lost(self, exc):
+ *         self.con_status = CONNECTION_BAD             # <<<<<<<<<<<<<<
+ *         self._set_state(PROTOCOL_FAILED)
+ *         self._on_connection_lost(exc)
+ */
+  __pyx_v_self->__pyx_base.con_status = __pyx_e_7asyncpg_8protocol_8protocol_CONNECTION_BAD;
+
+  /* "asyncpg/protocol/protocol.pyx":909
+ *     def connection_lost(self, exc):
+ *         self.con_status = CONNECTION_BAD
+ *         self._set_state(PROTOCOL_FAILED)             # <<<<<<<<<<<<<<
+ *         self._on_connection_lost(exc)
+ * 
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._set_state(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self), __pyx_e_7asyncpg_8protocol_8protocol_PROTOCOL_FAILED); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 909, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":910
+ *         self.con_status = CONNECTION_BAD
+ *         self._set_state(PROTOCOL_FAILED)
+ *         self._on_connection_lost(exc)             # <<<<<<<<<<<<<<
+ * 
+ *     def pause_writing(self):
+ */
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._on_connection_lost(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v_self), __pyx_v_exc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":907
+ *             self._on_error(ex)
+ * 
+ *     def connection_lost(self, exc):             # <<<<<<<<<<<<<<
+ *         self.con_status = CONNECTION_BAD
+ *         self._set_state(PROTOCOL_FAILED)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.connection_lost", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":912
+ *         self._on_connection_lost(exc)
+ * 
+ *     def pause_writing(self):             # <<<<<<<<<<<<<<
+ *         self.writing_allowed.clear()
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_68pause_writing(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_68pause_writing(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("pause_writing (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_67pause_writing(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_67pause_writing(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("pause_writing", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":913
+ * 
+ *     def pause_writing(self):
+ *         self.writing_allowed.clear()             # <<<<<<<<<<<<<<
+ * 
+ *     def resume_writing(self):
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_writing_allowed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_clear); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 913, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 913, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":912
+ *         self._on_connection_lost(exc)
+ * 
+ *     def pause_writing(self):             # <<<<<<<<<<<<<<
+ *         self.writing_allowed.clear()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.pause_writing", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":915
+ *         self.writing_allowed.clear()
+ * 
+ *     def resume_writing(self):             # <<<<<<<<<<<<<<
+ *         self.writing_allowed.set()
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_70resume_writing(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_70resume_writing(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("resume_writing (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_69resume_writing(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_69resume_writing(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("resume_writing", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":916
+ * 
+ *     def resume_writing(self):
+ *         self.writing_allowed.set()             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_writing_allowed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 916, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_set); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 916, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 916, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":915
+ *         self.writing_allowed.clear()
+ * 
+ *     def resume_writing(self):             # <<<<<<<<<<<<<<
+ *         self.writing_allowed.set()
+ * 
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.resume_writing", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pxd":52
+ *         bint closing
+ * 
+ *         readonly uint64_t queries_count             # <<<<<<<<<<<<<<
+ * 
+ *         PreparedStatementState statement
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_13queries_count_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_13queries_count_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_13queries_count___get__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_13queries_count___get__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__get__", 0);
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_self->queries_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(13, 52, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.queries_count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.address, self.backend_pid, self.backend_secret, self.buffer, self.cancel_sent_waiter, self.cancel_waiter, self.closing, self.completed_callback, self.con_params, self.con_status, self.conref, self.create_future, self.encoding, self.is_reading, self.last_query, self.loop, self.queries_count, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.return_extra, self.settings, self.state, self.statement, self.timeout_callback, self.timeout_handle, self.transport, self.waiter, self.writing_paused, self.xact_status)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_72__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_72__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_71__reduce_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_71__reduce_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self) {
+  int __pyx_v_use_setstate;
+  PyObject *__pyx_v_state = NULL;
+  PyObject *__pyx_v__dict = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  PyObject *__pyx_t_10 = NULL;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  PyObject *__pyx_t_15 = NULL;
+  int __pyx_t_16;
+  int __pyx_t_17;
+  int __pyx_t_18;
+  __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+  /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.address, self.backend_pid, self.backend_secret, self.buffer, self.cancel_sent_waiter, self.cancel_waiter, self.closing, self.completed_callback, self.con_params, self.con_status, self.conref, self.create_future, self.encoding, self.is_reading, self.last_query, self.loop, self.queries_count, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.return_extra, self.settings, self.state, self.statement, self.timeout_callback, self.timeout_handle, self.transport, self.waiter, self.writing_paused, self.xact_status)             # <<<<<<<<<<<<<<
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ */
+  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->__pyx_base._discard_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->__pyx_base._skip_discard); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_self->__pyx_base.backend_pid); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->__pyx_base.backend_secret); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_4);
+  __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_self->closing); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_5);
+  __pyx_t_6 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(__pyx_v_self->__pyx_base.con_status); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->is_reading); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  __pyx_t_8 = __Pyx_PyInt_From_uint64_t(__pyx_v_self->queries_count); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_8);
+  __pyx_t_9 = __Pyx_PyBool_FromLong(__pyx_v_self->__pyx_base.result_execute_completed); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_9);
+  __pyx_t_10 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(__pyx_v_self->__pyx_base.result_type); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_10);
+  __pyx_t_11 = __Pyx_PyBool_FromLong(__pyx_v_self->return_extra); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_11);
+  __pyx_t_12 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_v_self->__pyx_base.state); if (unlikely(!__pyx_t_12)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_12);
+  __pyx_t_13 = __Pyx_PyBool_FromLong(__pyx_v_self->writing_paused); if (unlikely(!__pyx_t_13)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_13);
+  __pyx_t_14 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(__pyx_v_self->__pyx_base.xact_status); if (unlikely(!__pyx_t_14)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_14);
+  __pyx_t_15 = PyTuple_New(38); if (unlikely(!__pyx_t_15)) __PYX_ERR(2, 3, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_15);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_1);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base._execute_iter);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base._execute_iter);
+  PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_self->__pyx_base._execute_iter);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base._execute_portal_name);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base._execute_portal_name);
+  PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_v_self->__pyx_base._execute_portal_name);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base._execute_stmt_name);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base._execute_stmt_name);
+  PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_v_self->__pyx_base._execute_stmt_name);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_t_2);
+  __Pyx_INCREF(__pyx_v_self->address);
+  __Pyx_GIVEREF(__pyx_v_self->address);
+  PyTuple_SET_ITEM(__pyx_t_15, 5, __pyx_v_self->address);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_15, 6, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_4);
+  PyTuple_SET_ITEM(__pyx_t_15, 7, __pyx_t_4);
+  __Pyx_INCREF(((PyObject *)__pyx_v_self->__pyx_base.buffer));
+  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->__pyx_base.buffer));
+  PyTuple_SET_ITEM(__pyx_t_15, 8, ((PyObject *)__pyx_v_self->__pyx_base.buffer));
+  __Pyx_INCREF(__pyx_v_self->cancel_sent_waiter);
+  __Pyx_GIVEREF(__pyx_v_self->cancel_sent_waiter);
+  PyTuple_SET_ITEM(__pyx_t_15, 9, __pyx_v_self->cancel_sent_waiter);
+  __Pyx_INCREF(__pyx_v_self->cancel_waiter);
+  __Pyx_GIVEREF(__pyx_v_self->cancel_waiter);
+  PyTuple_SET_ITEM(__pyx_t_15, 10, __pyx_v_self->cancel_waiter);
+  __Pyx_GIVEREF(__pyx_t_5);
+  PyTuple_SET_ITEM(__pyx_t_15, 11, __pyx_t_5);
+  __Pyx_INCREF(__pyx_v_self->completed_callback);
+  __Pyx_GIVEREF(__pyx_v_self->completed_callback);
+  PyTuple_SET_ITEM(__pyx_t_15, 12, __pyx_v_self->completed_callback);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.con_params);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.con_params);
+  PyTuple_SET_ITEM(__pyx_t_15, 13, __pyx_v_self->__pyx_base.con_params);
+  __Pyx_GIVEREF(__pyx_t_6);
+  PyTuple_SET_ITEM(__pyx_t_15, 14, __pyx_t_6);
+  __Pyx_INCREF(__pyx_v_self->conref);
+  __Pyx_GIVEREF(__pyx_v_self->conref);
+  PyTuple_SET_ITEM(__pyx_t_15, 15, __pyx_v_self->conref);
+  __Pyx_INCREF(__pyx_v_self->create_future);
+  __Pyx_GIVEREF(__pyx_v_self->create_future);
+  PyTuple_SET_ITEM(__pyx_t_15, 16, __pyx_v_self->create_future);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.encoding);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.encoding);
+  PyTuple_SET_ITEM(__pyx_t_15, 17, __pyx_v_self->__pyx_base.encoding);
+  __Pyx_GIVEREF(__pyx_t_7);
+  PyTuple_SET_ITEM(__pyx_t_15, 18, __pyx_t_7);
+  __Pyx_INCREF(__pyx_v_self->last_query);
+  __Pyx_GIVEREF(__pyx_v_self->last_query);
+  PyTuple_SET_ITEM(__pyx_t_15, 19, __pyx_v_self->last_query);
+  __Pyx_INCREF(__pyx_v_self->loop);
+  __Pyx_GIVEREF(__pyx_v_self->loop);
+  PyTuple_SET_ITEM(__pyx_t_15, 20, __pyx_v_self->loop);
+  __Pyx_GIVEREF(__pyx_t_8);
+  PyTuple_SET_ITEM(__pyx_t_15, 21, __pyx_t_8);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.result);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result);
+  PyTuple_SET_ITEM(__pyx_t_15, 22, __pyx_v_self->__pyx_base.result);
+  __Pyx_GIVEREF(__pyx_t_9);
+  PyTuple_SET_ITEM(__pyx_t_15, 23, __pyx_t_9);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.result_param_desc);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result_param_desc);
+  PyTuple_SET_ITEM(__pyx_t_15, 24, __pyx_v_self->__pyx_base.result_param_desc);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.result_row_desc);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result_row_desc);
+  PyTuple_SET_ITEM(__pyx_t_15, 25, __pyx_v_self->__pyx_base.result_row_desc);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.result_status_msg);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.result_status_msg);
+  PyTuple_SET_ITEM(__pyx_t_15, 26, __pyx_v_self->__pyx_base.result_status_msg);
+  __Pyx_GIVEREF(__pyx_t_10);
+  PyTuple_SET_ITEM(__pyx_t_15, 27, __pyx_t_10);
+  __Pyx_GIVEREF(__pyx_t_11);
+  PyTuple_SET_ITEM(__pyx_t_15, 28, __pyx_t_11);
+  __Pyx_INCREF(((PyObject *)__pyx_v_self->settings));
+  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->settings));
+  PyTuple_SET_ITEM(__pyx_t_15, 29, ((PyObject *)__pyx_v_self->settings));
+  __Pyx_GIVEREF(__pyx_t_12);
+  PyTuple_SET_ITEM(__pyx_t_15, 30, __pyx_t_12);
+  __Pyx_INCREF(((PyObject *)__pyx_v_self->statement));
+  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->statement));
+  PyTuple_SET_ITEM(__pyx_t_15, 31, ((PyObject *)__pyx_v_self->statement));
+  __Pyx_INCREF(__pyx_v_self->timeout_callback);
+  __Pyx_GIVEREF(__pyx_v_self->timeout_callback);
+  PyTuple_SET_ITEM(__pyx_t_15, 32, __pyx_v_self->timeout_callback);
+  __Pyx_INCREF(__pyx_v_self->timeout_handle);
+  __Pyx_GIVEREF(__pyx_v_self->timeout_handle);
+  PyTuple_SET_ITEM(__pyx_t_15, 33, __pyx_v_self->timeout_handle);
+  __Pyx_INCREF(__pyx_v_self->__pyx_base.transport);
+  __Pyx_GIVEREF(__pyx_v_self->__pyx_base.transport);
+  PyTuple_SET_ITEM(__pyx_t_15, 34, __pyx_v_self->__pyx_base.transport);
+  __Pyx_INCREF(__pyx_v_self->waiter);
+  __Pyx_GIVEREF(__pyx_v_self->waiter);
+  PyTuple_SET_ITEM(__pyx_t_15, 35, __pyx_v_self->waiter);
+  __Pyx_GIVEREF(__pyx_t_13);
+  PyTuple_SET_ITEM(__pyx_t_15, 36, __pyx_t_13);
+  __Pyx_GIVEREF(__pyx_t_14);
+  PyTuple_SET_ITEM(__pyx_t_15, 37, __pyx_t_14);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_3 = 0;
+  __pyx_t_4 = 0;
+  __pyx_t_5 = 0;
+  __pyx_t_6 = 0;
+  __pyx_t_7 = 0;
+  __pyx_t_8 = 0;
+  __pyx_t_9 = 0;
+  __pyx_t_10 = 0;
+  __pyx_t_11 = 0;
+  __pyx_t_12 = 0;
+  __pyx_t_13 = 0;
+  __pyx_t_14 = 0;
+  __pyx_v_state = ((PyObject*)__pyx_t_15);
+  __pyx_t_15 = 0;
+
+  /* "(tree fragment)":4
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.address, self.backend_pid, self.backend_secret, self.buffer, self.cancel_sent_waiter, self.cancel_waiter, self.closing, self.completed_callback, self.con_params, self.con_status, self.conref, self.create_future, self.encoding, self.is_reading, self.last_query, self.loop, self.queries_count, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.return_extra, self.settings, self.state, self.statement, self.timeout_callback, self.timeout_handle, self.transport, self.waiter, self.writing_paused, self.xact_status)
+ *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
+ *     if _dict is not None:
+ *         state += (_dict,)
+ */
+  __pyx_t_15 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_15)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_15);
+  __pyx_v__dict = __pyx_t_15;
+  __pyx_t_15 = 0;
+
+  /* "(tree fragment)":5
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.address, self.backend_pid, self.backend_secret, self.buffer, self.cancel_sent_waiter, self.cancel_waiter, self.closing, self.completed_callback, self.con_params, self.con_status, self.conref, self.create_future, self.encoding, self.is_reading, self.last_query, self.loop, self.queries_count, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.return_extra, self.settings, self.state, self.statement, self.timeout_callback, self.timeout_handle, self.transport, self.waiter, self.writing_paused, self.xact_status)
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+  __pyx_t_16 = (__pyx_v__dict != Py_None);
+  __pyx_t_17 = (__pyx_t_16 != 0);
+  if (__pyx_t_17) {
+
+    /* "(tree fragment)":6
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:
+ *         state += (_dict,)             # <<<<<<<<<<<<<<
+ *         use_setstate = True
+ *     else:
+ */
+    __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_15);
+    __Pyx_INCREF(__pyx_v__dict);
+    __Pyx_GIVEREF(__pyx_v__dict);
+    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v__dict);
+    __pyx_t_14 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(2, 6, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_14);
+    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_14));
+    __pyx_t_14 = 0;
+
+    /* "(tree fragment)":7
+ *     if _dict is not None:
+ *         state += (_dict,)
+ *         use_setstate = True             # <<<<<<<<<<<<<<
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.address is not None or self.buffer is not None or self.cancel_sent_waiter is not None or self.cancel_waiter is not None or self.completed_callback is not None or self.con_params is not None or self.conref is not None or self.create_future is not None or self.encoding is not None or self.last_query is not None or self.loop is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.settings is not None or self.statement is not None or self.timeout_callback is not None or self.timeout_handle is not None or self.transport is not None or self.waiter is not None
+ */
+    __pyx_v_use_setstate = 1;
+
+    /* "(tree fragment)":5
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.address, self.backend_pid, self.backend_secret, self.buffer, self.cancel_sent_waiter, self.cancel_waiter, self.closing, self.completed_callback, self.con_params, self.con_status, self.conref, self.create_future, self.encoding, self.is_reading, self.last_query, self.loop, self.queries_count, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.return_extra, self.settings, self.state, self.statement, self.timeout_callback, self.timeout_handle, self.transport, self.waiter, self.writing_paused, self.xact_status)
+ *     _dict = getattr(self, '__dict__', None)
+ *     if _dict is not None:             # <<<<<<<<<<<<<<
+ *         state += (_dict,)
+ *         use_setstate = True
+ */
+    goto __pyx_L3;
+  }
+
+  /* "(tree fragment)":9
+ *         use_setstate = True
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.address is not None or self.buffer is not None or self.cancel_sent_waiter is not None or self.cancel_waiter is not None or self.completed_callback is not None or self.con_params is not None or self.conref is not None or self.create_future is not None or self.encoding is not None or self.last_query is not None or self.loop is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.settings is not None or self.statement is not None or self.timeout_callback is not None or self.timeout_handle is not None or self.transport is not None or self.waiter is not None             # <<<<<<<<<<<<<<
+ *     if use_setstate:
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, None), state
+ */
+  /*else*/ {
+    __pyx_t_16 = (__pyx_v_self->__pyx_base._execute_iter != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->__pyx_base._execute_portal_name != ((PyObject*)Py_None));
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->__pyx_base._execute_stmt_name != ((PyObject*)Py_None));
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->address != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (((PyObject *)__pyx_v_self->__pyx_base.buffer) != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->cancel_sent_waiter != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->cancel_waiter != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->completed_callback != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->__pyx_base.con_params != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->conref != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->create_future != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->__pyx_base.encoding != ((PyObject*)Py_None));
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->last_query != ((PyObject*)Py_None));
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->loop != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->__pyx_base.result != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->__pyx_base.result_param_desc != ((PyObject*)Py_None));
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->__pyx_base.result_row_desc != ((PyObject*)Py_None));
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->__pyx_base.result_status_msg != ((PyObject*)Py_None));
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (((PyObject *)__pyx_v_self->settings) != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (((PyObject *)__pyx_v_self->statement) != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->timeout_callback != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->timeout_handle != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    if (!__pyx_t_16) {
+    } else {
+      __pyx_t_17 = __pyx_t_16;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_16 = (__pyx_v_self->__pyx_base.transport != Py_None);
+    __pyx_t_18 = (__pyx_t_16 != 0);
+    if (!__pyx_t_18) {
+    } else {
+      __pyx_t_17 = __pyx_t_18;
+      goto __pyx_L4_bool_binop_done;
+    }
+    __pyx_t_18 = (__pyx_v_self->waiter != Py_None);
+    __pyx_t_16 = (__pyx_t_18 != 0);
+    __pyx_t_17 = __pyx_t_16;
+    __pyx_L4_bool_binop_done:;
+    __pyx_v_use_setstate = __pyx_t_17;
+  }
+  __pyx_L3:;
+
+  /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.address is not None or self.buffer is not None or self.cancel_sent_waiter is not None or self.cancel_waiter is not None or self.completed_callback is not None or self.con_params is not None or self.conref is not None or self.create_future is not None or self.encoding is not None or self.last_query is not None or self.loop is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.settings is not None or self.statement is not None or self.timeout_callback is not None or self.timeout_handle is not None or self.transport is not None or self.waiter is not None
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, None), state
+ *     else:
+ */
+  __pyx_t_17 = (__pyx_v_use_setstate != 0);
+  if (__pyx_t_17) {
+
+    /* "(tree fragment)":11
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.address is not None or self.buffer is not None or self.cancel_sent_waiter is not None or self.cancel_waiter is not None or self.completed_callback is not None or self.con_params is not None or self.conref is not None or self.create_future is not None or self.encoding is not None or self.last_query is not None or self.loop is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.settings is not None or self.statement is not None or self.timeout_callback is not None or self.timeout_handle is not None or self.transport is not None or self.waiter is not None
+ *     if use_setstate:
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, None), state             # <<<<<<<<<<<<<<
+ *     else:
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, state)
+ */
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_pyx_unpickle_BaseProtocol); if (unlikely(!__pyx_t_14)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_14);
+    __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_15);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_81883559);
+    __Pyx_GIVEREF(__pyx_int_81883559);
+    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_81883559);
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    PyTuple_SET_ITEM(__pyx_t_15, 2, Py_None);
+    __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) __PYX_ERR(2, 11, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_13);
+    __Pyx_GIVEREF(__pyx_t_14);
+    PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_14);
+    __Pyx_GIVEREF(__pyx_t_15);
+    PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_15);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_v_state);
+    __pyx_t_14 = 0;
+    __pyx_t_15 = 0;
+    __pyx_r = __pyx_t_13;
+    __pyx_t_13 = 0;
+    goto __pyx_L0;
+
+    /* "(tree fragment)":10
+ *     else:
+ *         use_setstate = self._execute_iter is not None or self._execute_portal_name is not None or self._execute_stmt_name is not None or self.address is not None or self.buffer is not None or self.cancel_sent_waiter is not None or self.cancel_waiter is not None or self.completed_callback is not None or self.con_params is not None or self.conref is not None or self.create_future is not None or self.encoding is not None or self.last_query is not None or self.loop is not None or self.result is not None or self.result_param_desc is not None or self.result_row_desc is not None or self.result_status_msg is not None or self.settings is not None or self.statement is not None or self.timeout_callback is not None or self.timeout_handle is not None or self.transport is not None or self.waiter is not None
+ *     if use_setstate:             # <<<<<<<<<<<<<<
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, None), state
+ *     else:
+ */
+  }
+
+  /* "(tree fragment)":13
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, None), state
+ *     else:
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, state)             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_BaseProtocol__set_state(self, __pyx_state)
+ */
+  /*else*/ {
+    __Pyx_XDECREF(__pyx_r);
+    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_pyx_unpickle_BaseProtocol); if (unlikely(!__pyx_t_13)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_13);
+    __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_15);
+    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+    __Pyx_INCREF(__pyx_int_81883559);
+    __Pyx_GIVEREF(__pyx_int_81883559);
+    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_int_81883559);
+    __Pyx_INCREF(__pyx_v_state);
+    __Pyx_GIVEREF(__pyx_v_state);
+    PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_v_state);
+    __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(2, 13, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_14);
+    __Pyx_GIVEREF(__pyx_t_13);
+    PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13);
+    __Pyx_GIVEREF(__pyx_t_15);
+    PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_15);
+    __pyx_t_13 = 0;
+    __pyx_t_15 = 0;
+    __pyx_r = __pyx_t_14;
+    __pyx_t_14 = 0;
+    goto __pyx_L0;
+  }
+
+  /* "(tree fragment)":1
+ * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
+ *     cdef bint use_setstate
+ *     state = (self._discard_data, self._execute_iter, self._execute_portal_name, self._execute_stmt_name, self._skip_discard, self.address, self.backend_pid, self.backend_secret, self.buffer, self.cancel_sent_waiter, self.cancel_waiter, self.closing, self.completed_callback, self.con_params, self.con_status, self.conref, self.create_future, self.encoding, self.is_reading, self.last_query, self.loop, self.queries_count, self.result, self.result_execute_completed, self.result_param_desc, self.result_row_desc, self.result_status_msg, self.result_type, self.return_extra, self.settings, self.state, self.statement, self.timeout_callback, self.timeout_handle, self.transport, self.waiter, self.writing_paused, self.xact_status)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_10);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_XDECREF(__pyx_t_15);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_state);
+  __Pyx_XDECREF(__pyx_v__dict);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_BaseProtocol__set_state(self, __pyx_state)
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_74__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_74__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_73__setstate_cython__(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_12BaseProtocol_73__setstate_cython__(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+  /* "(tree fragment)":15
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, state)
+ * def __setstate_cython__(self, __pyx_state):
+ *     __pyx_unpickle_BaseProtocol__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
+ */
+  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error)
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_BaseProtocol__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":14
+ *     else:
+ *         return __pyx_unpickle_BaseProtocol, (type(self), 0x4e171a7, state)
+ * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_unpickle_BaseProtocol__set_state(self, __pyx_state)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.BaseProtocol.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":920
+ * 
+ * class Timer:
+ *     def __init__(self, budget):             # <<<<<<<<<<<<<<
+ *         self._budget = budget
+ *         self._started = 0
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_1__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_self = 0;
+  PyObject *__pyx_v_budget = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_budget,0};
+    PyObject* values[2] = {0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_budget)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 920, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 920, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+    }
+    __pyx_v_self = values[0];
+    __pyx_v_budget = values[1];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 920, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Timer.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Timer___init__(__pyx_self, __pyx_v_self, __pyx_v_budget);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_budget) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__init__", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":921
+ * class Timer:
+ *     def __init__(self, budget):
+ *         self._budget = budget             # <<<<<<<<<<<<<<
+ *         self._started = 0
+ * 
+ */
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_budget_2, __pyx_v_budget) < 0) __PYX_ERR(0, 921, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":922
+ *     def __init__(self, budget):
+ *         self._budget = budget
+ *         self._started = 0             # <<<<<<<<<<<<<<
+ * 
+ *     def __enter__(self):
+ */
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_started, __pyx_int_0) < 0) __PYX_ERR(0, 922, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":920
+ * 
+ * class Timer:
+ *     def __init__(self, budget):             # <<<<<<<<<<<<<<
+ *         self._budget = budget
+ *         self._started = 0
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Timer.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":924
+ *         self._started = 0
+ * 
+ *     def __enter__(self):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._started = time.monotonic()
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_3__enter__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_3__enter__ = {"__enter__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_3__enter__, METH_O, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_3__enter__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Timer_2__enter__(__pyx_self, ((PyObject *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer_2__enter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  __Pyx_RefNannySetupContext("__enter__", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":925
+ * 
+ *     def __enter__(self):
+ *         if self._budget is not None:             # <<<<<<<<<<<<<<
+ *             self._started = time.monotonic()
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_budget_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 925, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = (__pyx_t_1 != Py_None);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/protocol.pyx":926
+ *     def __enter__(self):
+ *         if self._budget is not None:
+ *             self._started = time.monotonic()             # <<<<<<<<<<<<<<
+ * 
+ *     def __exit__(self, et, e, tb):
+ */
+    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 926, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_monotonic); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 926, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_t_4 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
+      if (likely(__pyx_t_4)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+        __Pyx_INCREF(__pyx_t_4);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_5, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
+    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 926, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_started, __pyx_t_1) < 0) __PYX_ERR(0, 926, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":925
+ * 
+ *     def __enter__(self):
+ *         if self._budget is not None:             # <<<<<<<<<<<<<<
+ *             self._started = time.monotonic()
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":924
+ *         self._started = 0
+ * 
+ *     def __enter__(self):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._started = time.monotonic()
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Timer.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":928
+ *             self._started = time.monotonic()
+ * 
+ *     def __exit__(self, et, e, tb):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._budget -= time.monotonic() - self._started
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_5__exit__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_5__exit__ = {"__exit__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_5__exit__, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_5__exit__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_self = 0;
+  CYTHON_UNUSED PyObject *__pyx_v_et = 0;
+  CYTHON_UNUSED PyObject *__pyx_v_e = 0;
+  CYTHON_UNUSED PyObject *__pyx_v_tb = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_et,&__pyx_n_s_e,&__pyx_n_s_tb,0};
+    PyObject* values[4] = {0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        CYTHON_FALLTHROUGH;
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_et)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 4, 4, 1); __PYX_ERR(0, 928, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_e)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 4, 4, 2); __PYX_ERR(0, 928, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  3:
+        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tb)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 4, 4, 3); __PYX_ERR(0, 928, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 928, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+    }
+    __pyx_v_self = values[0];
+    __pyx_v_et = values[1];
+    __pyx_v_e = values[2];
+    __pyx_v_tb = values[3];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 928, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Timer.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Timer_4__exit__(__pyx_self, __pyx_v_self, __pyx_v_et, __pyx_v_e, __pyx_v_tb);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer_4__exit__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_et, CYTHON_UNUSED PyObject *__pyx_v_e, CYTHON_UNUSED PyObject *__pyx_v_tb) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  PyObject *__pyx_t_6 = NULL;
+  __Pyx_RefNannySetupContext("__exit__", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":929
+ * 
+ *     def __exit__(self, et, e, tb):
+ *         if self._budget is not None:             # <<<<<<<<<<<<<<
+ *             self._budget -= time.monotonic() - self._started
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_budget_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 929, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = (__pyx_t_1 != Py_None);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_3 = (__pyx_t_2 != 0);
+  if (__pyx_t_3) {
+
+    /* "asyncpg/protocol/protocol.pyx":930
+ *     def __exit__(self, et, e, tb):
+ *         if self._budget is not None:
+ *             self._budget -= time.monotonic() - self._started             # <<<<<<<<<<<<<<
+ * 
+ *     def get_remaining_budget(self):
+ */
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_budget_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_monotonic); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
+      }
+    }
+    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_started); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_5 = PyNumber_Subtract(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = PyNumber_InPlaceSubtract(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_budget_2, __pyx_t_6) < 0) __PYX_ERR(0, 930, __pyx_L1_error)
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":929
+ * 
+ *     def __exit__(self, et, e, tb):
+ *         if self._budget is not None:             # <<<<<<<<<<<<<<
+ *             self._budget -= time.monotonic() - self._started
+ * 
+ */
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":928
+ *             self._started = time.monotonic()
+ * 
+ *     def __exit__(self, et, e, tb):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._budget -= time.monotonic() - self._started
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Timer.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":932
+ *             self._budget -= time.monotonic() - self._started
+ * 
+ *     def get_remaining_budget(self):             # <<<<<<<<<<<<<<
+ *         return self._budget
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_7get_remaining_budget(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_7get_remaining_budget = {"get_remaining_budget", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_7get_remaining_budget, METH_O, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5Timer_7get_remaining_budget(PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_remaining_budget (wrapper)", 0);
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_5Timer_6get_remaining_budget(__pyx_self, ((PyObject *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_5Timer_6get_remaining_budget(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("get_remaining_budget", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":933
+ * 
+ *     def get_remaining_budget(self):
+ *         return self._budget             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_budget_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 933, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":932
+ *             self._budget -= time.monotonic() - self._started
+ * 
+ *     def get_remaining_budget(self):             # <<<<<<<<<<<<<<
+ *         return self._budget
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.Timer.get_remaining_budget", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/protocol/protocol.pyx":940
+ * 
+ * 
+ * def _create_record(object mapping, tuple elems):             # <<<<<<<<<<<<<<
+ *     # Exposed only for testing purposes.
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_1_create_record(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_1_create_record = {"_create_record", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_1_create_record, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_1_create_record(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_mapping = 0;
+  PyObject *__pyx_v_elems = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("_create_record (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_mapping,&__pyx_n_s_elems,0};
+    PyObject* values[2] = {0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mapping)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_elems)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("_create_record", 1, 2, 2, 1); __PYX_ERR(0, 940, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_create_record") < 0)) __PYX_ERR(0, 940, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+    }
+    __pyx_v_mapping = values[0];
+    __pyx_v_elems = ((PyObject*)values[1]);
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("_create_record", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 940, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._create_record", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_elems), (&PyTuple_Type), 1, "elems", 1))) __PYX_ERR(0, 940, __pyx_L1_error)
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol__create_record(__pyx_self, __pyx_v_mapping, __pyx_v_elems);
+
+  /* function exit code */
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol__create_record(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mapping, PyObject *__pyx_v_elems) {
+  PyObject *__pyx_v_rec = 0;
+  int32_t __pyx_v_i;
+  PyObject *__pyx_v_desc = NULL;
+  PyObject *__pyx_v_elem = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  int __pyx_t_2;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  Py_ssize_t __pyx_t_5;
+  Py_ssize_t __pyx_t_6;
+  int32_t __pyx_t_7;
+  __Pyx_RefNannySetupContext("_create_record", 0);
+
+  /* "asyncpg/protocol/protocol.pyx":947
+ *         int32_t i
+ * 
+ *     if mapping is None:             # <<<<<<<<<<<<<<
+ *         desc = record.ApgRecordDesc_New({}, ())
+ *     else:
+ */
+  __pyx_t_1 = (__pyx_v_mapping == Py_None);
+  __pyx_t_2 = (__pyx_t_1 != 0);
+  if (__pyx_t_2) {
+
+    /* "asyncpg/protocol/protocol.pyx":948
+ * 
+ *     if mapping is None:
+ *         desc = record.ApgRecordDesc_New({}, ())             # <<<<<<<<<<<<<<
+ *     else:
+ *         desc = record.ApgRecordDesc_New(
+ */
+    __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_4 = ApgRecordDesc_New(__pyx_t_3, __pyx_empty_tuple); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 948, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __pyx_v_desc = __pyx_t_4;
+    __pyx_t_4 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":947
+ *         int32_t i
+ * 
+ *     if mapping is None:             # <<<<<<<<<<<<<<
+ *         desc = record.ApgRecordDesc_New({}, ())
+ *     else:
+ */
+    goto __pyx_L3;
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":950
+ *         desc = record.ApgRecordDesc_New({}, ())
+ *     else:
+ *         desc = record.ApgRecordDesc_New(             # <<<<<<<<<<<<<<
+ *             mapping, tuple(mapping) if mapping else ())
+ * 
+ */
+  /*else*/ {
+
+    /* "asyncpg/protocol/protocol.pyx":951
+ *     else:
+ *         desc = record.ApgRecordDesc_New(
+ *             mapping, tuple(mapping) if mapping else ())             # <<<<<<<<<<<<<<
+ * 
+ *     rec = record.ApgRecord_New(desc, len(elems))
+ */
+    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_mapping); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 951, __pyx_L1_error)
+    if (__pyx_t_2) {
+      __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_v_mapping); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 951, __pyx_L1_error)
+      __Pyx_GOTREF(__pyx_t_3);
+      __pyx_t_4 = __pyx_t_3;
+      __pyx_t_3 = 0;
+    } else {
+      __Pyx_INCREF(__pyx_empty_tuple);
+      __pyx_t_4 = __pyx_empty_tuple;
+    }
+
+    /* "asyncpg/protocol/protocol.pyx":950
+ *         desc = record.ApgRecordDesc_New({}, ())
+ *     else:
+ *         desc = record.ApgRecordDesc_New(             # <<<<<<<<<<<<<<
+ *             mapping, tuple(mapping) if mapping else ())
+ * 
+ */
+    __pyx_t_3 = ApgRecordDesc_New(__pyx_v_mapping, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 950, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    __pyx_v_desc = __pyx_t_3;
+    __pyx_t_3 = 0;
+  }
+  __pyx_L3:;
+
+  /* "asyncpg/protocol/protocol.pyx":953
+ *             mapping, tuple(mapping) if mapping else ())
+ * 
+ *     rec = record.ApgRecord_New(desc, len(elems))             # <<<<<<<<<<<<<<
+ *     for i in range(len(elems)):
+ *         elem = elems[i]
+ */
+  if (unlikely(__pyx_v_elems == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(0, 953, __pyx_L1_error)
+  }
+  __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v_elems); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 953, __pyx_L1_error)
+  __pyx_t_3 = ApgRecord_New(__pyx_v_desc, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 953, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_v_rec = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":954
+ * 
+ *     rec = record.ApgRecord_New(desc, len(elems))
+ *     for i in range(len(elems)):             # <<<<<<<<<<<<<<
+ *         elem = elems[i]
+ *         cpython.Py_INCREF(elem)
+ */
+  if (unlikely(__pyx_v_elems == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(0, 954, __pyx_L1_error)
+  }
+  __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v_elems); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 954, __pyx_L1_error)
+  __pyx_t_6 = __pyx_t_5;
+  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
+    __pyx_v_i = __pyx_t_7;
+
+    /* "asyncpg/protocol/protocol.pyx":955
+ *     rec = record.ApgRecord_New(desc, len(elems))
+ *     for i in range(len(elems)):
+ *         elem = elems[i]             # <<<<<<<<<<<<<<
+ *         cpython.Py_INCREF(elem)
+ *         record.ApgRecord_SET_ITEM(rec, i, elem)
+ */
+    if (unlikely(__pyx_v_elems == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(0, 955, __pyx_L1_error)
+    }
+    __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_elems, __pyx_v_i, int32_t, 1, __Pyx_PyInt_From_int32_t, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 955, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_XDECREF_SET(__pyx_v_elem, __pyx_t_3);
+    __pyx_t_3 = 0;
+
+    /* "asyncpg/protocol/protocol.pyx":956
+ *     for i in range(len(elems)):
+ *         elem = elems[i]
+ *         cpython.Py_INCREF(elem)             # <<<<<<<<<<<<<<
+ *         record.ApgRecord_SET_ITEM(rec, i, elem)
+ *     return rec
+ */
+    Py_INCREF(__pyx_v_elem);
+
+    /* "asyncpg/protocol/protocol.pyx":957
+ *         elem = elems[i]
+ *         cpython.Py_INCREF(elem)
+ *         record.ApgRecord_SET_ITEM(rec, i, elem)             # <<<<<<<<<<<<<<
+ *     return rec
+ * 
+ */
+    ApgRecord_SET_ITEM(__pyx_v_rec, __pyx_v_i, __pyx_v_elem);
+  }
+
+  /* "asyncpg/protocol/protocol.pyx":958
+ *         cpython.Py_INCREF(elem)
+ *         record.ApgRecord_SET_ITEM(rec, i, elem)
+ *     return rec             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_rec);
+  __pyx_r = __pyx_v_rec;
+  goto __pyx_L0;
+
+  /* "asyncpg/protocol/protocol.pyx":940
+ * 
+ * 
+ * def _create_record(object mapping, tuple elems):             # <<<<<<<<<<<<<<
+ *     # Exposed only for testing purposes.
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol._create_record", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_rec);
+  __Pyx_XDECREF(__pyx_v_desc);
+  __Pyx_XDECREF(__pyx_v_elem);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x7336a95:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_3__pyx_unpickle_DataCodecConfig(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_3__pyx_unpickle_DataCodecConfig = {"__pyx_unpickle_DataCodecConfig", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_3__pyx_unpickle_DataCodecConfig, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_3__pyx_unpickle_DataCodecConfig(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v___pyx_type = 0;
+  long __pyx_v___pyx_checksum;
+  PyObject *__pyx_v___pyx_state = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__pyx_unpickle_DataCodecConfig (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_DataCodecConfig", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_DataCodecConfig", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_DataCodecConfig") < 0)) __PYX_ERR(2, 1, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v___pyx_type = values[0];
+    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error)
+    __pyx_v___pyx_state = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_DataCodecConfig", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_DataCodecConfig", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_2__pyx_unpickle_DataCodecConfig(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_2__pyx_unpickle_DataCodecConfig(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_v___pyx_PickleError = NULL;
+  PyObject *__pyx_v___pyx_result = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_DataCodecConfig", 0);
+
+  /* "(tree fragment)":2
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x7336a95:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)
+ */
+  __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x7336a95) != 0);
+  if (__pyx_t_1) {
+
+    /* "(tree fragment)":3
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x7336a95:
+ *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)
+ *     __pyx_result = DataCodecConfig.__new__(__pyx_type)
+ */
+    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_n_s_PickleError);
+    __Pyx_GIVEREF(__pyx_n_s_PickleError);
+    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
+    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_v___pyx_PickleError = __pyx_t_2;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":4
+ *     if __pyx_checksum != 0x7336a95:
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)             # <<<<<<<<<<<<<<
+ *     __pyx_result = DataCodecConfig.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ */
+    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x73, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_INCREF(__pyx_v___pyx_PickleError);
+    __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(2, 4, __pyx_L1_error)
+
+    /* "(tree fragment)":2
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x7336a95:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)
+ */
+  }
+
+  /* "(tree fragment)":5
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)
+ *     __pyx_result = DataCodecConfig.__new__(__pyx_type)             # <<<<<<<<<<<<<<
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_DataCodecConfig), __pyx_n_s_new_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v___pyx_result = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)
+ *     __pyx_result = DataCodecConfig.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  __pyx_t_1 = (__pyx_v___pyx_state != Py_None);
+  __pyx_t_6 = (__pyx_t_1 != 0);
+  if (__pyx_t_6) {
+
+    /* "(tree fragment)":7
+ *     __pyx_result = DataCodecConfig.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
+ *     return __pyx_result
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):
+ */
+    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error)
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_DataCodecConfig__set_state(((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x7336a95 = (_custom_type_codecs, _derived_type_codecs))" % __pyx_checksum)
+ *     __pyx_result = DataCodecConfig.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  }
+
+  /* "(tree fragment)":8
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ *     return __pyx_result             # <<<<<<<<<<<<<<
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v___pyx_result);
+  __pyx_r = __pyx_v___pyx_result;
+  goto __pyx_L0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x7336a95:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_DataCodecConfig", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
+  __Pyx_XDECREF(__pyx_v___pyx_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":9
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_DataCodecConfig__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  Py_ssize_t __pyx_t_3;
+  int __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_DataCodecConfig__set_state", 0);
+
+  /* "(tree fragment)":10
+ *     return __pyx_result
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]             # <<<<<<<<<<<<<<
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[2])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->_custom_type_codecs);
+  __Pyx_DECREF(__pyx_v___pyx_result->_custom_type_codecs);
+  __pyx_v___pyx_result->_custom_type_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->_derived_type_codecs);
+  __Pyx_DECREF(__pyx_v___pyx_result->_derived_type_codecs);
+  __pyx_v___pyx_result->_derived_type_codecs = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "(tree fragment)":11
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[2])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(2, 11, __pyx_L1_error)
+  }
+  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error)
+  __pyx_t_4 = ((__pyx_t_3 > 2) != 0);
+  if (__pyx_t_4) {
+  } else {
+    __pyx_t_2 = __pyx_t_4;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error)
+  __pyx_t_5 = (__pyx_t_4 != 0);
+  __pyx_t_2 = __pyx_t_5;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_2) {
+
+    /* "(tree fragment)":12
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[2])             # <<<<<<<<<<<<<<
+ */
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(__pyx_v___pyx_state == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(2, 12, __pyx_L1_error)
+    }
+    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_8 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
+      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+      if (likely(__pyx_t_8)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_7, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
+    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "(tree fragment)":11
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[2])
+ */
+  }
+
+  /* "(tree fragment)":9
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_DataCodecConfig__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __pyx_unpickle_CoreProtocol(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x197884c:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5__pyx_unpickle_CoreProtocol(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_5__pyx_unpickle_CoreProtocol = {"__pyx_unpickle_CoreProtocol", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_5__pyx_unpickle_CoreProtocol, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_5__pyx_unpickle_CoreProtocol(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v___pyx_type = 0;
+  long __pyx_v___pyx_checksum;
+  PyObject *__pyx_v___pyx_state = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__pyx_unpickle_CoreProtocol (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CoreProtocol", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CoreProtocol", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_CoreProtocol") < 0)) __PYX_ERR(2, 1, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v___pyx_type = values[0];
+    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error)
+    __pyx_v___pyx_state = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_CoreProtocol", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_CoreProtocol", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_4__pyx_unpickle_CoreProtocol(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_4__pyx_unpickle_CoreProtocol(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_v___pyx_PickleError = NULL;
+  PyObject *__pyx_v___pyx_result = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_CoreProtocol", 0);
+
+  /* "(tree fragment)":2
+ * def __pyx_unpickle_CoreProtocol(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x197884c:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)
+ */
+  __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x197884c) != 0);
+  if (__pyx_t_1) {
+
+    /* "(tree fragment)":3
+ * def __pyx_unpickle_CoreProtocol(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x197884c:
+ *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)
+ *     __pyx_result = CoreProtocol.__new__(__pyx_type)
+ */
+    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_n_s_PickleError);
+    __Pyx_GIVEREF(__pyx_n_s_PickleError);
+    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
+    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_v___pyx_PickleError = __pyx_t_2;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":4
+ *     if __pyx_checksum != 0x197884c:
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)             # <<<<<<<<<<<<<<
+ *     __pyx_result = CoreProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ */
+    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x19, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_INCREF(__pyx_v___pyx_PickleError);
+    __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(2, 4, __pyx_L1_error)
+
+    /* "(tree fragment)":2
+ * def __pyx_unpickle_CoreProtocol(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x197884c:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)
+ */
+  }
+
+  /* "(tree fragment)":5
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)
+ *     __pyx_result = CoreProtocol.__new__(__pyx_type)             # <<<<<<<<<<<<<<
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_CoreProtocol), __pyx_n_s_new_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v___pyx_result = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)
+ *     __pyx_result = CoreProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  __pyx_t_1 = (__pyx_v___pyx_state != Py_None);
+  __pyx_t_6 = (__pyx_t_1 != 0);
+  if (__pyx_t_6) {
+
+    /* "(tree fragment)":7
+ *     __pyx_result = CoreProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):
+ */
+    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error)
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_CoreProtocol__set_state(((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x197884c = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, backend_pid, backend_secret, buffer, con_params, con_status, encoding, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, state, transport, xact_status))" % __pyx_checksum)
+ *     __pyx_result = CoreProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  }
+
+  /* "(tree fragment)":8
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result             # <<<<<<<<<<<<<<
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v___pyx_result);
+  __pyx_r = __pyx_v___pyx_result;
+  goto __pyx_L0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_CoreProtocol(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x197884c:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_CoreProtocol", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
+  __Pyx_XDECREF(__pyx_v___pyx_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":9
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]
+ *     if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'):
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_CoreProtocol__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int32_t __pyx_t_3;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus __pyx_t_4;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType __pyx_t_5;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __pyx_t_6;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus __pyx_t_7;
+  Py_ssize_t __pyx_t_8;
+  int __pyx_t_9;
+  int __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_CoreProtocol__set_state", 0);
+
+  /* "(tree fragment)":10
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]             # <<<<<<<<<<<<<<
+ *     if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[20])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->_discard_data = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->_execute_iter);
+  __Pyx_DECREF(__pyx_v___pyx_result->_execute_iter);
+  __pyx_v___pyx_result->_execute_iter = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->_execute_portal_name);
+  __Pyx_DECREF(__pyx_v___pyx_result->_execute_portal_name);
+  __pyx_v___pyx_result->_execute_portal_name = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->_execute_stmt_name);
+  __Pyx_DECREF(__pyx_v___pyx_result->_execute_stmt_name);
+  __pyx_v___pyx_result->_execute_stmt_name = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->_skip_discard = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->backend_pid = __pyx_t_3;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->backend_secret = __pyx_t_3;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer))))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->buffer);
+  __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->buffer));
+  __pyx_v___pyx_result->buffer = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->con_params);
+  __Pyx_DECREF(__pyx_v___pyx_result->con_params);
+  __pyx_v___pyx_result->con_params = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 9, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->con_status = __pyx_t_4;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 10, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->encoding);
+  __Pyx_DECREF(__pyx_v___pyx_result->encoding);
+  __pyx_v___pyx_result->encoding = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 11, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->result);
+  __Pyx_DECREF(__pyx_v___pyx_result->result);
+  __pyx_v___pyx_result->result = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 12, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->result_execute_completed = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 13, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->result_param_desc);
+  __Pyx_DECREF(__pyx_v___pyx_result->result_param_desc);
+  __pyx_v___pyx_result->result_param_desc = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 14, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->result_row_desc);
+  __Pyx_DECREF(__pyx_v___pyx_result->result_row_desc);
+  __pyx_v___pyx_result->result_row_desc = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 15, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->result_status_msg);
+  __Pyx_DECREF(__pyx_v___pyx_result->result_status_msg);
+  __pyx_v___pyx_result->result_status_msg = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 16, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_5 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->result_type = __pyx_t_5;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 17, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_6 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->state = __pyx_t_6;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 18, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->transport);
+  __Pyx_DECREF(__pyx_v___pyx_result->transport);
+  __pyx_v___pyx_result->transport = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 19, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_7 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->xact_status = __pyx_t_7;
+
+  /* "(tree fragment)":11
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]
+ *     if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[20])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(2, 11, __pyx_L1_error)
+  }
+  __pyx_t_8 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error)
+  __pyx_t_9 = ((__pyx_t_8 > 20) != 0);
+  if (__pyx_t_9) {
+  } else {
+    __pyx_t_2 = __pyx_t_9;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_9 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error)
+  __pyx_t_10 = (__pyx_t_9 != 0);
+  __pyx_t_2 = __pyx_t_10;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_2) {
+
+    /* "(tree fragment)":12
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]
+ *     if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[20])             # <<<<<<<<<<<<<<
+ */
+    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_11);
+    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_update); if (unlikely(!__pyx_t_12)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_12);
+    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+    if (unlikely(__pyx_v___pyx_state == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(2, 12, __pyx_L1_error)
+    }
+    __pyx_t_11 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 20, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_11);
+    __pyx_t_13 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
+      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
+      if (likely(__pyx_t_13)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
+        __Pyx_INCREF(__pyx_t_13);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_12, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_12, __pyx_t_13, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_11);
+    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "(tree fragment)":11
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]
+ *     if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[20])
+ */
+  }
+
+  /* "(tree fragment)":9
+ *         __pyx_unpickle_CoreProtocol__set_state(<CoreProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_CoreProtocol__set_state(CoreProtocol __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.backend_pid = __pyx_state[5]; __pyx_result.backend_secret = __pyx_state[6]; __pyx_result.buffer = __pyx_state[7]; __pyx_result.con_params = __pyx_state[8]; __pyx_result.con_status = __pyx_state[9]; __pyx_result.encoding = __pyx_state[10]; __pyx_result.result = __pyx_state[11]; __pyx_result.result_execute_completed = __pyx_state[12]; __pyx_result.result_param_desc = __pyx_state[13]; __pyx_result.result_row_desc = __pyx_state[14]; __pyx_result.result_status_msg = __pyx_state[15]; __pyx_result.result_type = __pyx_state[16]; __pyx_result.state = __pyx_state[17]; __pyx_result.transport = __pyx_state[18]; __pyx_result.xact_status = __pyx_state[19]
+ *     if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_CoreProtocol__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":1
+ * def __pyx_unpickle_BaseProtocol(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x4e171a7:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_7__pyx_unpickle_BaseProtocol(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7asyncpg_8protocol_8protocol_7__pyx_unpickle_BaseProtocol = {"__pyx_unpickle_BaseProtocol", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_7__pyx_unpickle_BaseProtocol, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7asyncpg_8protocol_8protocol_7__pyx_unpickle_BaseProtocol(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v___pyx_type = 0;
+  long __pyx_v___pyx_checksum;
+  PyObject *__pyx_v___pyx_state = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__pyx_unpickle_BaseProtocol (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
+    PyObject* values[3] = {0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        CYTHON_FALLTHROUGH;
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        CYTHON_FALLTHROUGH;
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        CYTHON_FALLTHROUGH;
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        CYTHON_FALLTHROUGH;
+        case  1:
+        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseProtocol", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+        CYTHON_FALLTHROUGH;
+        case  2:
+        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseProtocol", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error)
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BaseProtocol") < 0)) __PYX_ERR(2, 1, __pyx_L3_error)
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v___pyx_type = values[0];
+    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error)
+    __pyx_v___pyx_state = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseProtocol", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error)
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_BaseProtocol", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_7asyncpg_8protocol_8protocol_6__pyx_unpickle_BaseProtocol(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_7asyncpg_8protocol_8protocol_6__pyx_unpickle_BaseProtocol(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_v___pyx_PickleError = NULL;
+  PyObject *__pyx_v___pyx_result = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_t_6;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_BaseProtocol", 0);
+
+  /* "(tree fragment)":2
+ * def __pyx_unpickle_BaseProtocol(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x4e171a7:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)
+ */
+  __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x4e171a7) != 0);
+  if (__pyx_t_1) {
+
+    /* "(tree fragment)":3
+ * def __pyx_unpickle_BaseProtocol(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x4e171a7:
+ *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)
+ *     __pyx_result = BaseProtocol.__new__(__pyx_type)
+ */
+    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_n_s_PickleError);
+    __Pyx_GIVEREF(__pyx_n_s_PickleError);
+    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
+    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_INCREF(__pyx_t_2);
+    __pyx_v___pyx_PickleError = __pyx_t_2;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":4
+ *     if __pyx_checksum != 0x4e171a7:
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)             # <<<<<<<<<<<<<<
+ *     __pyx_result = BaseProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ */
+    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x4e, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_4);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_INCREF(__pyx_v___pyx_PickleError);
+    __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL;
+    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_5)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_5);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+      }
+    }
+    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
+    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+    if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    __PYX_ERR(2, 4, __pyx_L1_error)
+
+    /* "(tree fragment)":2
+ * def __pyx_unpickle_BaseProtocol(__pyx_type, long __pyx_checksum, __pyx_state):
+ *     if __pyx_checksum != 0x4e171a7:             # <<<<<<<<<<<<<<
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)
+ */
+  }
+
+  /* "(tree fragment)":5
+ *         from pickle import PickleError as __pyx_PickleError
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)
+ *     __pyx_result = BaseProtocol.__new__(__pyx_type)             # <<<<<<<<<<<<<<
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol), __pyx_n_s_new_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_4 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
+    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_4)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+      __Pyx_INCREF(__pyx_t_4);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_2, function);
+    }
+  }
+  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type);
+  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_v___pyx_result = __pyx_t_3;
+  __pyx_t_3 = 0;
+
+  /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)
+ *     __pyx_result = BaseProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  __pyx_t_1 = (__pyx_v___pyx_state != Py_None);
+  __pyx_t_6 = (__pyx_t_1 != 0);
+  if (__pyx_t_6) {
+
+    /* "(tree fragment)":7
+ *     __pyx_result = BaseProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
+ *     return __pyx_result
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):
+ */
+    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error)
+    __pyx_t_3 = __pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_BaseProtocol__set_state(((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+    /* "(tree fragment)":6
+ *         raise __pyx_PickleError("Incompatible checksums (%s vs 0x4e171a7 = (_discard_data, _execute_iter, _execute_portal_name, _execute_stmt_name, _skip_discard, address, backend_pid, backend_secret, buffer, cancel_sent_waiter, cancel_waiter, closing, completed_callback, con_params, con_status, conref, create_future, encoding, is_reading, last_query, loop, queries_count, result, result_execute_completed, result_param_desc, result_row_desc, result_status_msg, result_type, return_extra, settings, state, statement, timeout_callback, timeout_handle, transport, waiter, writing_paused, xact_status))" % __pyx_checksum)
+ *     __pyx_result = BaseProtocol.__new__(__pyx_type)
+ *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ */
+  }
+
+  /* "(tree fragment)":8
+ *     if __pyx_state is not None:
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result             # <<<<<<<<<<<<<<
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v___pyx_result);
+  __pyx_r = __pyx_v___pyx_result;
+  goto __pyx_L0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_BaseProtocol(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x4e171a7:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_BaseProtocol", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
+  __Pyx_XDECREF(__pyx_v___pyx_result);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "(tree fragment)":9
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]
+ *     if len(__pyx_state) > 38 and hasattr(__pyx_result, '__dict__'):
+ */
+
+static PyObject *__pyx_f_7asyncpg_8protocol_8protocol___pyx_unpickle_BaseProtocol__set_state(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int32_t __pyx_t_3;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus __pyx_t_4;
+  uint64_t __pyx_t_5;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType __pyx_t_6;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __pyx_t_7;
+  enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus __pyx_t_8;
+  Py_ssize_t __pyx_t_9;
+  int __pyx_t_10;
+  int __pyx_t_11;
+  PyObject *__pyx_t_12 = NULL;
+  PyObject *__pyx_t_13 = NULL;
+  PyObject *__pyx_t_14 = NULL;
+  __Pyx_RefNannySetupContext("__pyx_unpickle_BaseProtocol__set_state", 0);
+
+  /* "(tree fragment)":10
+ *     return __pyx_result
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]             # <<<<<<<<<<<<<<
+ *     if len(__pyx_state) > 38 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[38])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base._discard_data = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base._execute_iter);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base._execute_iter);
+  __pyx_v___pyx_result->__pyx_base._execute_iter = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base._execute_portal_name);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base._execute_portal_name);
+  __pyx_v___pyx_result->__pyx_base._execute_portal_name = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base._execute_stmt_name);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base._execute_stmt_name);
+  __pyx_v___pyx_result->__pyx_base._execute_stmt_name = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base._skip_discard = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->address);
+  __Pyx_DECREF(__pyx_v___pyx_result->address);
+  __pyx_v___pyx_result->address = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.backend_pid = __pyx_t_3;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_3 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.backend_secret = __pyx_t_3;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer))))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.buffer);
+  __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->__pyx_base.buffer));
+  __pyx_v___pyx_result->__pyx_base.buffer = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 9, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->cancel_sent_waiter);
+  __Pyx_DECREF(__pyx_v___pyx_result->cancel_sent_waiter);
+  __pyx_v___pyx_result->cancel_sent_waiter = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 10, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->cancel_waiter);
+  __Pyx_DECREF(__pyx_v___pyx_result->cancel_waiter);
+  __pyx_v___pyx_result->cancel_waiter = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 11, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->closing = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 12, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->completed_callback);
+  __Pyx_DECREF(__pyx_v___pyx_result->completed_callback);
+  __pyx_v___pyx_result->completed_callback = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 13, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.con_params);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.con_params);
+  __pyx_v___pyx_result->__pyx_base.con_params = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 14, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_4 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.con_status = __pyx_t_4;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 15, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->conref);
+  __Pyx_DECREF(__pyx_v___pyx_result->conref);
+  __pyx_v___pyx_result->conref = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 16, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->create_future);
+  __Pyx_DECREF(__pyx_v___pyx_result->create_future);
+  __pyx_v___pyx_result->create_future = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 17, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.encoding);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.encoding);
+  __pyx_v___pyx_result->__pyx_base.encoding = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 18, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->is_reading = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 19, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->last_query);
+  __Pyx_DECREF(__pyx_v___pyx_result->last_query);
+  __pyx_v___pyx_result->last_query = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 20, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->loop);
+  __Pyx_DECREF(__pyx_v___pyx_result->loop);
+  __pyx_v___pyx_result->loop = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 21, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_5 = __Pyx_PyInt_As_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_5 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->queries_count = __pyx_t_5;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 22, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.result);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.result);
+  __pyx_v___pyx_result->__pyx_base.result = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 23, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.result_execute_completed = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 24, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.result_param_desc);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.result_param_desc);
+  __pyx_v___pyx_result->__pyx_base.result_param_desc = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 25, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.result_row_desc);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.result_row_desc);
+  __pyx_v___pyx_result->__pyx_base.result_row_desc = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 26, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.result_status_msg);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.result_status_msg);
+  __pyx_v___pyx_result->__pyx_base.result_status_msg = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 27, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_6 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.result_type = __pyx_t_6;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 28, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->return_extra = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 29, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7asyncpg_8protocol_8protocol_ConnectionSettings))))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->settings);
+  __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->settings));
+  __pyx_v___pyx_result->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 30, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_7 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.state = __pyx_t_7;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 31, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState))))) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->statement);
+  __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->statement));
+  __pyx_v___pyx_result->statement = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)__pyx_t_1);
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 32, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->timeout_callback);
+  __Pyx_DECREF(__pyx_v___pyx_result->timeout_callback);
+  __pyx_v___pyx_result->timeout_callback = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 33, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->timeout_handle);
+  __Pyx_DECREF(__pyx_v___pyx_result->timeout_handle);
+  __pyx_v___pyx_result->timeout_handle = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 34, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.transport);
+  __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.transport);
+  __pyx_v___pyx_result->__pyx_base.transport = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 35, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v___pyx_result->waiter);
+  __Pyx_DECREF(__pyx_v___pyx_result->waiter);
+  __pyx_v___pyx_result->waiter = __pyx_t_1;
+  __pyx_t_1 = 0;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 36, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->writing_paused = __pyx_t_2;
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+    __PYX_ERR(2, 10, __pyx_L1_error)
+  }
+  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 37, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_8 = ((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)__Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(__pyx_t_1)); if (unlikely(PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_v___pyx_result->__pyx_base.xact_status = __pyx_t_8;
+
+  /* "(tree fragment)":11
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]
+ *     if len(__pyx_state) > 38 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[38])
+ */
+  if (unlikely(__pyx_v___pyx_state == Py_None)) {
+    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+    __PYX_ERR(2, 11, __pyx_L1_error)
+  }
+  __pyx_t_9 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error)
+  __pyx_t_10 = ((__pyx_t_9 > 38) != 0);
+  if (__pyx_t_10) {
+  } else {
+    __pyx_t_2 = __pyx_t_10;
+    goto __pyx_L4_bool_binop_done;
+  }
+  __pyx_t_10 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error)
+  __pyx_t_11 = (__pyx_t_10 != 0);
+  __pyx_t_2 = __pyx_t_11;
+  __pyx_L4_bool_binop_done:;
+  if (__pyx_t_2) {
+
+    /* "(tree fragment)":12
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]
+ *     if len(__pyx_state) > 38 and hasattr(__pyx_result, '__dict__'):
+ *         __pyx_result.__dict__.update(__pyx_state[38])             # <<<<<<<<<<<<<<
+ */
+    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_12)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_12);
+    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_update); if (unlikely(!__pyx_t_13)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_13);
+    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+    if (unlikely(__pyx_v___pyx_state == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      __PYX_ERR(2, 12, __pyx_L1_error)
+    }
+    __pyx_t_12 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 38, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_12);
+    __pyx_t_14 = NULL;
+    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
+      __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
+      if (likely(__pyx_t_14)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
+        __Pyx_INCREF(__pyx_t_14);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_13, function);
+      }
+    }
+    __pyx_t_1 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_14, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12);
+    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
+    if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+    /* "(tree fragment)":11
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]
+ *     if len(__pyx_state) > 38 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
+ *         __pyx_result.__dict__.update(__pyx_state[38])
+ */
+  }
+
+  /* "(tree fragment)":9
+ *         __pyx_unpickle_BaseProtocol__set_state(<BaseProtocol> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_BaseProtocol__set_state(BaseProtocol __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._discard_data = __pyx_state[0]; __pyx_result._execute_iter = __pyx_state[1]; __pyx_result._execute_portal_name = __pyx_state[2]; __pyx_result._execute_stmt_name = __pyx_state[3]; __pyx_result._skip_discard = __pyx_state[4]; __pyx_result.address = __pyx_state[5]; __pyx_result.backend_pid = __pyx_state[6]; __pyx_result.backend_secret = __pyx_state[7]; __pyx_result.buffer = __pyx_state[8]; __pyx_result.cancel_sent_waiter = __pyx_state[9]; __pyx_result.cancel_waiter = __pyx_state[10]; __pyx_result.closing = __pyx_state[11]; __pyx_result.completed_callback = __pyx_state[12]; __pyx_result.con_params = __pyx_state[13]; __pyx_result.con_status = __pyx_state[14]; __pyx_result.conref = __pyx_state[15]; __pyx_result.create_future = __pyx_state[16]; __pyx_result.encoding = __pyx_state[17]; __pyx_result.is_reading = __pyx_state[18]; __pyx_result.last_query = __pyx_state[19]; __pyx_result.loop = __pyx_state[20]; __pyx_result.queries_count = __pyx_state[21]; __pyx_result.result = __pyx_state[22]; __pyx_result.result_execute_completed = __pyx_state[23]; __pyx_result.result_param_desc = __pyx_state[24]; __pyx_result.result_row_desc = __pyx_state[25]; __pyx_result.result_status_msg = __pyx_state[26]; __pyx_result.result_type = __pyx_state[27]; __pyx_result.return_extra = __pyx_state[28]; __pyx_result.settings = __pyx_state[29]; __pyx_result.state = __pyx_state[30]; __pyx_result.statement = __pyx_state[31]; __pyx_result.timeout_callback = __pyx_state[32]; __pyx_result.timeout_handle = __pyx_state[33]; __pyx_result.transport = __pyx_state[34]; __pyx_result.waiter = __pyx_state[35]; __pyx_result.writing_paused = __pyx_state[36]; __pyx_result.xact_status = __pyx_state[37]
+ *     if len(__pyx_state) > 38 and hasattr(__pyx_result, '__dict__'):
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_12);
+  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_14);
+  __Pyx_AddTraceback("asyncpg.protocol.protocol.__pyx_unpickle_BaseProtocol__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":14
+ *         ssize_t len
+ * 
+ *     inline ssize_t frb_get_len(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         return frb.len
+ * 
+ */
+
+static CYTHON_INLINE Py_ssize_t __pyx_f_7asyncpg_7pgproto_7pgproto_frb_get_len(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb) {
+  Py_ssize_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("frb_get_len", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":15
+ * 
+ *     inline ssize_t frb_get_len(FRBuffer *frb):
+ *         return frb.len             # <<<<<<<<<<<<<<
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):
+ */
+  __pyx_r = __pyx_v_frb->len;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":14
+ *         ssize_t len
+ * 
+ *     inline ssize_t frb_get_len(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         return frb.len
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":17
+ *         return frb.len
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):             # <<<<<<<<<<<<<<
+ *         frb.len = new_len
+ * 
+ */
+
+static CYTHON_INLINE void __pyx_f_7asyncpg_7pgproto_7pgproto_frb_set_len(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, Py_ssize_t __pyx_v_new_len) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("frb_set_len", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":18
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):
+ *         frb.len = new_len             # <<<<<<<<<<<<<<
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+ */
+  __pyx_v_frb->len = __pyx_v_new_len;
+
+  /* "asyncpg/pgproto/frb.pxd":17
+ *         return frb.len
+ * 
+ *     inline void frb_set_len(FRBuffer *frb, ssize_t new_len):             # <<<<<<<<<<<<<<
+ *         frb.len = new_len
+ * 
+ */
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "asyncpg/pgproto/frb.pxd":20
+ *         frb.len = new_len
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):             # <<<<<<<<<<<<<<
+ *         frb.buf = buf
+ *         frb.len = len
+ */
+
+static CYTHON_INLINE void __pyx_f_7asyncpg_7pgproto_7pgproto_frb_init(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, char const *__pyx_v_buf, Py_ssize_t __pyx_v_len) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("frb_init", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":21
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+ *         frb.buf = buf             # <<<<<<<<<<<<<<
+ *         frb.len = len
+ * 
+ */
+  __pyx_v_frb->buf = __pyx_v_buf;
+
+  /* "asyncpg/pgproto/frb.pxd":22
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):
+ *         frb.buf = buf
+ *         frb.len = len             # <<<<<<<<<<<<<<
+ * 
+ *     inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:
+ */
+  __pyx_v_frb->len = __pyx_v_len;
+
+  /* "asyncpg/pgproto/frb.pxd":20
+ *         frb.len = new_len
+ * 
+ *     inline void frb_init(FRBuffer *frb, const char *buf, ssize_t len):             # <<<<<<<<<<<<<<
+ *         frb.buf = buf
+ *         frb.len = len
+ */
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+}
+
+/* "asyncpg/pgproto/frb.pxd":24
+ *         frb.len = len
+ * 
+ *     inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ * 
+ */
+
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, Py_ssize_t __pyx_v_n) {
+  char const *__pyx_v_result;
+  char const *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  char const *__pyx_t_3;
+  __Pyx_RefNannySetupContext("frb_read", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":27
+ *         cdef const char *result
+ * 
+ *         if n > frb.len:             # <<<<<<<<<<<<<<
+ *             frb_check(frb, n)
+ * 
+ */
+  __pyx_t_1 = ((__pyx_v_n > __pyx_v_frb->len) != 0);
+  if (__pyx_t_1) {
+
+    /* "asyncpg/pgproto/frb.pxd":28
+ * 
+ *         if n > frb.len:
+ *             frb_check(frb, n)             # <<<<<<<<<<<<<<
+ * 
+ *         result = frb.buf
+ */
+    __pyx_t_2 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_check(__pyx_v_frb, __pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(14, 28, __pyx_L1_error)
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+    /* "asyncpg/pgproto/frb.pxd":27
+ *         cdef const char *result
+ * 
+ *         if n > frb.len:             # <<<<<<<<<<<<<<
+ *             frb_check(frb, n)
+ * 
+ */
+  }
+
+  /* "asyncpg/pgproto/frb.pxd":30
+ *             frb_check(frb, n)
+ * 
+ *         result = frb.buf             # <<<<<<<<<<<<<<
+ *         frb.buf += n
+ *         frb.len -= n
+ */
+  __pyx_t_3 = __pyx_v_frb->buf;
+  __pyx_v_result = __pyx_t_3;
+
+  /* "asyncpg/pgproto/frb.pxd":31
+ * 
+ *         result = frb.buf
+ *         frb.buf += n             # <<<<<<<<<<<<<<
+ *         frb.len -= n
+ * 
+ */
+  __pyx_v_frb->buf = (__pyx_v_frb->buf + __pyx_v_n);
+
+  /* "asyncpg/pgproto/frb.pxd":32
+ *         result = frb.buf
+ *         frb.buf += n
+ *         frb.len -= n             # <<<<<<<<<<<<<<
+ * 
+ *         return result
+ */
+  __pyx_v_frb->len = (__pyx_v_frb->len - __pyx_v_n);
+
+  /* "asyncpg/pgproto/frb.pxd":34
+ *         frb.len -= n
+ * 
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     inline const char* frb_read_all(FRBuffer *frb):
+ */
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":24
+ *         frb.len = len
+ * 
+ *     inline const char* frb_read(FRBuffer *frb, ssize_t n) except NULL:             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.frb_read", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":36
+ *         return result
+ * 
+ *     inline const char* frb_read_all(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ *         result = frb.buf
+ */
+
+static CYTHON_INLINE char const *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_read_all(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb) {
+  char const *__pyx_v_result;
+  char const *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  __Pyx_RefNannySetupContext("frb_read_all", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":38
+ *     inline const char* frb_read_all(FRBuffer *frb):
+ *         cdef const char *result
+ *         result = frb.buf             # <<<<<<<<<<<<<<
+ *         frb.buf += frb.len
+ *         frb.len = 0
+ */
+  __pyx_t_1 = __pyx_v_frb->buf;
+  __pyx_v_result = __pyx_t_1;
+
+  /* "asyncpg/pgproto/frb.pxd":39
+ *         cdef const char *result
+ *         result = frb.buf
+ *         frb.buf += frb.len             # <<<<<<<<<<<<<<
+ *         frb.len = 0
+ *         return result
+ */
+  __pyx_v_frb->buf = (__pyx_v_frb->buf + __pyx_v_frb->len);
+
+  /* "asyncpg/pgproto/frb.pxd":40
+ *         result = frb.buf
+ *         frb.buf += frb.len
+ *         frb.len = 0             # <<<<<<<<<<<<<<
+ *         return result
+ * 
+ */
+  __pyx_v_frb->len = 0;
+
+  /* "asyncpg/pgproto/frb.pxd":41
+ *         frb.buf += frb.len
+ *         frb.len = 0
+ *         return result             # <<<<<<<<<<<<<<
+ * 
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,
+ */
+  __pyx_r = __pyx_v_result;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":36
+ *         return result
+ * 
+ *     inline const char* frb_read_all(FRBuffer *frb):             # <<<<<<<<<<<<<<
+ *         cdef const char *result
+ *         result = frb.buf
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/frb.pxd":43
+ *         return result
+ * 
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,             # <<<<<<<<<<<<<<
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)
+ */
+
+static CYTHON_INLINE struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_f_7asyncpg_7pgproto_7pgproto_frb_slice_from(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_frb, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_v_source, Py_ssize_t __pyx_v_len) {
+  struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *__pyx_r;
+  __Pyx_RefNannyDeclarations
+  char const *__pyx_t_1;
+  __Pyx_RefNannySetupContext("frb_slice_from", 0);
+
+  /* "asyncpg/pgproto/frb.pxd":45
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)             # <<<<<<<<<<<<<<
+ *         frb.len = len
+ *         return frb
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_7pgproto_7pgproto_frb_read(__pyx_v_source, __pyx_v_len); if (unlikely(__pyx_t_1 == ((char const *)NULL))) __PYX_ERR(14, 45, __pyx_L1_error)
+  __pyx_v_frb->buf = __pyx_t_1;
+
+  /* "asyncpg/pgproto/frb.pxd":46
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)
+ *         frb.len = len             # <<<<<<<<<<<<<<
+ *         return frb
+ * 
+ */
+  __pyx_v_frb->len = __pyx_v_len;
+
+  /* "asyncpg/pgproto/frb.pxd":47
+ *         frb.buf = frb_read(source, len)
+ *         frb.len = len
+ *         return frb             # <<<<<<<<<<<<<<
+ * 
+ *     object frb_check(FRBuffer *frb, ssize_t n)
+ */
+  __pyx_r = __pyx_v_frb;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/frb.pxd":43
+ *         return result
+ * 
+ *     inline FRBuffer *frb_slice_from(FRBuffer *frb,             # <<<<<<<<<<<<<<
+ *                                     FRBuffer* source, ssize_t len):
+ *         frb.buf = frb_read(source, len)
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_WriteUnraisable("asyncpg.pgproto.pgproto.frb_slice_from", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":28
+ *         bint _message_mode
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_11WriteBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("len", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":29
+ * 
+ *     cdef inline len(self):
+ *         return self._length             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline _check_readonly(self)
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(15, 29, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":28
+ *         bint _message_mode
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.WriteBuffer.len", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":94
+ *         bint _current_message_ready
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_len(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("len", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":95
+ * 
+ *     cdef inline len(self):
+ *         return self._length             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline char get_message_type(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(15, 95, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":94
+ *         bint _current_message_ready
+ * 
+ *     cdef inline len(self):             # <<<<<<<<<<<<<<
+ *         return self._length
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.len", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":97
+ *         return self._length
+ * 
+ *     cdef inline char get_message_type(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_type
+ * 
+ */
+
+static CYTHON_INLINE char __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_type(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  char __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_message_type", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":98
+ * 
+ *     cdef inline char get_message_type(self):
+ *         return self._current_message_type             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline int32_t get_message_length(self):
+ */
+  __pyx_r = __pyx_v_self->_current_message_type;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":97
+ *         return self._length
+ * 
+ *     cdef inline char get_message_type(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_type
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":100
+ *         return self._current_message_type
+ * 
+ *     cdef inline int32_t get_message_length(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_len
+ * 
+ */
+
+static CYTHON_INLINE int32_t __pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_get_message_length(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  int32_t __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("get_message_length", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":101
+ * 
+ *     cdef inline int32_t get_message_length(self):
+ *         return self._current_message_len             # <<<<<<<<<<<<<<
+ * 
+ *     cdef inline read_utf8(self):
+ */
+  __pyx_r = __pyx_v_self->_current_message_len;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":100
+ *         return self._current_message_type
+ * 
+ *     cdef inline int32_t get_message_length(self):             # <<<<<<<<<<<<<<
+ *         return self._current_message_len
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "asyncpg/pgproto/buffer.pxd":103
+ *         return self._current_message_len
+ * 
+ *     cdef inline read_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self.read_cstr().decode('utf-8')
+ * 
+ */
+
+static CYTHON_INLINE PyObject *__pyx_f_7asyncpg_7pgproto_7pgproto_10ReadBuffer_read_utf8(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  __Pyx_RefNannySetupContext("read_utf8", 0);
+
+  /* "asyncpg/pgproto/buffer.pxd":104
+ * 
+ *     cdef inline read_utf8(self):
+ *         return self.read_cstr().decode('utf-8')             # <<<<<<<<<<<<<<
+ * 
+ *     cdef feed_data(self, data)
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_2 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer *)__pyx_v_self->__pyx_vtab)->read_cstr(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(15, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_decode); if (unlikely(!__pyx_t_3)) __PYX_ERR(15, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = NULL;
+  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
+    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+    if (likely(__pyx_t_2)) {
+      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+      __Pyx_INCREF(__pyx_t_2);
+      __Pyx_INCREF(function);
+      __Pyx_DECREF_SET(__pyx_t_3, function);
+    }
+  }
+  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_utf_8);
+  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+  if (unlikely(!__pyx_t_1)) __PYX_ERR(15, 104, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "asyncpg/pgproto/buffer.pxd":103
+ *         return self._current_message_len
+ * 
+ *     cdef inline read_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self.read_cstr().decode('utf-8')
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_AddTraceback("asyncpg.pgproto.pgproto.ReadBuffer.read_utf8", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = 0;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_Codec __pyx_vtable_7asyncpg_8protocol_8protocol_Codec;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_Codec(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *p;
+  PyObject *o;
+  o = (*t->tp_alloc)(t, 0);
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_8protocol_8protocol_Codec;
+  p->name = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->schema = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->kind = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->py_encoder = Py_None; Py_INCREF(Py_None);
+  p->py_decoder = Py_None; Py_INCREF(Py_None);
+  p->element_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None); Py_INCREF(Py_None);
+  p->element_type_oids = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->element_names = Py_None; Py_INCREF(Py_None);
+  p->record_desc = Py_None; Py_INCREF(Py_None);
+  p->element_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  if (unlikely(__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_1__cinit__(o, a, k) < 0)) goto bad;
+  return o;
+  bad:
+  Py_DECREF(o); o = 0;
+  return NULL;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_Codec(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->name);
+  Py_CLEAR(p->schema);
+  Py_CLEAR(p->kind);
+  Py_CLEAR(p->py_encoder);
+  Py_CLEAR(p->py_decoder);
+  Py_CLEAR(p->element_codec);
+  Py_CLEAR(p->element_type_oids);
+  Py_CLEAR(p->element_names);
+  Py_CLEAR(p->record_desc);
+  Py_CLEAR(p->element_codecs);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol_Codec(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)o;
+  if (p->py_encoder) {
+    e = (*v)(p->py_encoder, a); if (e) return e;
+  }
+  if (p->py_decoder) {
+    e = (*v)(p->py_decoder, a); if (e) return e;
+  }
+  if (p->element_codec) {
+    e = (*v)(((PyObject *)p->element_codec), a); if (e) return e;
+  }
+  if (p->element_type_oids) {
+    e = (*v)(p->element_type_oids, a); if (e) return e;
+  }
+  if (p->element_names) {
+    e = (*v)(p->element_names, a); if (e) return e;
+  }
+  if (p->record_desc) {
+    e = (*v)(p->record_desc, a); if (e) return e;
+  }
+  if (p->element_codecs) {
+    e = (*v)(p->element_codecs, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_7asyncpg_8protocol_8protocol_Codec(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)o;
+  tmp = ((PyObject*)p->py_encoder);
+  p->py_encoder = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->py_decoder);
+  p->py_decoder = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->element_codec);
+  p->element_codec = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->element_type_oids);
+  p->element_type_oids = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->element_names);
+  p->element_names = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->record_desc);
+  p->record_desc = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->element_codecs);
+  p->element_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_8protocol_8protocol_Codec[] = {
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_5__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_5Codec_7__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol_Codec = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.Codec", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_Codec, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  __pyx_pw_7asyncpg_8protocol_8protocol_5Codec_3__repr__, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol_Codec, /*tp_traverse*/
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_Codec, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_8protocol_8protocol_Codec, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol_Codec, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_DataCodecConfig __pyx_vtable_7asyncpg_8protocol_8protocol_DataCodecConfig;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_DataCodecConfig(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *p;
+  PyObject *o;
+  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
+    o = (*t->tp_alloc)(t, 0);
+  } else {
+    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
+  }
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_8protocol_8protocol_DataCodecConfig;
+  p->_derived_type_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->_custom_type_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_DataCodecConfig(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)o;
+  #if CYTHON_USE_TP_FINALIZE
+  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
+    if (PyObject_CallFinalizerFromDealloc(o)) return;
+  }
+  #endif
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->_derived_type_codecs);
+  Py_CLEAR(p->_custom_type_codecs);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol_DataCodecConfig(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)o;
+  if (p->_derived_type_codecs) {
+    e = (*v)(p->_derived_type_codecs, a); if (e) return e;
+  }
+  if (p->_custom_type_codecs) {
+    e = (*v)(p->_custom_type_codecs, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_7asyncpg_8protocol_8protocol_DataCodecConfig(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)o;
+  tmp = ((PyObject*)p->_derived_type_codecs);
+  p->_derived_type_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->_custom_type_codecs);
+  p->_custom_type_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_8protocol_8protocol_DataCodecConfig[] = {
+  {"add_types", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_3add_types, METH_O, 0},
+  {"add_python_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_5add_python_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"remove_python_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_7remove_python_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"_set_builtin_type_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_9_set_builtin_type_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"set_builtin_type_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_11set_builtin_type_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"clear_type_cache", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_13clear_type_cache, METH_NOARGS, 0},
+  {"declare_fallback_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_15declare_fallback_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_17__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_19__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.DataCodecConfig", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_DataCodecConfig, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol_DataCodecConfig, /*tp_traverse*/
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_DataCodecConfig, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_8protocol_8protocol_DataCodecConfig, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_pw_7asyncpg_8protocol_8protocol_15DataCodecConfig_1__init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol_DataCodecConfig, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_ConnectionSettings __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_ConnectionSettings(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *p;
+  PyObject *o = __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_new(t, a, k);
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext*)__pyx_vtabptr_7asyncpg_8protocol_8protocol_ConnectionSettings;
+  p->_encoding = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->_codec = Py_None; Py_INCREF(Py_None);
+  p->_settings = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->_data_codecs = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)Py_None); Py_INCREF(Py_None);
+  if (unlikely(__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_1__cinit__(o, a, k) < 0)) goto bad;
+  return o;
+  bad:
+  Py_DECREF(o); o = 0;
+  return NULL;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_ConnectionSettings(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->_encoding);
+  Py_CLEAR(p->_codec);
+  Py_CLEAR(p->_settings);
+  Py_CLEAR(p->_data_codecs);
+  #if CYTHON_USE_TYPE_SLOTS
+  if (PyType_IS_GC(Py_TYPE(o)->tp_base))
+  #endif
+  PyObject_GC_Track(o);
+  if (likely(__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext)) __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_dealloc(o); else __Pyx_call_next_tp_dealloc(o, __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_ConnectionSettings);
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol_ConnectionSettings(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)o;
+  e = ((likely(__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext)) ? ((__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_traverse) ? __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_7asyncpg_8protocol_8protocol_ConnectionSettings)); if (e) return e;
+  if (p->_codec) {
+    e = (*v)(p->_codec, a); if (e) return e;
+  }
+  if (p->_settings) {
+    e = (*v)(p->_settings, a); if (e) return e;
+  }
+  if (p->_data_codecs) {
+    e = (*v)(((PyObject *)p->_data_codecs), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_7asyncpg_8protocol_8protocol_ConnectionSettings(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)o;
+  if (likely(__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext)) { if (__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_clear) __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_7asyncpg_8protocol_8protocol_ConnectionSettings);
+  tmp = ((PyObject*)p->_codec);
+  p->_codec = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->_settings);
+  p->_settings = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->_data_codecs);
+  p->_data_codecs = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyObject *__pyx_tp_getattro_7asyncpg_8protocol_8protocol_ConnectionSettings(PyObject *o, PyObject *n) {
+  PyObject *v = __Pyx_PyObject_GenericGetAttrNoDict(o, n);
+  if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+    PyErr_Clear();
+    v = __pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_17__getattr__(o, n);
+  }
+  return v;
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_8protocol_8protocol_ConnectionSettings[] = {
+  {"get_text_codec", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_3get_text_codec, METH_NOARGS, 0},
+  {"register_data_types", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_5register_data_types, METH_O, 0},
+  {"add_python_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_7add_python_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"remove_python_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_9remove_python_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"clear_type_cache", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_11clear_type_cache, METH_NOARGS, 0},
+  {"set_builtin_type_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_13set_builtin_type_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"get_data_codec", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_15get_data_codec, METH_VARARGS|METH_KEYWORDS, 0},
+  {"__getattr__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_17__getattr__, METH_O|METH_COEXIST, 0},
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_21__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_23__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.ConnectionSettings", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_ConnectionSettings, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  __pyx_pw_7asyncpg_8protocol_8protocol_18ConnectionSettings_19__repr__, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  __pyx_tp_getattro_7asyncpg_8protocol_8protocol_ConnectionSettings, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol_ConnectionSettings, /*tp_traverse*/
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_ConnectionSettings, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_8protocol_8protocol_ConnectionSettings, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol_ConnectionSettings, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_CoreProtocol(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *p;
+  PyObject *o;
+  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
+    o = (*t->tp_alloc)(t, 0);
+  } else {
+    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
+  }
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_8protocol_8protocol_CoreProtocol;
+  p->buffer = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)Py_None); Py_INCREF(Py_None);
+  p->_execute_iter = Py_None; Py_INCREF(Py_None);
+  p->_execute_portal_name = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->_execute_stmt_name = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->encoding = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->transport = Py_None; Py_INCREF(Py_None);
+  p->con_params = Py_None; Py_INCREF(Py_None);
+  p->result = Py_None; Py_INCREF(Py_None);
+  p->result_param_desc = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->result_row_desc = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->result_status_msg = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_CoreProtocol(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)o;
+  #if CYTHON_USE_TP_FINALIZE
+  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
+    if (PyObject_CallFinalizerFromDealloc(o)) return;
+  }
+  #endif
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->buffer);
+  Py_CLEAR(p->_execute_iter);
+  Py_CLEAR(p->_execute_portal_name);
+  Py_CLEAR(p->_execute_stmt_name);
+  Py_CLEAR(p->encoding);
+  Py_CLEAR(p->transport);
+  Py_CLEAR(p->con_params);
+  Py_CLEAR(p->result);
+  Py_CLEAR(p->result_param_desc);
+  Py_CLEAR(p->result_row_desc);
+  Py_CLEAR(p->result_status_msg);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol_CoreProtocol(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)o;
+  if (p->buffer) {
+    e = (*v)(((PyObject *)p->buffer), a); if (e) return e;
+  }
+  if (p->_execute_iter) {
+    e = (*v)(p->_execute_iter, a); if (e) return e;
+  }
+  if (p->transport) {
+    e = (*v)(p->transport, a); if (e) return e;
+  }
+  if (p->con_params) {
+    e = (*v)(p->con_params, a); if (e) return e;
+  }
+  if (p->result) {
+    e = (*v)(p->result, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_7asyncpg_8protocol_8protocol_CoreProtocol(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *)o;
+  tmp = ((PyObject*)p->buffer);
+  p->buffer = ((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->_execute_iter);
+  p->_execute_iter = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->transport);
+  p->transport = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->con_params);
+  p->con_params = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->result);
+  p->result = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_12CoreProtocol_backend_pid(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_11backend_pid_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_12CoreProtocol_backend_secret(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_14backend_secret_1__get__(o);
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_8protocol_8protocol_CoreProtocol[] = {
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_3__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_5__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static struct PyGetSetDef __pyx_getsets_7asyncpg_8protocol_8protocol_CoreProtocol[] = {
+  {(char *)"backend_pid", __pyx_getprop_7asyncpg_8protocol_8protocol_12CoreProtocol_backend_pid, 0, (char *)0, 0},
+  {(char *)"backend_secret", __pyx_getprop_7asyncpg_8protocol_8protocol_12CoreProtocol_backend_secret, 0, (char *)0, 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.CoreProtocol", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_CoreProtocol, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol_CoreProtocol, /*tp_traverse*/
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_CoreProtocol, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_8protocol_8protocol_CoreProtocol, /*tp_methods*/
+  0, /*tp_members*/
+  __pyx_getsets_7asyncpg_8protocol_8protocol_CoreProtocol, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_pw_7asyncpg_8protocol_8protocol_12CoreProtocol_1__init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol_CoreProtocol, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_PreparedStatementState __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_PreparedStatementState(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *p;
+  PyObject *o;
+  o = (*t->tp_alloc)(t, 0);
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)o);
+  p->__pyx_vtab = __pyx_vtabptr_7asyncpg_8protocol_8protocol_PreparedStatementState;
+  p->name = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->query = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->row_desc = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->parameters_desc = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)Py_None); Py_INCREF(Py_None);
+  p->args_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->cols_desc = Py_None; Py_INCREF(Py_None);
+  p->rows_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  if (unlikely(__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_1__cinit__(o, a, k) < 0)) goto bad;
+  return o;
+  bad:
+  Py_DECREF(o); o = 0;
+  return NULL;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_PreparedStatementState(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->name);
+  Py_CLEAR(p->query);
+  Py_CLEAR(p->row_desc);
+  Py_CLEAR(p->parameters_desc);
+  Py_CLEAR(p->settings);
+  Py_CLEAR(p->args_codecs);
+  Py_CLEAR(p->cols_desc);
+  Py_CLEAR(p->rows_codecs);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol_PreparedStatementState(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)o;
+  if (p->row_desc) {
+    e = (*v)(p->row_desc, a); if (e) return e;
+  }
+  if (p->parameters_desc) {
+    e = (*v)(p->parameters_desc, a); if (e) return e;
+  }
+  if (p->settings) {
+    e = (*v)(((PyObject *)p->settings), a); if (e) return e;
+  }
+  if (p->args_codecs) {
+    e = (*v)(p->args_codecs, a); if (e) return e;
+  }
+  if (p->cols_desc) {
+    e = (*v)(p->cols_desc, a); if (e) return e;
+  }
+  if (p->rows_codecs) {
+    e = (*v)(p->rows_codecs, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_7asyncpg_8protocol_8protocol_PreparedStatementState(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)o;
+  tmp = ((PyObject*)p->row_desc);
+  p->row_desc = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->parameters_desc);
+  p->parameters_desc = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->settings);
+  p->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->args_codecs);
+  p->args_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->cols_desc);
+  p->cols_desc = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->rows_codecs);
+  p->rows_codecs = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_name(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_4name_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_query(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_5query_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_closed(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_6closed_1__get__(o);
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_refs(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_4refs_1__get__(o);
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_8protocol_8protocol_PreparedStatementState[] = {
+  {"_get_parameters", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_3_get_parameters, METH_NOARGS, 0},
+  {"_get_attributes", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_5_get_attributes, METH_NOARGS, 0},
+  {"_init_types", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_7_init_types, METH_NOARGS, 0},
+  {"_init_codecs", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_9_init_codecs, METH_NOARGS, 0},
+  {"attach", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_11attach, METH_NOARGS, 0},
+  {"detach", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_13detach, METH_NOARGS, 0},
+  {"mark_closed", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_15mark_closed, METH_NOARGS, 0},
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_17__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_22PreparedStatementState_19__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static struct PyGetSetDef __pyx_getsets_7asyncpg_8protocol_8protocol_PreparedStatementState[] = {
+  {(char *)"name", __pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_name, 0, (char *)0, 0},
+  {(char *)"query", __pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_query, 0, (char *)0, 0},
+  {(char *)"closed", __pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_closed, 0, (char *)0, 0},
+  {(char *)"refs", __pyx_getprop_7asyncpg_8protocol_8protocol_22PreparedStatementState_refs, 0, (char *)0, 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.PreparedStatementState", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_PreparedStatementState, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol_PreparedStatementState, /*tp_traverse*/
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_PreparedStatementState, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_8protocol_8protocol_PreparedStatementState, /*tp_methods*/
+  0, /*tp_members*/
+  __pyx_getsets_7asyncpg_8protocol_8protocol_PreparedStatementState, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol_PreparedStatementState, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+static struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_BaseProtocol __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol_BaseProtocol(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *p;
+  PyObject *o = __pyx_tp_new_7asyncpg_8protocol_8protocol_CoreProtocol(t, a, k);
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)o);
+  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_7asyncpg_8protocol_8protocol_CoreProtocol*)__pyx_vtabptr_7asyncpg_8protocol_8protocol_BaseProtocol;
+  p->loop = Py_None; Py_INCREF(Py_None);
+  p->address = Py_None; Py_INCREF(Py_None);
+  p->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)Py_None); Py_INCREF(Py_None);
+  p->cancel_sent_waiter = Py_None; Py_INCREF(Py_None);
+  p->cancel_waiter = Py_None; Py_INCREF(Py_None);
+  p->waiter = Py_None; Py_INCREF(Py_None);
+  p->create_future = Py_None; Py_INCREF(Py_None);
+  p->timeout_handle = Py_None; Py_INCREF(Py_None);
+  p->timeout_callback = Py_None; Py_INCREF(Py_None);
+  p->completed_callback = Py_None; Py_INCREF(Py_None);
+  p->conref = Py_None; Py_INCREF(Py_None);
+  p->last_query = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->statement = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_BaseProtocol(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)o;
+  #if CYTHON_USE_TP_FINALIZE
+  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
+    if (PyObject_CallFinalizerFromDealloc(o)) return;
+  }
+  #endif
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->loop);
+  Py_CLEAR(p->address);
+  Py_CLEAR(p->settings);
+  Py_CLEAR(p->cancel_sent_waiter);
+  Py_CLEAR(p->cancel_waiter);
+  Py_CLEAR(p->waiter);
+  Py_CLEAR(p->create_future);
+  Py_CLEAR(p->timeout_handle);
+  Py_CLEAR(p->timeout_callback);
+  Py_CLEAR(p->completed_callback);
+  Py_CLEAR(p->conref);
+  Py_CLEAR(p->last_query);
+  Py_CLEAR(p->statement);
+  PyObject_GC_Track(o);
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_CoreProtocol(o);
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol_BaseProtocol(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)o;
+  e = __pyx_tp_traverse_7asyncpg_8protocol_8protocol_CoreProtocol(o, v, a); if (e) return e;
+  if (p->loop) {
+    e = (*v)(p->loop, a); if (e) return e;
+  }
+  if (p->address) {
+    e = (*v)(p->address, a); if (e) return e;
+  }
+  if (p->settings) {
+    e = (*v)(((PyObject *)p->settings), a); if (e) return e;
+  }
+  if (p->cancel_sent_waiter) {
+    e = (*v)(p->cancel_sent_waiter, a); if (e) return e;
+  }
+  if (p->cancel_waiter) {
+    e = (*v)(p->cancel_waiter, a); if (e) return e;
+  }
+  if (p->waiter) {
+    e = (*v)(p->waiter, a); if (e) return e;
+  }
+  if (p->create_future) {
+    e = (*v)(p->create_future, a); if (e) return e;
+  }
+  if (p->timeout_handle) {
+    e = (*v)(p->timeout_handle, a); if (e) return e;
+  }
+  if (p->timeout_callback) {
+    e = (*v)(p->timeout_callback, a); if (e) return e;
+  }
+  if (p->completed_callback) {
+    e = (*v)(p->completed_callback, a); if (e) return e;
+  }
+  if (p->conref) {
+    e = (*v)(p->conref, a); if (e) return e;
+  }
+  if (p->statement) {
+    e = (*v)(((PyObject *)p->statement), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_7asyncpg_8protocol_8protocol_BaseProtocol(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *)o;
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_CoreProtocol(o);
+  tmp = ((PyObject*)p->loop);
+  p->loop = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->address);
+  p->address = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->settings);
+  p->settings = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->cancel_sent_waiter);
+  p->cancel_sent_waiter = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->cancel_waiter);
+  p->cancel_waiter = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->waiter);
+  p->waiter = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->create_future);
+  p->create_future = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->timeout_handle);
+  p->timeout_handle = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->timeout_callback);
+  p->timeout_callback = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->completed_callback);
+  p->completed_callback = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->conref);
+  p->conref = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->statement);
+  p->statement = ((struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyObject *__pyx_getprop_7asyncpg_8protocol_8protocol_12BaseProtocol_queries_count(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_13queries_count_1__get__(o);
+}
+
+static PyMethodDef __pyx_methods_7asyncpg_8protocol_8protocol_BaseProtocol[] = {
+  {"set_connection", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_3set_connection, METH_O, 0},
+  {"get_server_pid", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_5get_server_pid, METH_NOARGS, 0},
+  {"get_settings", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_7get_settings, METH_NOARGS, 0},
+  {"is_in_transaction", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_9is_in_transaction, METH_NOARGS, 0},
+  {"prepare", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_11prepare, METH_VARARGS|METH_KEYWORDS, 0},
+  {"bind_execute", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_14bind_execute, METH_VARARGS|METH_KEYWORDS, 0},
+  {"bind_execute_many", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_17bind_execute_many, METH_VARARGS|METH_KEYWORDS, 0},
+  {"bind", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_20bind, METH_VARARGS|METH_KEYWORDS, 0},
+  {"execute", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_23execute, METH_VARARGS|METH_KEYWORDS, 0},
+  {"query", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_26query, METH_VARARGS|METH_KEYWORDS, 0},
+  {"copy_out", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_29copy_out, METH_VARARGS|METH_KEYWORDS, 0},
+  {"copy_in", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_32copy_in, METH_VARARGS|METH_KEYWORDS, 0},
+  {"close_statement", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_35close_statement, METH_VARARGS|METH_KEYWORDS, 0},
+  {"is_closed", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_38is_closed, METH_NOARGS, 0},
+  {"is_connected", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_40is_connected, METH_NOARGS, 0},
+  {"abort", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_42abort, METH_NOARGS, 0},
+  {"close", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_44close, METH_O, 0},
+  {"_request_cancel", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_47_request_cancel, METH_NOARGS, 0},
+  {"_on_timeout", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_49_on_timeout, METH_O, 0},
+  {"_on_waiter_completed", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_51_on_waiter_completed, METH_O, 0},
+  {"_create_future_fallback", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_53_create_future_fallback, METH_NOARGS, 0},
+  {"_get_timeout", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_55_get_timeout, METH_O, 0},
+  {"_is_cancelling", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_57_is_cancelling, METH_NOARGS, 0},
+  {"_wait_for_cancellation", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_59_wait_for_cancellation, METH_NOARGS, 0},
+  {"data_received", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_62data_received, METH_O, 0},
+  {"connection_made", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_64connection_made, METH_O, 0},
+  {"connection_lost", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_66connection_lost, METH_O, 0},
+  {"pause_writing", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_68pause_writing, METH_NOARGS, 0},
+  {"resume_writing", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_70resume_writing, METH_NOARGS, 0},
+  {"__reduce_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_72__reduce_cython__, METH_NOARGS, 0},
+  {"__setstate_cython__", (PyCFunction)__pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_74__setstate_cython__, METH_O, 0},
+  {0, 0, 0, 0}
+};
+
+static struct PyGetSetDef __pyx_getsets_7asyncpg_8protocol_8protocol_BaseProtocol[] = {
+  {(char *)"queries_count", __pyx_getprop_7asyncpg_8protocol_8protocol_12BaseProtocol_queries_count, 0, (char *)0, 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.BaseProtocol", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol_BaseProtocol, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol_BaseProtocol, /*tp_traverse*/
+  __pyx_tp_clear_7asyncpg_8protocol_8protocol_BaseProtocol, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_7asyncpg_8protocol_8protocol_BaseProtocol, /*tp_methods*/
+  0, /*tp_members*/
+  __pyx_getsets_7asyncpg_8protocol_8protocol_BaseProtocol, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_pw_7asyncpg_8protocol_8protocol_12BaseProtocol_1__init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol_BaseProtocol, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_query);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_state);
+  Py_CLEAR(p->__pyx_v_stmt_name);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare *)o;
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_query) {
+    e = (*v)(p->__pyx_v_query, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_state) {
+    e = (*v)(((PyObject *)p->__pyx_v_state), a); if (e) return e;
+  }
+  if (p->__pyx_v_stmt_name) {
+    e = (*v)(p->__pyx_v_stmt_name, a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct__prepare", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_args);
+  Py_CLEAR(p->__pyx_v_args_buf);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_portal_name);
+  Py_CLEAR(p->__pyx_v_return_extra);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_state);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute *)o;
+  if (p->__pyx_v_args) {
+    e = (*v)(p->__pyx_v_args, a); if (e) return e;
+  }
+  if (p->__pyx_v_args_buf) {
+    e = (*v)(p->__pyx_v_args_buf, a); if (e) return e;
+  }
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_return_extra) {
+    e = (*v)(p->__pyx_v_return_extra, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_state) {
+    e = (*v)(((PyObject *)p->__pyx_v_state), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_1_bind_execute", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_arg_bufs);
+  Py_CLEAR(p->__pyx_v_args);
+  Py_CLEAR(p->__pyx_v_data_gen);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_genexpr);
+  Py_CLEAR(p->__pyx_v_portal_name);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_state);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many *)o;
+  if (p->__pyx_v_arg_bufs) {
+    e = (*v)(p->__pyx_v_arg_bufs, a); if (e) return e;
+  }
+  if (p->__pyx_v_args) {
+    e = (*v)(p->__pyx_v_args, a); if (e) return e;
+  }
+  if (p->__pyx_v_data_gen) {
+    e = (*v)(p->__pyx_v_data_gen, a); if (e) return e;
+  }
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_genexpr) {
+    e = (*v)(p->__pyx_v_genexpr, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_state) {
+    e = (*v)(((PyObject *)p->__pyx_v_state), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_2_bind_execute_many", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_outer_scope);
+  Py_CLEAR(p->__pyx_v_b);
+  Py_CLEAR(p->__pyx_t_0);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr *)o;
+  if (p->__pyx_outer_scope) {
+    e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e;
+  }
+  if (p->__pyx_v_b) {
+    e = (*v)(p->__pyx_v_b, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_3_genexpr", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_args);
+  Py_CLEAR(p->__pyx_v_args_buf);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_portal_name);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_state);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind *)o;
+  if (p->__pyx_v_args) {
+    e = (*v)(p->__pyx_v_args, a); if (e) return e;
+  }
+  if (p->__pyx_v_args_buf) {
+    e = (*v)(p->__pyx_v_args_buf, a); if (e) return e;
+  }
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_state) {
+    e = (*v)(((PyObject *)p->__pyx_v_state), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_4_bind", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_portal_name);
+  Py_CLEAR(p->__pyx_v_return_extra);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_state);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute *)o;
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_return_extra) {
+    e = (*v)(p->__pyx_v_return_extra, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_state) {
+    e = (*v)(((PyObject *)p->__pyx_v_state), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_5_execute", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_query);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query *)o;
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_query) {
+    e = (*v)(p->__pyx_v_query, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_6_query", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_buffer);
+  Py_CLEAR(p->__pyx_v_copy_stmt);
+  Py_CLEAR(p->__pyx_v_done);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_sink);
+  Py_CLEAR(p->__pyx_v_status_msg);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_timer);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  Py_CLEAR(p->__pyx_t_6);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out *)o;
+  if (p->__pyx_v_buffer) {
+    e = (*v)(p->__pyx_v_buffer, a); if (e) return e;
+  }
+  if (p->__pyx_v_copy_stmt) {
+    e = (*v)(p->__pyx_v_copy_stmt, a); if (e) return e;
+  }
+  if (p->__pyx_v_done) {
+    e = (*v)(p->__pyx_v_done, a); if (e) return e;
+  }
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_sink) {
+    e = (*v)(p->__pyx_v_sink, a); if (e) return e;
+  }
+  if (p->__pyx_v_status_msg) {
+    e = (*v)(p->__pyx_v_status_msg, a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_timer) {
+    e = (*v)(p->__pyx_v_timer, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  if (p->__pyx_t_6) {
+    e = (*v)(p->__pyx_t_6, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_7_copy_out", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_aiter);
+  Py_CLEAR(p->__pyx_v_chunk);
+  Py_CLEAR(p->__pyx_v_codec);
+  Py_CLEAR(p->__pyx_v_codecs);
+  Py_CLEAR(p->__pyx_v_copy_stmt);
+  Py_CLEAR(p->__pyx_v_data);
+  Py_CLEAR(p->__pyx_v_e);
+  Py_CLEAR(p->__pyx_v_item);
+  Py_CLEAR(p->__pyx_v_iterator);
+  Py_CLEAR(p->__pyx_v_reader);
+  Py_CLEAR(p->__pyx_v_record_stmt);
+  Py_CLEAR(p->__pyx_v_records);
+  Py_CLEAR(p->__pyx_v_row);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_settings);
+  Py_CLEAR(p->__pyx_v_status_msg);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_timer);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_v_wbuf);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_6);
+  Py_CLEAR(p->__pyx_t_7);
+  Py_CLEAR(p->__pyx_t_8);
+  Py_CLEAR(p->__pyx_t_9);
+  Py_CLEAR(p->__pyx_t_10);
+  Py_CLEAR(p->__pyx_t_11);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in *)o;
+  if (p->__pyx_v_aiter) {
+    e = (*v)(p->__pyx_v_aiter, a); if (e) return e;
+  }
+  if (p->__pyx_v_chunk) {
+    e = (*v)(p->__pyx_v_chunk, a); if (e) return e;
+  }
+  if (p->__pyx_v_codec) {
+    e = (*v)(((PyObject *)p->__pyx_v_codec), a); if (e) return e;
+  }
+  if (p->__pyx_v_codecs) {
+    e = (*v)(p->__pyx_v_codecs, a); if (e) return e;
+  }
+  if (p->__pyx_v_copy_stmt) {
+    e = (*v)(p->__pyx_v_copy_stmt, a); if (e) return e;
+  }
+  if (p->__pyx_v_data) {
+    e = (*v)(p->__pyx_v_data, a); if (e) return e;
+  }
+  if (p->__pyx_v_e) {
+    e = (*v)(p->__pyx_v_e, a); if (e) return e;
+  }
+  if (p->__pyx_v_item) {
+    e = (*v)(p->__pyx_v_item, a); if (e) return e;
+  }
+  if (p->__pyx_v_iterator) {
+    e = (*v)(p->__pyx_v_iterator, a); if (e) return e;
+  }
+  if (p->__pyx_v_reader) {
+    e = (*v)(p->__pyx_v_reader, a); if (e) return e;
+  }
+  if (p->__pyx_v_record_stmt) {
+    e = (*v)(((PyObject *)p->__pyx_v_record_stmt), a); if (e) return e;
+  }
+  if (p->__pyx_v_records) {
+    e = (*v)(p->__pyx_v_records, a); if (e) return e;
+  }
+  if (p->__pyx_v_row) {
+    e = (*v)(p->__pyx_v_row, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_settings) {
+    e = (*v)(((PyObject *)p->__pyx_v_settings), a); if (e) return e;
+  }
+  if (p->__pyx_v_status_msg) {
+    e = (*v)(p->__pyx_v_status_msg, a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_timer) {
+    e = (*v)(p->__pyx_v_timer, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_v_wbuf) {
+    e = (*v)(((PyObject *)p->__pyx_v_wbuf), a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_6) {
+    e = (*v)(p->__pyx_t_6, a); if (e) return e;
+  }
+  if (p->__pyx_t_7) {
+    e = (*v)(p->__pyx_t_7, a); if (e) return e;
+  }
+  if (p->__pyx_t_8) {
+    e = (*v)(p->__pyx_t_8, a); if (e) return e;
+  }
+  if (p->__pyx_t_9) {
+    e = (*v)(p->__pyx_t_9, a); if (e) return e;
+  }
+  if (p->__pyx_t_10) {
+    e = (*v)(p->__pyx_t_10, a); if (e) return e;
+  }
+  if (p->__pyx_t_11) {
+    e = (*v)(p->__pyx_t_11, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_8_copy_in", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_ex);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_state);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_v_waiter);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  Py_CLEAR(p->__pyx_t_3);
+  Py_CLEAR(p->__pyx_t_4);
+  Py_CLEAR(p->__pyx_t_5);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement *)o;
+  if (p->__pyx_v_ex) {
+    e = (*v)(p->__pyx_v_ex, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_state) {
+    e = (*v)(((PyObject *)p->__pyx_v_state), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_v_waiter) {
+    e = (*v)(p->__pyx_v_waiter, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  if (p->__pyx_t_3) {
+    e = (*v)(p->__pyx_t_3, a); if (e) return e;
+  }
+  if (p->__pyx_t_4) {
+    e = (*v)(p->__pyx_t_4, a); if (e) return e;
+  }
+  if (p->__pyx_t_5) {
+    e = (*v)(p->__pyx_t_5, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_9_close_statement", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_self);
+  Py_CLEAR(p->__pyx_v_timeout);
+  Py_CLEAR(p->__pyx_t_0);
+  Py_CLEAR(p->__pyx_t_1);
+  Py_CLEAR(p->__pyx_t_2);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close *)o;
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  if (p->__pyx_v_timeout) {
+    e = (*v)(p->__pyx_v_timeout, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  if (p->__pyx_t_1) {
+    e = (*v)(p->__pyx_t_1, a); if (e) return e;
+  }
+  if (p->__pyx_t_2) {
+    e = (*v)(p->__pyx_t_2, a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_10_close", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation[8];
+static int __pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation = 0;
+
+static PyObject *__pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation)))) {
+    o = (PyObject*)__pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation[--__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation];
+    memset(o, 0, sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation(PyObject *o) {
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_self);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation)))) {
+    __pyx_freelist_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation[__pyx_freecount_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation++] = ((struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *p = (struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation *)o;
+  if (p->__pyx_v_self) {
+    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
+  }
+  return 0;
+}
+
+static PyTypeObject __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "asyncpg.protocol.protocol.__pyx_scope_struct_11__wait_for_cancellation", /*tp_name*/
+  sizeof(struct __pyx_obj_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation, /*tp_traverse*/
+  0, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+  {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+#if CYTHON_PEP489_MULTI_PHASE_INIT
+static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
+static int __pyx_pymod_exec_protocol(PyObject* module); /*proto*/
+static PyModuleDef_Slot __pyx_moduledef_slots[] = {
+  {Py_mod_create, (void*)__pyx_pymod_create},
+  {Py_mod_exec, (void*)__pyx_pymod_exec_protocol},
+  {0, NULL}
+};
+#endif
+
+static struct PyModuleDef __pyx_moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "protocol",
+    0, /* m_doc */
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+    0, /* m_size */
+  #else
+    -1, /* m_size */
+  #endif
+    __pyx_methods /* m_methods */,
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+    __pyx_moduledef_slots, /* m_slots */
+  #else
+    NULL, /* m_reload */
+  #endif
+    NULL, /* m_traverse */
+    NULL, /* m_clear */
+    NULL /* m_free */
+};
+#endif
+#ifndef CYTHON_SMALL_CODE
+#if defined(__clang__)
+    #define CYTHON_SMALL_CODE
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+    #define CYTHON_SMALL_CODE __attribute__((cold))
+#else
+    #define CYTHON_SMALL_CODE
+#endif
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+  {&__pyx_n_s_AF_UNIX, __pyx_k_AF_UNIX, sizeof(__pyx_k_AF_UNIX), 0, 0, 1, 1},
+  {&__pyx_n_u_AF_UNIX, __pyx_k_AF_UNIX, sizeof(__pyx_k_AF_UNIX), 0, 1, 0, 1},
+  {&__pyx_n_s_ARRAY_TYPES, __pyx_k_ARRAY_TYPES, sizeof(__pyx_k_ARRAY_TYPES), 0, 0, 1, 1},
+  {&__pyx_n_s_AUTH_METHOD_NAME, __pyx_k_AUTH_METHOD_NAME, sizeof(__pyx_k_AUTH_METHOD_NAME), 0, 0, 1, 1},
+  {&__pyx_n_s_AssertionError, __pyx_k_AssertionError, sizeof(__pyx_k_AssertionError), 0, 0, 1, 1},
+  {&__pyx_n_s_Attribute, __pyx_k_Attribute, sizeof(__pyx_k_Attribute), 0, 0, 1, 1},
+  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
+  {&__pyx_n_s_BUILTIN_TYPE_NAME_MAP, __pyx_k_BUILTIN_TYPE_NAME_MAP, sizeof(__pyx_k_BUILTIN_TYPE_NAME_MAP), 0, 0, 1, 1},
+  {&__pyx_n_s_BUILTIN_TYPE_OID_MAP, __pyx_k_BUILTIN_TYPE_OID_MAP, sizeof(__pyx_k_BUILTIN_TYPE_OID_MAP), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol, __pyx_k_BaseProtocol, sizeof(__pyx_k_BaseProtocol), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol__wait_for_cancellat, __pyx_k_BaseProtocol__wait_for_cancellat, sizeof(__pyx_k_BaseProtocol__wait_for_cancellat), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_bind, __pyx_k_BaseProtocol_bind, sizeof(__pyx_k_BaseProtocol_bind), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_bind_execute, __pyx_k_BaseProtocol_bind_execute, sizeof(__pyx_k_BaseProtocol_bind_execute), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_bind_execute_many, __pyx_k_BaseProtocol_bind_execute_many, sizeof(__pyx_k_BaseProtocol_bind_execute_many), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_close, __pyx_k_BaseProtocol_close, sizeof(__pyx_k_BaseProtocol_close), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_close_statement, __pyx_k_BaseProtocol_close_statement, sizeof(__pyx_k_BaseProtocol_close_statement), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_copy_in, __pyx_k_BaseProtocol_copy_in, sizeof(__pyx_k_BaseProtocol_copy_in), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_copy_out, __pyx_k_BaseProtocol_copy_out, sizeof(__pyx_k_BaseProtocol_copy_out), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_execute, __pyx_k_BaseProtocol_execute, sizeof(__pyx_k_BaseProtocol_execute), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_prepare, __pyx_k_BaseProtocol_prepare, sizeof(__pyx_k_BaseProtocol_prepare), 0, 0, 1, 1},
+  {&__pyx_n_s_BaseProtocol_query, __pyx_k_BaseProtocol_query, sizeof(__pyx_k_BaseProtocol_query), 0, 0, 1, 1},
+  {&__pyx_n_s_BufferError, __pyx_k_BufferError, sizeof(__pyx_k_BufferError), 0, 0, 1, 1},
+  {&__pyx_kp_u_Check_the_query_against_the_pass, __pyx_k_Check_the_query_against_the_pass, sizeof(__pyx_k_Check_the_query_against_the_pass), 0, 1, 0, 0},
+  {&__pyx_n_s_Codec, __pyx_k_Codec, sizeof(__pyx_k_Codec), 0, 0, 1, 1},
+  {&__pyx_kp_u_Codec_oid_elem_oid_core, __pyx_k_Codec_oid_elem_oid_core, sizeof(__pyx_k_Codec_oid_elem_oid_core), 0, 1, 0, 0},
+  {&__pyx_n_s_ConnectionDoesNotExistError, __pyx_k_ConnectionDoesNotExistError, sizeof(__pyx_k_ConnectionDoesNotExistError), 0, 0, 1, 1},
+  {&__pyx_n_s_ConnectionResetError, __pyx_k_ConnectionResetError, sizeof(__pyx_k_ConnectionResetError), 0, 0, 1, 1},
+  {&__pyx_n_s_ConnectionSettings, __pyx_k_ConnectionSettings, sizeof(__pyx_k_ConnectionSettings), 0, 0, 1, 1},
+  {&__pyx_kp_u_ConnectionSettings_r, __pyx_k_ConnectionSettings_r, sizeof(__pyx_k_ConnectionSettings_r), 0, 1, 0, 0},
+  {&__pyx_n_s_CoreProtocol, __pyx_k_CoreProtocol, sizeof(__pyx_k_CoreProtocol), 0, 0, 1, 1},
+  {&__pyx_n_s_DataCodecConfig, __pyx_k_DataCodecConfig, sizeof(__pyx_k_DataCodecConfig), 0, 0, 1, 1},
+  {&__pyx_n_s_DataError, __pyx_k_DataError, sizeof(__pyx_k_DataError), 0, 0, 1, 1},
+  {&__pyx_n_s_Event, __pyx_k_Event, sizeof(__pyx_k_Event), 0, 0, 1, 1},
+  {&__pyx_n_s_Future, __pyx_k_Future, sizeof(__pyx_k_Future), 0, 0, 1, 1},
+  {&__pyx_n_s_IPPROTO_TCP, __pyx_k_IPPROTO_TCP, sizeof(__pyx_k_IPPROTO_TCP), 0, 0, 1, 1},
+  {&__pyx_kp_s_Incompatible_checksums_s_vs_0x19, __pyx_k_Incompatible_checksums_s_vs_0x19, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x19), 0, 0, 1, 0},
+  {&__pyx_kp_s_Incompatible_checksums_s_vs_0x4e, __pyx_k_Incompatible_checksums_s_vs_0x4e, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x4e), 0, 0, 1, 0},
+  {&__pyx_kp_s_Incompatible_checksums_s_vs_0x73, __pyx_k_Incompatible_checksums_s_vs_0x73, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x73), 0, 0, 1, 0},
+  {&__pyx_n_s_InterfaceError, __pyx_k_InterfaceError, sizeof(__pyx_k_InterfaceError), 0, 0, 1, 1},
+  {&__pyx_n_s_InternalClientError, __pyx_k_InternalClientError, sizeof(__pyx_k_InternalClientError), 0, 0, 1, 1},
+  {&__pyx_n_s_Iterable, __pyx_k_Iterable, sizeof(__pyx_k_Iterable), 0, 0, 1, 1},
+  {&__pyx_n_s_IterableABC, __pyx_k_IterableABC, sizeof(__pyx_k_IterableABC), 0, 0, 1, 1},
+  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
+  {&__pyx_n_s_Mapping, __pyx_k_Mapping, sizeof(__pyx_k_Mapping), 0, 0, 1, 1},
+  {&__pyx_n_s_MappingABC, __pyx_k_MappingABC, sizeof(__pyx_k_MappingABC), 0, 0, 1, 1},
+  {&__pyx_n_u_NA, __pyx_k_NA, sizeof(__pyx_k_NA), 0, 1, 0, 1},
+  {&__pyx_n_s_NO_TIMEOUT, __pyx_k_NO_TIMEOUT, sizeof(__pyx_k_NO_TIMEOUT), 0, 0, 1, 1},
+  {&__pyx_n_b_NULL, __pyx_k_NULL, sizeof(__pyx_k_NULL), 0, 0, 0, 1},
+  {&__pyx_kp_b_NULL_2, __pyx_k_NULL_2, sizeof(__pyx_k_NULL_2), 0, 0, 0, 0},
+  {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
+  {&__pyx_kp_u_Note_that_parameters_are_suppor, __pyx_k_Note_that_parameters_are_suppor, sizeof(__pyx_k_Note_that_parameters_are_suppor), 0, 1, 0, 0},
+  {&__pyx_kp_u_OID_value_too_large_r, __pyx_k_OID_value_too_large_r, sizeof(__pyx_k_OID_value_too_large_r), 0, 1, 0, 0},
+  {&__pyx_n_s_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1},
+  {&__pyx_n_s_OutdatedSchemaCacheError, __pyx_k_OutdatedSchemaCacheError, sizeof(__pyx_k_OutdatedSchemaCacheError), 0, 0, 1, 1},
+  {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1},
+  {&__pyx_kp_b_PGCOPY, __pyx_k_PGCOPY, sizeof(__pyx_k_PGCOPY), 0, 0, 0, 0},
+  {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
+  {&__pyx_n_s_PostgresError, __pyx_k_PostgresError, sizeof(__pyx_k_PostgresError), 0, 0, 1, 1},
+  {&__pyx_n_s_PreparedStatementState, __pyx_k_PreparedStatementState, sizeof(__pyx_k_PreparedStatementState), 0, 0, 1, 1},
+  {&__pyx_n_s_Protocol, __pyx_k_Protocol, sizeof(__pyx_k_Protocol), 0, 0, 1, 1},
+  {&__pyx_n_s_ProtocolError, __pyx_k_ProtocolError, sizeof(__pyx_k_ProtocolError), 0, 0, 1, 1},
+  {&__pyx_n_s_Range, __pyx_k_Range, sizeof(__pyx_k_Range), 0, 0, 1, 1},
+  {&__pyx_n_s_Record, __pyx_k_Record, sizeof(__pyx_k_Record), 0, 0, 1, 1},
+  {&__pyx_n_s_Sized, __pyx_k_Sized, sizeof(__pyx_k_Sized), 0, 0, 1, 1},
+  {&__pyx_n_s_SizedABC, __pyx_k_SizedABC, sizeof(__pyx_k_SizedABC), 0, 0, 1, 1},
+  {&__pyx_n_s_StopAsyncIteration, __pyx_k_StopAsyncIteration, sizeof(__pyx_k_StopAsyncIteration), 0, 0, 1, 1},
+  {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1},
+  {&__pyx_n_s_TCP_NODELAY, __pyx_k_TCP_NODELAY, sizeof(__pyx_k_TCP_NODELAY), 0, 0, 1, 1},
+  {&__pyx_n_s_TimeoutError, __pyx_k_TimeoutError, sizeof(__pyx_k_TimeoutError), 0, 0, 1, 1},
+  {&__pyx_n_u_TimeoutError, __pyx_k_TimeoutError, sizeof(__pyx_k_TimeoutError), 0, 1, 0, 1},
+  {&__pyx_n_s_Timer, __pyx_k_Timer, sizeof(__pyx_k_Timer), 0, 0, 1, 1},
+  {&__pyx_n_s_Timer___enter, __pyx_k_Timer___enter, sizeof(__pyx_k_Timer___enter), 0, 0, 1, 1},
+  {&__pyx_n_s_Timer___exit, __pyx_k_Timer___exit, sizeof(__pyx_k_Timer___exit), 0, 0, 1, 1},
+  {&__pyx_n_s_Timer___init, __pyx_k_Timer___init, sizeof(__pyx_k_Timer___init), 0, 0, 1, 1},
+  {&__pyx_n_s_Timer_get_remaining_budget, __pyx_k_Timer_get_remaining_budget, sizeof(__pyx_k_Timer_get_remaining_budget), 0, 0, 1, 1},
+  {&__pyx_kp_u_TimoutError_was_not_raised, __pyx_k_TimoutError_was_not_raised, sizeof(__pyx_k_TimoutError_was_not_raised), 0, 1, 0, 0},
+  {&__pyx_n_s_Type, __pyx_k_Type, sizeof(__pyx_k_Type), 0, 0, 1, 1},
+  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
+  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
+  {&__pyx_kp_b__18, __pyx_k__18, sizeof(__pyx_k__18), 0, 0, 0, 0},
+  {&__pyx_n_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 1},
+  {&__pyx_kp_u__24, __pyx_k__24, sizeof(__pyx_k__24), 0, 1, 0, 0},
+  {&__pyx_kp_b__25, __pyx_k__25, sizeof(__pyx_k__25), 0, 0, 0, 0},
+  {&__pyx_kp_u__25, __pyx_k__25, sizeof(__pyx_k__25), 0, 1, 0, 0},
+  {&__pyx_kp_u__26, __pyx_k__26, sizeof(__pyx_k__26), 0, 1, 0, 0},
+  {&__pyx_kp_u__28, __pyx_k__28, sizeof(__pyx_k__28), 0, 1, 0, 0},
+  {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0},
+  {&__pyx_kp_u_a_sized_iterable_container_expec, __pyx_k_a_sized_iterable_container_expec, sizeof(__pyx_k_a_sized_iterable_container_expec), 0, 1, 0, 0},
+  {&__pyx_n_u_abc, __pyx_k_abc, sizeof(__pyx_k_abc), 0, 1, 0, 1},
+  {&__pyx_n_s_abort, __pyx_k_abort, sizeof(__pyx_k_abort), 0, 0, 1, 1},
+  {&__pyx_n_u_abstime, __pyx_k_abstime, sizeof(__pyx_k_abstime), 0, 1, 0, 1},
+  {&__pyx_n_u_aclitem, __pyx_k_aclitem, sizeof(__pyx_k_aclitem), 0, 1, 0, 1},
+  {&__pyx_n_s_add_done_callback, __pyx_k_add_done_callback, sizeof(__pyx_k_add_done_callback), 0, 0, 1, 1},
+  {&__pyx_n_s_add_python_codec, __pyx_k_add_python_codec, sizeof(__pyx_k_add_python_codec), 0, 0, 1, 1},
+  {&__pyx_n_s_add_types, __pyx_k_add_types, sizeof(__pyx_k_add_types), 0, 0, 1, 1},
+  {&__pyx_n_s_addr, __pyx_k_addr, sizeof(__pyx_k_addr), 0, 0, 1, 1},
+  {&__pyx_n_s_aiter, __pyx_k_aiter, sizeof(__pyx_k_aiter), 0, 0, 1, 1},
+  {&__pyx_n_s_alias_to, __pyx_k_alias_to, sizeof(__pyx_k_alias_to), 0, 0, 1, 1},
+  {&__pyx_kp_u_already_connected, __pyx_k_already_connected, sizeof(__pyx_k_already_connected), 0, 1, 0, 0},
+  {&__pyx_n_u_alt, __pyx_k_alt, sizeof(__pyx_k_alt), 0, 1, 0, 1},
+  {&__pyx_n_s_anext, __pyx_k_anext, sizeof(__pyx_k_anext), 0, 0, 1, 1},
+  {&__pyx_n_u_any, __pyx_k_any, sizeof(__pyx_k_any), 0, 1, 0, 1},
+  {&__pyx_n_u_anyarray, __pyx_k_anyarray, sizeof(__pyx_k_anyarray), 0, 1, 0, 1},
+  {&__pyx_n_u_anyelement, __pyx_k_anyelement, sizeof(__pyx_k_anyelement), 0, 1, 0, 1},
+  {&__pyx_n_u_anyenum, __pyx_k_anyenum, sizeof(__pyx_k_anyenum), 0, 1, 0, 1},
+  {&__pyx_n_u_anynonarray, __pyx_k_anynonarray, sizeof(__pyx_k_anynonarray), 0, 1, 0, 1},
+  {&__pyx_n_u_anyrange, __pyx_k_anyrange, sizeof(__pyx_k_anyrange), 0, 1, 0, 1},
+  {&__pyx_n_s_apg_exc, __pyx_k_apg_exc, sizeof(__pyx_k_apg_exc), 0, 0, 1, 1},
+  {&__pyx_n_s_apg_exc_base, __pyx_k_apg_exc_base, sizeof(__pyx_k_apg_exc_base), 0, 0, 1, 1},
+  {&__pyx_n_s_apg_types, __pyx_k_apg_types, sizeof(__pyx_k_apg_types), 0, 0, 1, 1},
+  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
+  {&__pyx_n_u_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 1, 0, 1},
+  {&__pyx_n_u_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 1, 0, 1},
+  {&__pyx_n_s_asyncio, __pyx_k_asyncio, sizeof(__pyx_k_asyncio), 0, 0, 1, 1},
+  {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1},
+  {&__pyx_n_s_asyncio_tasks, __pyx_k_asyncio_tasks, sizeof(__pyx_k_asyncio_tasks), 0, 0, 1, 1},
+  {&__pyx_n_s_asyncpg, __pyx_k_asyncpg, sizeof(__pyx_k_asyncpg), 0, 0, 1, 1},
+  {&__pyx_kp_u_asyncpg_Protocol_has_no_referenc, __pyx_k_asyncpg_Protocol_has_no_referenc, sizeof(__pyx_k_asyncpg_Protocol_has_no_referenc), 0, 1, 0, 0},
+  {&__pyx_n_s_asyncpg_exceptions, __pyx_k_asyncpg_exceptions, sizeof(__pyx_k_asyncpg_exceptions), 0, 0, 1, 1},
+  {&__pyx_n_s_asyncpg_protocol_protocol, __pyx_k_asyncpg_protocol_protocol, sizeof(__pyx_k_asyncpg_protocol_protocol), 0, 0, 1, 1},
+  {&__pyx_kp_s_asyncpg_protocol_protocol_pyx, __pyx_k_asyncpg_protocol_protocol_pyx, sizeof(__pyx_k_asyncpg_protocol_protocol_pyx), 0, 0, 1, 0},
+  {&__pyx_n_u_attrnames, __pyx_k_attrnames, sizeof(__pyx_k_attrnames), 0, 1, 0, 1},
+  {&__pyx_n_u_attrtypoids, __pyx_k_attrtypoids, sizeof(__pyx_k_attrtypoids), 0, 1, 0, 1},
+  {&__pyx_n_s_auth_msg, __pyx_k_auth_msg, sizeof(__pyx_k_auth_msg), 0, 0, 1, 1},
+  {&__pyx_n_s_await, __pyx_k_await, sizeof(__pyx_k_await), 0, 0, 1, 1},
+  {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1},
+  {&__pyx_n_u_basetype, __pyx_k_basetype, sizeof(__pyx_k_basetype), 0, 1, 0, 1},
+  {&__pyx_n_u_bigint, __pyx_k_bigint, sizeof(__pyx_k_bigint), 0, 1, 0, 1},
+  {&__pyx_n_u_binary, __pyx_k_binary, sizeof(__pyx_k_binary), 0, 1, 0, 1},
+  {&__pyx_n_s_bind, __pyx_k_bind, sizeof(__pyx_k_bind), 0, 0, 1, 1},
+  {&__pyx_n_s_bind_execute, __pyx_k_bind_execute, sizeof(__pyx_k_bind_execute), 0, 0, 1, 1},
+  {&__pyx_n_s_bind_execute_many, __pyx_k_bind_execute_many, sizeof(__pyx_k_bind_execute_many), 0, 0, 1, 1},
+  {&__pyx_n_s_bind_execute_many_locals_genexpr, __pyx_k_bind_execute_many_locals_genexpr, sizeof(__pyx_k_bind_execute_many_locals_genexpr), 0, 0, 1, 1},
+  {&__pyx_n_u_bit, __pyx_k_bit, sizeof(__pyx_k_bit), 0, 1, 0, 1},
+  {&__pyx_n_u_bool, __pyx_k_bool, sizeof(__pyx_k_bool), 0, 1, 0, 1},
+  {&__pyx_n_u_box, __pyx_k_box, sizeof(__pyx_k_box), 0, 1, 0, 1},
+  {&__pyx_n_u_bpchar, __pyx_k_bpchar, sizeof(__pyx_k_bpchar), 0, 1, 0, 1},
+  {&__pyx_n_s_budget, __pyx_k_budget, sizeof(__pyx_k_budget), 0, 0, 1, 1},
+  {&__pyx_n_s_budget_2, __pyx_k_budget_2, sizeof(__pyx_k_budget_2), 0, 0, 1, 1},
+  {&__pyx_n_s_builtins, __pyx_k_builtins, sizeof(__pyx_k_builtins), 0, 0, 1, 1},
+  {&__pyx_n_u_bytea, __pyx_k_bytea, sizeof(__pyx_k_bytea), 0, 1, 0, 1},
+  {&__pyx_n_b_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 0, 1},
+  {&__pyx_n_s_cache_key, __pyx_k_cache_key, sizeof(__pyx_k_cache_key), 0, 0, 1, 1},
+  {&__pyx_n_s_call_exception_handler, __pyx_k_call_exception_handler, sizeof(__pyx_k_call_exception_handler), 0, 0, 1, 1},
+  {&__pyx_n_s_call_later, __pyx_k_call_later, sizeof(__pyx_k_call_later), 0, 0, 1, 1},
+  {&__pyx_n_s_cancel, __pyx_k_cancel, sizeof(__pyx_k_cancel), 0, 0, 1, 1},
+  {&__pyx_n_s_cancel_current_command, __pyx_k_cancel_current_command, sizeof(__pyx_k_cancel_current_command), 0, 0, 1, 1},
+  {&__pyx_n_s_cancelled, __pyx_k_cancelled, sizeof(__pyx_k_cancelled), 0, 0, 1, 1},
+  {&__pyx_kp_u_cannot_alias, __pyx_k_cannot_alias, sizeof(__pyx_k_cannot_alias), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_close_prepared_statement, __pyx_k_cannot_close_prepared_statement, sizeof(__pyx_k_cannot_close_prepared_statement), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_decode_type_text_encoding, __pyx_k_cannot_decode_type_text_encoding, sizeof(__pyx_k_cannot_decode_type_text_encoding), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_decode_type_text_encoding_2, __pyx_k_cannot_decode_type_text_encoding_2, sizeof(__pyx_k_cannot_decode_type_text_encoding_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_perform_operation_another, __pyx_k_cannot_perform_operation_another, sizeof(__pyx_k_cannot_perform_operation_another), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_perform_operation_another_2, __pyx_k_cannot_perform_operation_another_2, sizeof(__pyx_k_cannot_perform_operation_another_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_perform_operation_connect, __pyx_k_cannot_perform_operation_connect, sizeof(__pyx_k_cannot_perform_operation_connect), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_process_message, __pyx_k_cannot_process_message, sizeof(__pyx_k_cannot_process_message), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_register_core_codec_for_O, __pyx_k_cannot_register_core_codec_for_O, sizeof(__pyx_k_cannot_register_core_codec_for_O), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_switch_to_idle_state_prot, __pyx_k_cannot_switch_to_idle_state_prot, sizeof(__pyx_k_cannot_switch_to_idle_state_prot), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_switch_to_state_another_o, __pyx_k_cannot_switch_to_state_another_o, sizeof(__pyx_k_cannot_switch_to_state_another_o), 0, 1, 0, 0},
+  {&__pyx_kp_u_cannot_switch_to_state_protocol, __pyx_k_cannot_switch_to_state_protocol, sizeof(__pyx_k_cannot_switch_to_state_protocol), 0, 1, 0, 0},
+  {&__pyx_n_s_cause, __pyx_k_cause, sizeof(__pyx_k_cause), 0, 0, 1, 1},
+  {&__pyx_n_u_char, __pyx_k_char, sizeof(__pyx_k_char), 0, 1, 0, 1},
+  {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1},
+  {&__pyx_n_u_cid, __pyx_k_cid, sizeof(__pyx_k_cid), 0, 1, 0, 1},
+  {&__pyx_n_u_cidr, __pyx_k_cidr, sizeof(__pyx_k_cidr), 0, 1, 0, 1},
+  {&__pyx_n_u_circle, __pyx_k_circle, sizeof(__pyx_k_circle), 0, 1, 0, 1},
+  {&__pyx_n_s_cleanup, __pyx_k_cleanup, sizeof(__pyx_k_cleanup), 0, 0, 1, 1},
+  {&__pyx_n_s_clear, __pyx_k_clear, sizeof(__pyx_k_clear), 0, 0, 1, 1},
+  {&__pyx_n_s_clear_type_cache, __pyx_k_clear_type_cache, sizeof(__pyx_k_clear_type_cache), 0, 0, 1, 1},
+  {&__pyx_n_b_client_encoding, __pyx_k_client_encoding, sizeof(__pyx_k_client_encoding), 0, 0, 0, 1},
+  {&__pyx_n_u_client_encoding, __pyx_k_client_encoding, sizeof(__pyx_k_client_encoding), 0, 1, 0, 1},
+  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
+  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
+  {&__pyx_n_s_close_statement, __pyx_k_close_statement, sizeof(__pyx_k_close_statement), 0, 0, 1, 1},
+  {&__pyx_kp_u_codec_for, __pyx_k_codec_for, sizeof(__pyx_k_codec_for), 0, 1, 0, 0},
+  {&__pyx_n_s_codecs, __pyx_k_codecs, sizeof(__pyx_k_codecs), 0, 0, 1, 1},
+  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
+  {&__pyx_n_s_collections_abc, __pyx_k_collections_abc, sizeof(__pyx_k_collections_abc), 0, 0, 1, 1},
+  {&__pyx_n_s_command_timeout, __pyx_k_command_timeout, sizeof(__pyx_k_command_timeout), 0, 0, 1, 1},
+  {&__pyx_n_s_compat, __pyx_k_compat, sizeof(__pyx_k_compat), 0, 0, 1, 1},
+  {&__pyx_n_u_composite, __pyx_k_composite, sizeof(__pyx_k_composite), 0, 1, 0, 1},
+  {&__pyx_n_s_con_params, __pyx_k_con_params, sizeof(__pyx_k_con_params), 0, 0, 1, 1},
+  {&__pyx_n_s_config, __pyx_k_config, sizeof(__pyx_k_config), 0, 0, 1, 1},
+  {&__pyx_n_s_conn_key, __pyx_k_conn_key, sizeof(__pyx_k_conn_key), 0, 0, 1, 1},
+  {&__pyx_n_s_connected_fut, __pyx_k_connected_fut, sizeof(__pyx_k_connected_fut), 0, 0, 1, 1},
+  {&__pyx_kp_u_connection_was_closed_in_the_mid, __pyx_k_connection_was_closed_in_the_mid, sizeof(__pyx_k_connection_was_closed_in_the_mid), 0, 1, 0, 0},
+  {&__pyx_n_s_copy_in, __pyx_k_copy_in, sizeof(__pyx_k_copy_in), 0, 0, 1, 1},
+  {&__pyx_n_s_copy_in_locals_lambda, __pyx_k_copy_in_locals_lambda, sizeof(__pyx_k_copy_in_locals_lambda), 0, 0, 1, 1},
+  {&__pyx_n_s_copy_out, __pyx_k_copy_out, sizeof(__pyx_k_copy_out), 0, 0, 1, 1},
+  {&__pyx_n_s_copy_out_locals_lambda, __pyx_k_copy_out_locals_lambda, sizeof(__pyx_k_copy_out_locals_lambda), 0, 0, 1, 1},
+  {&__pyx_n_s_copy_stmt, __pyx_k_copy_stmt, sizeof(__pyx_k_copy_stmt), 0, 0, 1, 1},
+  {&__pyx_n_u_cp1250, __pyx_k_cp1250, sizeof(__pyx_k_cp1250), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1251, __pyx_k_cp1251, sizeof(__pyx_k_cp1251), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1252, __pyx_k_cp1252, sizeof(__pyx_k_cp1252), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1253, __pyx_k_cp1253, sizeof(__pyx_k_cp1253), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1254, __pyx_k_cp1254, sizeof(__pyx_k_cp1254), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1255, __pyx_k_cp1255, sizeof(__pyx_k_cp1255), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1256, __pyx_k_cp1256, sizeof(__pyx_k_cp1256), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1257, __pyx_k_cp1257, sizeof(__pyx_k_cp1257), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1258, __pyx_k_cp1258, sizeof(__pyx_k_cp1258), 0, 1, 0, 1},
+  {&__pyx_n_u_cp1521, __pyx_k_cp1521, sizeof(__pyx_k_cp1521), 0, 1, 0, 1},
+  {&__pyx_n_u_cp866, __pyx_k_cp866, sizeof(__pyx_k_cp866), 0, 1, 0, 1},
+  {&__pyx_n_u_cp874, __pyx_k_cp874, sizeof(__pyx_k_cp874), 0, 1, 0, 1},
+  {&__pyx_n_u_cp932, __pyx_k_cp932, sizeof(__pyx_k_cp932), 0, 1, 0, 1},
+  {&__pyx_n_u_cp936, __pyx_k_cp936, sizeof(__pyx_k_cp936), 0, 1, 0, 1},
+  {&__pyx_n_u_cp949, __pyx_k_cp949, sizeof(__pyx_k_cp949), 0, 1, 0, 1},
+  {&__pyx_n_u_cp950, __pyx_k_cp950, sizeof(__pyx_k_cp950), 0, 1, 0, 1},
+  {&__pyx_n_s_create_future, __pyx_k_create_future, sizeof(__pyx_k_create_future), 0, 0, 1, 1},
+  {&__pyx_n_s_create_future_fallback, __pyx_k_create_future_fallback, sizeof(__pyx_k_create_future_fallback), 0, 0, 1, 1},
+  {&__pyx_n_s_create_record, __pyx_k_create_record, sizeof(__pyx_k_create_record), 0, 0, 1, 1},
+  {&__pyx_n_u_cstring, __pyx_k_cstring, sizeof(__pyx_k_cstring), 0, 1, 0, 1},
+  {&__pyx_n_b_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 0, 1},
+  {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
+  {&__pyx_n_s_data_type, __pyx_k_data_type, sizeof(__pyx_k_data_type), 0, 0, 1, 1},
+  {&__pyx_n_s_database, __pyx_k_database, sizeof(__pyx_k_database), 0, 0, 1, 1},
+  {&__pyx_n_u_database, __pyx_k_database, sizeof(__pyx_k_database), 0, 1, 0, 1},
+  {&__pyx_n_u_date, __pyx_k_date, sizeof(__pyx_k_date), 0, 1, 0, 1},
+  {&__pyx_n_u_decimal, __pyx_k_decimal, sizeof(__pyx_k_decimal), 0, 1, 0, 1},
+  {&__pyx_n_s_declare_fallback_codec, __pyx_k_declare_fallback_codec, sizeof(__pyx_k_declare_fallback_codec), 0, 0, 1, 1},
+  {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1},
+  {&__pyx_kp_u_decode_row_statement_is_None, __pyx_k_decode_row_statement_is_None, sizeof(__pyx_k_decode_row_statement_is_None), 0, 1, 0, 0},
+  {&__pyx_n_s_decoder, __pyx_k_decoder, sizeof(__pyx_k_decoder), 0, 0, 1, 1},
+  {&__pyx_n_s_desc, __pyx_k_desc, sizeof(__pyx_k_desc), 0, 0, 1, 1},
+  {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
+  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
+  {&__pyx_n_s_done, __pyx_k_done, sizeof(__pyx_k_done), 0, 0, 1, 1},
+  {&__pyx_kp_u_double_precision, __pyx_k_double_precision, sizeof(__pyx_k_double_precision), 0, 1, 0, 0},
+  {&__pyx_n_b_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 0, 1},
+  {&__pyx_n_s_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 1, 1},
+  {&__pyx_n_s_elem, __pyx_k_elem, sizeof(__pyx_k_elem), 0, 0, 1, 1},
+  {&__pyx_n_u_elem_has_bin_io, __pyx_k_elem_has_bin_io, sizeof(__pyx_k_elem_has_bin_io), 0, 1, 0, 1},
+  {&__pyx_n_u_elemdelim, __pyx_k_elemdelim, sizeof(__pyx_k_elemdelim), 0, 1, 0, 1},
+  {&__pyx_n_s_elems, __pyx_k_elems, sizeof(__pyx_k_elems), 0, 0, 1, 1},
+  {&__pyx_n_u_elemtype, __pyx_k_elemtype, sizeof(__pyx_k_elemtype), 0, 1, 0, 1},
+  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
+  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
+  {&__pyx_n_s_encoder, __pyx_k_encoder, sizeof(__pyx_k_encoder), 0, 0, 1, 1},
+  {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
+  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
+  {&__pyx_n_s_et, __pyx_k_et, sizeof(__pyx_k_et), 0, 0, 1, 1},
+  {&__pyx_n_u_euc_cn, __pyx_k_euc_cn, sizeof(__pyx_k_euc_cn), 0, 1, 0, 1},
+  {&__pyx_n_u_euc_jis_2004, __pyx_k_euc_jis_2004, sizeof(__pyx_k_euc_jis_2004), 0, 1, 0, 1},
+  {&__pyx_n_u_euc_jp, __pyx_k_euc_jp, sizeof(__pyx_k_euc_jp), 0, 1, 0, 1},
+  {&__pyx_n_u_euc_kr, __pyx_k_euc_kr, sizeof(__pyx_k_euc_kr), 0, 1, 0, 1},
+  {&__pyx_n_u_euccn, __pyx_k_euccn, sizeof(__pyx_k_euccn), 0, 1, 0, 1},
+  {&__pyx_n_u_eucjp, __pyx_k_eucjp, sizeof(__pyx_k_eucjp), 0, 1, 0, 1},
+  {&__pyx_n_u_euckr, __pyx_k_euckr, sizeof(__pyx_k_euckr), 0, 1, 0, 1},
+  {&__pyx_n_u_event_trigger, __pyx_k_event_trigger, sizeof(__pyx_k_event_trigger), 0, 1, 0, 1},
+  {&__pyx_n_s_exception, __pyx_k_exception, sizeof(__pyx_k_exception), 0, 0, 1, 1},
+  {&__pyx_n_s_exceptions, __pyx_k_exceptions, sizeof(__pyx_k_exceptions), 0, 0, 1, 1},
+  {&__pyx_n_s_execute, __pyx_k_execute, sizeof(__pyx_k_execute), 0, 0, 1, 1},
+  {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
+  {&__pyx_kp_u_expected_0_1_or_2_elements_in_ra, __pyx_k_expected_0_1_or_2_elements_in_ra, sizeof(__pyx_k_expected_0_1_or_2_elements_in_ra), 0, 1, 0, 0},
+  {&__pyx_n_s_family, __pyx_k_family, sizeof(__pyx_k_family), 0, 0, 1, 1},
+  {&__pyx_n_u_fdw_handler, __pyx_k_fdw_handler, sizeof(__pyx_k_fdw_handler), 0, 1, 0, 1},
+  {&__pyx_n_u_float4, __pyx_k_float4, sizeof(__pyx_k_float4), 0, 1, 0, 1},
+  {&__pyx_n_u_float8, __pyx_k_float8, sizeof(__pyx_k_float8), 0, 1, 0, 1},
+  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
+  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1},
+  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
+  {&__pyx_n_s_get_extra_info, __pyx_k_get_extra_info, sizeof(__pyx_k_get_extra_info), 0, 0, 1, 1},
+  {&__pyx_n_s_get_remaining_budget, __pyx_k_get_remaining_budget, sizeof(__pyx_k_get_remaining_budget), 0, 0, 1, 1},
+  {&__pyx_n_s_get_timeout, __pyx_k_get_timeout, sizeof(__pyx_k_get_timeout), 0, 0, 1, 1},
+  {&__pyx_n_s_getattr, __pyx_k_getattr, sizeof(__pyx_k_getattr), 0, 0, 1, 1},
+  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
+  {&__pyx_kp_u_got_result_for_unknown_protocol, __pyx_k_got_result_for_unknown_protocol, sizeof(__pyx_k_got_result_for_unknown_protocol), 0, 1, 0, 0},
+  {&__pyx_n_u_gtsvector, __pyx_k_gtsvector, sizeof(__pyx_k_gtsvector), 0, 1, 0, 1},
+  {&__pyx_n_u_has_bin_io, __pyx_k_has_bin_io, sizeof(__pyx_k_has_bin_io), 0, 1, 0, 1},
+  {&__pyx_n_s_hashlib, __pyx_k_hashlib, sizeof(__pyx_k_hashlib), 0, 0, 1, 1},
+  {&__pyx_n_s_hashlib_md5, __pyx_k_hashlib_md5, sizeof(__pyx_k_hashlib_md5), 0, 0, 1, 1},
+  {&__pyx_n_s_hexdigest, __pyx_k_hexdigest, sizeof(__pyx_k_hexdigest), 0, 0, 1, 1},
+  {&__pyx_n_s_hint, __pyx_k_hint, sizeof(__pyx_k_hint), 0, 0, 1, 1},
+  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
+  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
+  {&__pyx_kp_u_inconsistent_sub_array_dimension, __pyx_k_inconsistent_sub_array_dimension, sizeof(__pyx_k_inconsistent_sub_array_dimension), 0, 1, 0, 0},
+  {&__pyx_n_u_index_am_handler, __pyx_k_index_am_handler, sizeof(__pyx_k_index_am_handler), 0, 1, 0, 1},
+  {&__pyx_n_u_inet, __pyx_k_inet, sizeof(__pyx_k_inet), 0, 1, 0, 1},
+  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
+  {&__pyx_n_s_inspect, __pyx_k_inspect, sizeof(__pyx_k_inspect), 0, 0, 1, 1},
+  {&__pyx_n_u_int, __pyx_k_int, sizeof(__pyx_k_int), 0, 1, 0, 1},
+  {&__pyx_n_u_int2, __pyx_k_int2, sizeof(__pyx_k_int2), 0, 1, 0, 1},
+  {&__pyx_n_u_int4, __pyx_k_int4, sizeof(__pyx_k_int4), 0, 1, 0, 1},
+  {&__pyx_n_u_int8, __pyx_k_int8, sizeof(__pyx_k_int8), 0, 1, 0, 1},
+  {&__pyx_n_u_integer, __pyx_k_integer, sizeof(__pyx_k_integer), 0, 1, 0, 1},
+  {&__pyx_n_u_internal, __pyx_k_internal, sizeof(__pyx_k_internal), 0, 1, 0, 1},
+  {&__pyx_n_u_interval, __pyx_k_interval, sizeof(__pyx_k_interval), 0, 1, 0, 1},
+  {&__pyx_kp_u_invalid_array_element, __pyx_k_invalid_array_element, sizeof(__pyx_k_invalid_array_element), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_array_element_at_index, __pyx_k_invalid_array_element_at_index, sizeof(__pyx_k_invalid_array_element_at_index), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_data_format, __pyx_k_invalid_data_format, sizeof(__pyx_k_invalid_data_format), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_format_argument_expected, __pyx_k_invalid_format_argument_expected, sizeof(__pyx_k_invalid_format_argument_expected), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_input_for_query_argument, __pyx_k_invalid_input_for_query_argument, sizeof(__pyx_k_invalid_input_for_query_argument), 0, 1, 0, 0},
+  {&__pyx_kp_u_invalid_timeout_value_expected_n, __pyx_k_invalid_timeout_value_expected_n, sizeof(__pyx_k_invalid_timeout_value_expected_n), 0, 1, 0, 0},
+  {&__pyx_n_s_isempty, __pyx_k_isempty, sizeof(__pyx_k_isempty), 0, 0, 1, 1},
+  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
+  {&__pyx_n_u_json, __pyx_k_json, sizeof(__pyx_k_json), 0, 1, 0, 1},
+  {&__pyx_n_u_jsonb, __pyx_k_jsonb, sizeof(__pyx_k_jsonb), 0, 1, 0, 1},
+  {&__pyx_n_u_kind, __pyx_k_kind, sizeof(__pyx_k_kind), 0, 1, 0, 1},
+  {&__pyx_n_u_koi8_r, __pyx_k_koi8_r, sizeof(__pyx_k_koi8_r), 0, 1, 0, 1},
+  {&__pyx_n_u_koi8_u, __pyx_k_koi8_u, sizeof(__pyx_k_koi8_u), 0, 1, 0, 1},
+  {&__pyx_n_u_koi8r, __pyx_k_koi8r, sizeof(__pyx_k_koi8r), 0, 1, 0, 1},
+  {&__pyx_n_u_koi8u, __pyx_k_koi8u, sizeof(__pyx_k_koi8u), 0, 1, 0, 1},
+  {&__pyx_n_u_language_handler, __pyx_k_language_handler, sizeof(__pyx_k_language_handler), 0, 1, 0, 1},
+  {&__pyx_n_s_limit, __pyx_k_limit, sizeof(__pyx_k_limit), 0, 0, 1, 1},
+  {&__pyx_n_u_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 1, 0, 1},
+  {&__pyx_kp_u_list_tuple_or_Range_object_expec, __pyx_k_list_tuple_or_Range_object_expec, sizeof(__pyx_k_list_tuple_or_Range_object_expec), 0, 1, 0, 0},
+  {&__pyx_n_s_lookup, __pyx_k_lookup, sizeof(__pyx_k_lookup), 0, 0, 1, 1},
+  {&__pyx_n_s_loop, __pyx_k_loop, sizeof(__pyx_k_loop), 0, 0, 1, 1},
+  {&__pyx_n_s_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 0, 0, 1, 1},
+  {&__pyx_n_s_lower_inc, __pyx_k_lower_inc, sizeof(__pyx_k_lower_inc), 0, 0, 1, 1},
+  {&__pyx_n_u_lseg, __pyx_k_lseg, sizeof(__pyx_k_lseg), 0, 1, 0, 1},
+  {&__pyx_n_u_macaddr, __pyx_k_macaddr, sizeof(__pyx_k_macaddr), 0, 1, 0, 1},
+  {&__pyx_n_u_macaddr8, __pyx_k_macaddr8, sizeof(__pyx_k_macaddr8), 0, 1, 0, 1},
+  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
+  {&__pyx_kp_u_malformed_array_literal_r, __pyx_k_malformed_array_literal_r, sizeof(__pyx_k_malformed_array_literal_r), 0, 1, 0, 0},
+  {&__pyx_n_s_mapping, __pyx_k_mapping, sizeof(__pyx_k_mapping), 0, 0, 1, 1},
+  {&__pyx_n_b_md5, __pyx_k_md5, sizeof(__pyx_k_md5), 0, 0, 0, 1},
+  {&__pyx_n_s_md5, __pyx_k_md5, sizeof(__pyx_k_md5), 0, 0, 1, 1},
+  {&__pyx_n_s_memoryview, __pyx_k_memoryview, sizeof(__pyx_k_memoryview), 0, 0, 1, 1},
+  {&__pyx_n_u_message, __pyx_k_message, sizeof(__pyx_k_message), 0, 1, 0, 1},
+  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
+  {&__pyx_kp_u_missing_after_array_dimensions, __pyx_k_missing_after_array_dimensions, sizeof(__pyx_k_missing_after_array_dimensions), 0, 1, 0, 0},
+  {&__pyx_kp_u_missing_after_array_dimensions_2, __pyx_k_missing_after_array_dimensions_2, sizeof(__pyx_k_missing_after_array_dimensions_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_missing_array_dimension_value, __pyx_k_missing_array_dimension_value, sizeof(__pyx_k_missing_array_dimension_value), 0, 1, 0, 0},
+  {&__pyx_kp_u_missing_codec_information_for_OI, __pyx_k_missing_codec_information_for_OI, sizeof(__pyx_k_missing_codec_information_for_OI), 0, 1, 0, 0},
+  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
+  {&__pyx_n_u_money, __pyx_k_money, sizeof(__pyx_k_money), 0, 1, 0, 1},
+  {&__pyx_n_s_monotonic, __pyx_k_monotonic, sizeof(__pyx_k_monotonic), 0, 0, 1, 1},
+  {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1},
+  {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
+  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
+  {&__pyx_n_u_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 1, 0, 1},
+  {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
+  {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
+  {&__pyx_n_s_new_2, __pyx_k_new_2, sizeof(__pyx_k_new_2), 0, 0, 1, 1},
+  {&__pyx_kp_u_no_binary_format_encoder_for_typ, __pyx_k_no_binary_format_encoder_for_typ, sizeof(__pyx_k_no_binary_format_encoder_for_typ), 0, 1, 0, 0},
+  {&__pyx_kp_u_no_codec_for_composite_attribute, __pyx_k_no_codec_for_composite_attribute, sizeof(__pyx_k_no_codec_for_composite_attribute), 0, 1, 0, 0},
+  {&__pyx_kp_u_no_decoder_for_OID, __pyx_k_no_decoder_for_OID, sizeof(__pyx_k_no_decoder_for_OID), 0, 1, 0, 0},
+  {&__pyx_kp_u_no_decoder_for_composite_type_el, __pyx_k_no_decoder_for_composite_type_el, sizeof(__pyx_k_no_decoder_for_composite_type_el), 0, 1, 0, 0},
+  {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
+  {&__pyx_kp_u_no_encoder_for_OID, __pyx_k_no_encoder_for_OID, sizeof(__pyx_k_no_encoder_for_OID), 0, 1, 0, 0},
+  {&__pyx_kp_u_non_homogeneous_array, __pyx_k_non_homogeneous_array, sizeof(__pyx_k_non_homogeneous_array), 0, 1, 0, 0},
+  {&__pyx_kp_u_not_connected, __pyx_k_not_connected, sizeof(__pyx_k_not_connected), 0, 1, 0, 0},
+  {&__pyx_n_u_ns, __pyx_k_ns, sizeof(__pyx_k_ns), 0, 1, 0, 1},
+  {&__pyx_kp_u_number_of_array_dimensions_excee, __pyx_k_number_of_array_dimensions_excee, sizeof(__pyx_k_number_of_array_dimensions_excee), 0, 1, 0, 0},
+  {&__pyx_n_u_numeric, __pyx_k_numeric, sizeof(__pyx_k_numeric), 0, 1, 0, 1},
+  {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
+  {&__pyx_n_s_oid, __pyx_k_oid, sizeof(__pyx_k_oid), 0, 0, 1, 1},
+  {&__pyx_n_u_oid, __pyx_k_oid, sizeof(__pyx_k_oid), 0, 1, 0, 1},
+  {&__pyx_kp_u_oid_2, __pyx_k_oid_2, sizeof(__pyx_k_oid_2), 0, 1, 0, 0},
+  {&__pyx_n_s_on_error, __pyx_k_on_error, sizeof(__pyx_k_on_error), 0, 0, 1, 1},
+  {&__pyx_kp_u_on_result__prepare_statement_is, __pyx_k_on_result__prepare_statement_is, sizeof(__pyx_k_on_result__prepare_statement_is), 0, 1, 0, 0},
+  {&__pyx_kp_u_on_result_waiter_is_None, __pyx_k_on_result_waiter_is_None, sizeof(__pyx_k_on_result_waiter_is_None), 0, 1, 0, 0},
+  {&__pyx_kp_u_on_result_waiter_is_done, __pyx_k_on_result_waiter_is_done, sizeof(__pyx_k_on_result_waiter_is_done), 0, 1, 0, 0},
+  {&__pyx_n_s_on_timeout, __pyx_k_on_timeout, sizeof(__pyx_k_on_timeout), 0, 0, 1, 1},
+  {&__pyx_n_s_on_waiter_completed, __pyx_k_on_waiter_completed, sizeof(__pyx_k_on_waiter_completed), 0, 0, 1, 1},
+  {&__pyx_n_u_opaque, __pyx_k_opaque, sizeof(__pyx_k_opaque), 0, 1, 0, 1},
+  {&__pyx_kp_u_parse_data_msgs_first_message_i, __pyx_k_parse_data_msgs_first_message_i, sizeof(__pyx_k_parse_data_msgs_first_message_i), 0, 1, 0, 0},
+  {&__pyx_kp_u_parse_data_msgs_result_is_not_a, __pyx_k_parse_data_msgs_result_is_not_a, sizeof(__pyx_k_parse_data_msgs_result_is_not_a), 0, 1, 0, 0},
+  {&__pyx_n_s_password, __pyx_k_password, sizeof(__pyx_k_password), 0, 0, 1, 1},
+  {&__pyx_n_u_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 1, 0, 1},
+  {&__pyx_n_s_pause_reading, __pyx_k_pause_reading, sizeof(__pyx_k_pause_reading), 0, 0, 1, 1},
+  {&__pyx_n_u_pg_catalog, __pyx_k_pg_catalog, sizeof(__pyx_k_pg_catalog), 0, 1, 0, 1},
+  {&__pyx_kp_u_pg_contrib_hstore, __pyx_k_pg_contrib_hstore, sizeof(__pyx_k_pg_contrib_hstore), 0, 1, 0, 0},
+  {&__pyx_n_u_pg_ddl_command, __pyx_k_pg_ddl_command, sizeof(__pyx_k_pg_ddl_command), 0, 1, 0, 1},
+  {&__pyx_n_u_pg_dependencies, __pyx_k_pg_dependencies, sizeof(__pyx_k_pg_dependencies), 0, 1, 0, 1},
+  {&__pyx_n_u_pg_lsn, __pyx_k_pg_lsn, sizeof(__pyx_k_pg_lsn), 0, 1, 0, 1},
+  {&__pyx_n_u_pg_ndistinct, __pyx_k_pg_ndistinct, sizeof(__pyx_k_pg_ndistinct), 0, 1, 0, 1},
+  {&__pyx_n_u_pg_node_tree, __pyx_k_pg_node_tree, sizeof(__pyx_k_pg_node_tree), 0, 1, 0, 1},
+  {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1},
+  {&__pyx_n_u_point, __pyx_k_point, sizeof(__pyx_k_point), 0, 1, 0, 1},
+  {&__pyx_n_u_polygon, __pyx_k_polygon, sizeof(__pyx_k_polygon), 0, 1, 0, 1},
+  {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
+  {&__pyx_n_s_portal_name, __pyx_k_portal_name, sizeof(__pyx_k_portal_name), 0, 0, 1, 1},
+  {&__pyx_n_s_position, __pyx_k_position, sizeof(__pyx_k_position), 0, 0, 1, 1},
+  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
+  {&__pyx_n_s_prepare_2, __pyx_k_prepare_2, sizeof(__pyx_k_prepare_2), 0, 0, 1, 1},
+  {&__pyx_n_s_process_log_message, __pyx_k_process_log_message, sizeof(__pyx_k_process_log_message), 0, 0, 1, 1},
+  {&__pyx_n_s_process_notification, __pyx_k_process_notification, sizeof(__pyx_k_process_notification), 0, 0, 1, 1},
+  {&__pyx_n_s_protocol, __pyx_k_protocol, sizeof(__pyx_k_protocol), 0, 0, 1, 1},
+  {&__pyx_kp_u_protocol_is_in_an_unexpected_st, __pyx_k_protocol_is_in_an_unexpected_st, sizeof(__pyx_k_protocol_is_in_an_unexpected_st), 0, 1, 0, 0},
+  {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_capi, __pyx_k_pyx_capi, sizeof(__pyx_k_pyx_capi), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_unpickle_BaseProtocol, __pyx_k_pyx_unpickle_BaseProtocol, sizeof(__pyx_k_pyx_unpickle_BaseProtocol), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_unpickle_CoreProtocol, __pyx_k_pyx_unpickle_CoreProtocol, sizeof(__pyx_k_pyx_unpickle_CoreProtocol), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_unpickle_DataCodecConfig, __pyx_k_pyx_unpickle_DataCodecConfig, sizeof(__pyx_k_pyx_unpickle_DataCodecConfig), 0, 0, 1, 1},
+  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
+  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
+  {&__pyx_n_s_query, __pyx_k_query, sizeof(__pyx_k_query), 0, 0, 1, 1},
+  {&__pyx_n_b_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 0, 1},
+  {&__pyx_kp_u_r_is_not_a_valid_element_of_com, __pyx_k_r_is_not_a_valid_element_of_com, sizeof(__pyx_k_r_is_not_a_valid_element_of_com), 0, 1, 0, 0},
+  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
+  {&__pyx_n_u_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 1, 0, 1},
+  {&__pyx_n_u_range_subtype, __pyx_k_range_subtype, sizeof(__pyx_k_range_subtype), 0, 1, 0, 1},
+  {&__pyx_n_s_reader, __pyx_k_reader, sizeof(__pyx_k_reader), 0, 0, 1, 1},
+  {&__pyx_kp_u_reader_is_not_an_asynchronous_it, __pyx_k_reader_is_not_an_asynchronous_it, sizeof(__pyx_k_reader_is_not_an_asynchronous_it), 0, 1, 0, 0},
+  {&__pyx_n_u_real, __pyx_k_real, sizeof(__pyx_k_real), 0, 1, 0, 1},
+  {&__pyx_n_s_rec, __pyx_k_rec, sizeof(__pyx_k_rec), 0, 0, 1, 1},
+  {&__pyx_n_u_record, __pyx_k_record, sizeof(__pyx_k_record), 0, 1, 0, 1},
+  {&__pyx_n_s_record_stmt, __pyx_k_record_stmt, sizeof(__pyx_k_record_stmt), 0, 0, 1, 1},
+  {&__pyx_n_s_records, __pyx_k_records, sizeof(__pyx_k_records), 0, 0, 1, 1},
+  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
+  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
+  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
+  {&__pyx_n_s_ref, __pyx_k_ref, sizeof(__pyx_k_ref), 0, 0, 1, 1},
+  {&__pyx_n_u_refcursor, __pyx_k_refcursor, sizeof(__pyx_k_refcursor), 0, 1, 0, 1},
+  {&__pyx_n_u_regclass, __pyx_k_regclass, sizeof(__pyx_k_regclass), 0, 1, 0, 1},
+  {&__pyx_n_u_regconfig, __pyx_k_regconfig, sizeof(__pyx_k_regconfig), 0, 1, 0, 1},
+  {&__pyx_n_u_regdictionary, __pyx_k_regdictionary, sizeof(__pyx_k_regdictionary), 0, 1, 0, 1},
+  {&__pyx_n_u_regnamespace, __pyx_k_regnamespace, sizeof(__pyx_k_regnamespace), 0, 1, 0, 1},
+  {&__pyx_n_u_regoper, __pyx_k_regoper, sizeof(__pyx_k_regoper), 0, 1, 0, 1},
+  {&__pyx_n_u_regoperator, __pyx_k_regoperator, sizeof(__pyx_k_regoperator), 0, 1, 0, 1},
+  {&__pyx_n_u_regproc, __pyx_k_regproc, sizeof(__pyx_k_regproc), 0, 1, 0, 1},
+  {&__pyx_n_u_regprocedure, __pyx_k_regprocedure, sizeof(__pyx_k_regprocedure), 0, 1, 0, 1},
+  {&__pyx_n_u_regrole, __pyx_k_regrole, sizeof(__pyx_k_regrole), 0, 1, 0, 1},
+  {&__pyx_n_u_regtype, __pyx_k_regtype, sizeof(__pyx_k_regtype), 0, 1, 0, 1},
+  {&__pyx_n_s_release, __pyx_k_release, sizeof(__pyx_k_release), 0, 0, 1, 1},
+  {&__pyx_n_u_reltime, __pyx_k_reltime, sizeof(__pyx_k_reltime), 0, 1, 0, 1},
+  {&__pyx_n_s_remove_python_codec, __pyx_k_remove_python_codec, sizeof(__pyx_k_remove_python_codec), 0, 0, 1, 1},
+  {&__pyx_n_s_request_cancel, __pyx_k_request_cancel, sizeof(__pyx_k_request_cancel), 0, 0, 1, 1},
+  {&__pyx_n_s_resume_reading, __pyx_k_resume_reading, sizeof(__pyx_k_resume_reading), 0, 0, 1, 1},
+  {&__pyx_n_s_return_extra, __pyx_k_return_extra, sizeof(__pyx_k_return_extra), 0, 0, 1, 1},
+  {&__pyx_n_s_reversed, __pyx_k_reversed, sizeof(__pyx_k_reversed), 0, 0, 1, 1},
+  {&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1},
+  {&__pyx_n_u_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 1, 0, 1},
+  {&__pyx_n_u_scalar, __pyx_k_scalar, sizeof(__pyx_k_scalar), 0, 1, 0, 1},
+  {&__pyx_n_s_schema, __pyx_k_schema, sizeof(__pyx_k_schema), 0, 0, 1, 1},
+  {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
+  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
+  {&__pyx_n_s_server_settings, __pyx_k_server_settings, sizeof(__pyx_k_server_settings), 0, 0, 1, 1},
+  {&__pyx_n_s_set, __pyx_k_set, sizeof(__pyx_k_set), 0, 0, 1, 1},
+  {&__pyx_n_s_set_builtin_type_codec, __pyx_k_set_builtin_type_codec, sizeof(__pyx_k_set_builtin_type_codec), 0, 0, 1, 1},
+  {&__pyx_n_s_set_builtin_type_codec_2, __pyx_k_set_builtin_type_codec_2, sizeof(__pyx_k_set_builtin_type_codec_2), 0, 0, 1, 1},
+  {&__pyx_n_s_set_exception, __pyx_k_set_exception, sizeof(__pyx_k_set_exception), 0, 0, 1, 1},
+  {&__pyx_n_s_set_result, __pyx_k_set_result, sizeof(__pyx_k_set_result), 0, 0, 1, 1},
+  {&__pyx_n_s_setsockopt, __pyx_k_setsockopt, sizeof(__pyx_k_setsockopt), 0, 0, 1, 1},
+  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
+  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
+  {&__pyx_n_u_shift_jis, __pyx_k_shift_jis, sizeof(__pyx_k_shift_jis), 0, 1, 0, 1},
+  {&__pyx_n_u_shift_jis_2004, __pyx_k_shift_jis_2004, sizeof(__pyx_k_shift_jis_2004), 0, 1, 0, 1},
+  {&__pyx_n_s_sink, __pyx_k_sink, sizeof(__pyx_k_sink), 0, 0, 1, 1},
+  {&__pyx_n_u_sjis, __pyx_k_sjis, sizeof(__pyx_k_sjis), 0, 1, 0, 1},
+  {&__pyx_n_u_smallint, __pyx_k_smallint, sizeof(__pyx_k_smallint), 0, 1, 0, 1},
+  {&__pyx_n_u_smgr, __pyx_k_smgr, sizeof(__pyx_k_smgr), 0, 1, 0, 1},
+  {&__pyx_n_s_socket, __pyx_k_socket, sizeof(__pyx_k_socket), 0, 0, 1, 1},
+  {&__pyx_n_u_socket, __pyx_k_socket, sizeof(__pyx_k_socket), 0, 1, 0, 1},
+  {&__pyx_kp_u_specified_array_dimensions_do_no, __pyx_k_specified_array_dimensions_do_no, sizeof(__pyx_k_specified_array_dimensions_do_no), 0, 1, 0, 0},
+  {&__pyx_n_u_sql_ascii, __pyx_k_sql_ascii, sizeof(__pyx_k_sql_ascii), 0, 1, 0, 1},
+  {&__pyx_n_s_started, __pyx_k_started, sizeof(__pyx_k_started), 0, 0, 1, 1},
+  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
+  {&__pyx_n_s_state, __pyx_k_state, sizeof(__pyx_k_state), 0, 0, 1, 1},
+  {&__pyx_n_s_stmt_name, __pyx_k_stmt_name, sizeof(__pyx_k_stmt_name), 0, 0, 1, 1},
+  {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
+  {&__pyx_n_s_tb, __pyx_k_tb, sizeof(__pyx_k_tb), 0, 0, 1, 1},
+  {&__pyx_n_u_tcvn, __pyx_k_tcvn, sizeof(__pyx_k_tcvn), 0, 1, 0, 1},
+  {&__pyx_n_u_tcvn5712, __pyx_k_tcvn5712, sizeof(__pyx_k_tcvn5712), 0, 1, 0, 1},
+  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
+  {&__pyx_n_u_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 1, 0, 1},
+  {&__pyx_kp_u_text_2, __pyx_k_text_2, sizeof(__pyx_k_text_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_text_binary_or_tuple, __pyx_k_text_binary_or_tuple, sizeof(__pyx_k_text_binary_or_tuple), 0, 1, 0, 0},
+  {&__pyx_kp_u_text_or_binary, __pyx_k_text_or_binary, sizeof(__pyx_k_text_or_binary), 0, 1, 0, 0},
+  {&__pyx_kp_u_text_or_binary_2, __pyx_k_text_or_binary_2, sizeof(__pyx_k_text_or_binary_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_the_number_of_columns_in_the_res, __pyx_k_the_number_of_columns_in_the_res, sizeof(__pyx_k_the_number_of_columns_in_the_res), 0, 1, 0, 0},
+  {&__pyx_kp_u_the_number_of_query_arguments_ca, __pyx_k_the_number_of_query_arguments_ca, sizeof(__pyx_k_the_number_of_query_arguments_ca), 0, 1, 0, 0},
+  {&__pyx_kp_u_the_server_expects_x_argument_s, __pyx_k_the_server_expects_x_argument_s, sizeof(__pyx_k_the_server_expects_x_argument_s), 0, 1, 0, 0},
+  {&__pyx_kp_u_there_is_no, __pyx_k_there_is_no, sizeof(__pyx_k_there_is_no), 0, 1, 0, 0},
+  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
+  {&__pyx_n_u_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 1, 0, 1},
+  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
+  {&__pyx_n_u_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 1, 0, 1},
+  {&__pyx_kp_u_time_with_timezone, __pyx_k_time_with_timezone, sizeof(__pyx_k_time_with_timezone), 0, 1, 0, 0},
+  {&__pyx_n_s_timeout, __pyx_k_timeout, sizeof(__pyx_k_timeout), 0, 0, 1, 1},
+  {&__pyx_n_u_timestamp, __pyx_k_timestamp, sizeof(__pyx_k_timestamp), 0, 1, 0, 1},
+  {&__pyx_kp_u_timestamp_with_timezone, __pyx_k_timestamp_with_timezone, sizeof(__pyx_k_timestamp_with_timezone), 0, 1, 0, 0},
+  {&__pyx_n_u_timestamptz, __pyx_k_timestamptz, sizeof(__pyx_k_timestamptz), 0, 1, 0, 1},
+  {&__pyx_n_u_timetz, __pyx_k_timetz, sizeof(__pyx_k_timetz), 0, 1, 0, 1},
+  {&__pyx_n_u_tinterval, __pyx_k_tinterval, sizeof(__pyx_k_tinterval), 0, 1, 0, 1},
+  {&__pyx_kp_u_to, __pyx_k_to, sizeof(__pyx_k_to), 0, 1, 0, 0},
+  {&__pyx_kp_u_too_many_elements_in_array_value, __pyx_k_too_many_elements_in_array_value, sizeof(__pyx_k_too_many_elements_in_array_value), 0, 1, 0, 0},
+  {&__pyx_kp_u_too_many_elements_in_composite_t, __pyx_k_too_many_elements_in_composite_t, sizeof(__pyx_k_too_many_elements_in_composite_t), 0, 1, 0, 0},
+  {&__pyx_n_u_trigger, __pyx_k_trigger, sizeof(__pyx_k_trigger), 0, 1, 0, 1},
+  {&__pyx_n_u_tsm_handler, __pyx_k_tsm_handler, sizeof(__pyx_k_tsm_handler), 0, 1, 0, 1},
+  {&__pyx_n_u_tsquery, __pyx_k_tsquery, sizeof(__pyx_k_tsquery), 0, 1, 0, 1},
+  {&__pyx_n_u_tsvector, __pyx_k_tsvector, sizeof(__pyx_k_tsvector), 0, 1, 0, 1},
+  {&__pyx_n_u_tuple, __pyx_k_tuple, sizeof(__pyx_k_tuple), 0, 1, 0, 1},
+  {&__pyx_n_u_txid_snapshot, __pyx_k_txid_snapshot, sizeof(__pyx_k_txid_snapshot), 0, 1, 0, 1},
+  {&__pyx_kp_u_type_does_not_support_the_tuple, __pyx_k_type_does_not_support_the_tuple, sizeof(__pyx_k_type_does_not_support_the_tuple), 0, 1, 0, 0},
+  {&__pyx_kp_u_type_record_missing_base_type_fo, __pyx_k_type_record_missing_base_type_fo, sizeof(__pyx_k_type_record_missing_base_type_fo), 0, 1, 0, 0},
+  {&__pyx_kp_u_type_record_missing_base_type_fo_2, __pyx_k_type_record_missing_base_type_fo_2, sizeof(__pyx_k_type_record_missing_base_type_fo_2), 0, 1, 0, 0},
+  {&__pyx_kp_u_type_record_missing_field_types, __pyx_k_type_record_missing_field_types, sizeof(__pyx_k_type_record_missing_field_types), 0, 1, 0, 0},
+  {&__pyx_n_s_typekind, __pyx_k_typekind, sizeof(__pyx_k_typekind), 0, 0, 1, 1},
+  {&__pyx_n_s_typename, __pyx_k_typename, sizeof(__pyx_k_typename), 0, 0, 1, 1},
+  {&__pyx_n_s_typeoid, __pyx_k_typeoid, sizeof(__pyx_k_typeoid), 0, 0, 1, 1},
+  {&__pyx_n_s_types, __pyx_k_types, sizeof(__pyx_k_types), 0, 0, 1, 1},
+  {&__pyx_n_s_typeschema, __pyx_k_typeschema, sizeof(__pyx_k_typeschema), 0, 0, 1, 1},
+  {&__pyx_kp_u_unexpected_character_r_at_positi, __pyx_k_unexpected_character_r_at_positi, sizeof(__pyx_k_unexpected_character_r_at_positi), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_codec_type, __pyx_k_unexpected_codec_type, sizeof(__pyx_k_unexpected_codec_type), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_data_format, __pyx_k_unexpected_data_format, sizeof(__pyx_k_unexpected_data_format), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_data_type_of_composit, __pyx_k_unexpected_data_type_of_composit, sizeof(__pyx_k_unexpected_data_type_of_composit), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_end_of_string, __pyx_k_unexpected_end_of_string, sizeof(__pyx_k_unexpected_end_of_string), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_exchange_format, __pyx_k_unexpected_exchange_format, sizeof(__pyx_k_unexpected_exchange_format), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_instance_of_anyarray, __pyx_k_unexpected_instance_of_anyarray, sizeof(__pyx_k_unexpected_instance_of_anyarray), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_ndims_value, __pyx_k_unexpected_ndims_value, sizeof(__pyx_k_unexpected_ndims_value), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_number_of_attributes, __pyx_k_unexpected_number_of_attributes, sizeof(__pyx_k_unexpected_number_of_attributes), 0, 1, 0, 0},
+  {&__pyx_kp_u_unexpected_trailing_bytes_in_buf, __pyx_k_unexpected_trailing_bytes_in_buf, sizeof(__pyx_k_unexpected_trailing_bytes_in_buf), 0, 1, 0, 0},
+  {&__pyx_kp_u_unhandled_standard_data_type_r_O, __pyx_k_unhandled_standard_data_type_r_O, sizeof(__pyx_k_unhandled_standard_data_type_r_O), 0, 1, 0, 0},
+  {&__pyx_n_u_unicode, __pyx_k_unicode, sizeof(__pyx_k_unicode), 0, 1, 0, 1},
+  {&__pyx_n_u_unknown, __pyx_k_unknown, sizeof(__pyx_k_unknown), 0, 1, 0, 1},
+  {&__pyx_kp_u_unknown_error_in_protocol_implem, __pyx_k_unknown_error_in_protocol_implem, sizeof(__pyx_k_unknown_error_in_protocol_implem), 0, 1, 0, 0},
+  {&__pyx_kp_u_unsupported_authentication_metho, __pyx_k_unsupported_authentication_metho, sizeof(__pyx_k_unsupported_authentication_metho), 0, 1, 0, 0},
+  {&__pyx_kp_u_unsupported_authentication_metho_2, __pyx_k_unsupported_authentication_metho_2, sizeof(__pyx_k_unsupported_authentication_metho_2), 0, 1, 0, 0},
+  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
+  {&__pyx_n_s_upper, __pyx_k_upper, sizeof(__pyx_k_upper), 0, 0, 1, 1},
+  {&__pyx_n_s_upper_inc, __pyx_k_upper_inc, sizeof(__pyx_k_upper_inc), 0, 0, 1, 1},
+  {&__pyx_n_s_user, __pyx_k_user, sizeof(__pyx_k_user), 0, 0, 1, 1},
+  {&__pyx_n_u_user, __pyx_k_user, sizeof(__pyx_k_user), 0, 1, 0, 1},
+  {&__pyx_kp_u_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0, 0},
+  {&__pyx_n_u_utf_8_2, __pyx_k_utf_8_2, sizeof(__pyx_k_utf_8_2), 0, 1, 0, 1},
+  {&__pyx_n_u_uuid, __pyx_k_uuid, sizeof(__pyx_k_uuid), 0, 1, 0, 1},
+  {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
+  {&__pyx_n_u_varbit, __pyx_k_varbit, sizeof(__pyx_k_varbit), 0, 1, 0, 1},
+  {&__pyx_n_u_varchar, __pyx_k_varchar, sizeof(__pyx_k_varchar), 0, 1, 0, 1},
+  {&__pyx_n_u_void, __pyx_k_void, sizeof(__pyx_k_void), 0, 1, 0, 1},
+  {&__pyx_n_u_vscii, __pyx_k_vscii, sizeof(__pyx_k_vscii), 0, 1, 0, 1},
+  {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1},
+  {&__pyx_n_s_wait, __pyx_k_wait, sizeof(__pyx_k_wait), 0, 0, 1, 1},
+  {&__pyx_n_s_wait_for, __pyx_k_wait_for, sizeof(__pyx_k_wait_for), 0, 0, 1, 1},
+  {&__pyx_n_s_wait_for_cancellation, __pyx_k_wait_for_cancellation, sizeof(__pyx_k_wait_for_cancellation), 0, 0, 1, 1},
+  {&__pyx_kp_u_waiter_is_not_done_while_handlin, __pyx_k_waiter_is_not_done_while_handlin, sizeof(__pyx_k_waiter_is_not_done_while_handlin), 0, 1, 0, 0},
+  {&__pyx_n_u_was, __pyx_k_was, sizeof(__pyx_k_was), 0, 1, 0, 1},
+  {&__pyx_n_s_weakref, __pyx_k_weakref, sizeof(__pyx_k_weakref), 0, 0, 1, 1},
+  {&__pyx_n_u_were, __pyx_k_were, sizeof(__pyx_k_were), 0, 1, 0, 1},
+  {&__pyx_n_u_win, __pyx_k_win, sizeof(__pyx_k_win), 0, 1, 0, 1},
+  {&__pyx_n_u_win1250, __pyx_k_win1250, sizeof(__pyx_k_win1250), 0, 1, 0, 1},
+  {&__pyx_n_u_win1251, __pyx_k_win1251, sizeof(__pyx_k_win1251), 0, 1, 0, 1},
+  {&__pyx_n_u_win1252, __pyx_k_win1252, sizeof(__pyx_k_win1252), 0, 1, 0, 1},
+  {&__pyx_n_u_win1253, __pyx_k_win1253, sizeof(__pyx_k_win1253), 0, 1, 0, 1},
+  {&__pyx_n_u_win1254, __pyx_k_win1254, sizeof(__pyx_k_win1254), 0, 1, 0, 1},
+  {&__pyx_n_u_win1255, __pyx_k_win1255, sizeof(__pyx_k_win1255), 0, 1, 0, 1},
+  {&__pyx_n_u_win1256, __pyx_k_win1256, sizeof(__pyx_k_win1256), 0, 1, 0, 1},
+  {&__pyx_n_u_win1257, __pyx_k_win1257, sizeof(__pyx_k_win1257), 0, 1, 0, 1},
+  {&__pyx_n_u_win1258, __pyx_k_win1258, sizeof(__pyx_k_win1258), 0, 1, 0, 1},
+  {&__pyx_n_u_win866, __pyx_k_win866, sizeof(__pyx_k_win866), 0, 1, 0, 1},
+  {&__pyx_n_u_win874, __pyx_k_win874, sizeof(__pyx_k_win874), 0, 1, 0, 1},
+  {&__pyx_n_u_win932, __pyx_k_win932, sizeof(__pyx_k_win932), 0, 1, 0, 1},
+  {&__pyx_n_u_win936, __pyx_k_win936, sizeof(__pyx_k_win936), 0, 1, 0, 1},
+  {&__pyx_n_u_win949, __pyx_k_win949, sizeof(__pyx_k_win949), 0, 1, 0, 1},
+  {&__pyx_n_u_win950, __pyx_k_win950, sizeof(__pyx_k_win950), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1250, __pyx_k_windows1250, sizeof(__pyx_k_windows1250), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1251, __pyx_k_windows1251, sizeof(__pyx_k_windows1251), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1252, __pyx_k_windows1252, sizeof(__pyx_k_windows1252), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1253, __pyx_k_windows1253, sizeof(__pyx_k_windows1253), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1254, __pyx_k_windows1254, sizeof(__pyx_k_windows1254), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1255, __pyx_k_windows1255, sizeof(__pyx_k_windows1255), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1256, __pyx_k_windows1256, sizeof(__pyx_k_windows1256), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1257, __pyx_k_windows1257, sizeof(__pyx_k_windows1257), 0, 1, 0, 1},
+  {&__pyx_n_u_windows1258, __pyx_k_windows1258, sizeof(__pyx_k_windows1258), 0, 1, 0, 1},
+  {&__pyx_n_u_windows866, __pyx_k_windows866, sizeof(__pyx_k_windows866), 0, 1, 0, 1},
+  {&__pyx_n_u_windows874, __pyx_k_windows874, sizeof(__pyx_k_windows874), 0, 1, 0, 1},
+  {&__pyx_n_u_windows932, __pyx_k_windows932, sizeof(__pyx_k_windows932), 0, 1, 0, 1},
+  {&__pyx_n_u_windows936, __pyx_k_windows936, sizeof(__pyx_k_windows936), 0, 1, 0, 1},
+  {&__pyx_n_u_windows949, __pyx_k_windows949, sizeof(__pyx_k_windows949), 0, 1, 0, 1},
+  {&__pyx_n_u_windows950, __pyx_k_windows950, sizeof(__pyx_k_windows950), 0, 1, 0, 1},
+  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
+  {&__pyx_n_s_writing_allowed, __pyx_k_writing_allowed, sizeof(__pyx_k_writing_allowed), 0, 0, 1, 1},
+  {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
+  {&__pyx_n_s_xformat, __pyx_k_xformat, sizeof(__pyx_k_xformat), 0, 0, 1, 1},
+  {&__pyx_n_u_xid, __pyx_k_xid, sizeof(__pyx_k_xid), 0, 1, 0, 1},
+  {&__pyx_n_u_xml, __pyx_k_xml, sizeof(__pyx_k_xml), 0, 1, 0, 1},
+  {&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1},
+  {0, 0, 0, 0, 0, 0, 0}
+};
+static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
+  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 72, __pyx_L1_error)
+  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(1, 103, __pyx_L1_error)
+  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(1, 104, __pyx_L1_error)
+  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(2, 2, __pyx_L1_error)
+  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(3, 68, __pyx_L1_error)
+  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(3, 139, __pyx_L1_error)
+  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(3, 147, __pyx_L1_error)
+  __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(3, 413, __pyx_L1_error)
+  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(3, 509, __pyx_L1_error)
+  __pyx_builtin_reversed = __Pyx_GetBuiltinName(__pyx_n_s_reversed); if (!__pyx_builtin_reversed) __PYX_ERR(4, 368, __pyx_L1_error)
+  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(5, 129, __pyx_L1_error)
+  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(5, 261, __pyx_L1_error)
+  __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s_AssertionError); if (!__pyx_builtin_AssertionError) __PYX_ERR(6, 147, __pyx_L1_error)
+  __pyx_builtin_BufferError = __Pyx_GetBuiltinName(__pyx_n_s_BufferError); if (!__pyx_builtin_BufferError) __PYX_ERR(6, 284, __pyx_L1_error)
+  return 0;
+  __pyx_L1_error:;
+  return -1;
+}
+
+static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__3);
+  __Pyx_GIVEREF(__pyx_tuple__3);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__4);
+  __Pyx_GIVEREF(__pyx_tuple__4);
+
+  /* "asyncpg/protocol/codecs/base.pyx":159
+ *         count = len(obj)
+ *         if count > _MAXINT32:
+ *             raise ValueError('too many elements in composite type record')             # <<<<<<<<<<<<<<
+ * 
+ *         elem_data = WriteBuffer.new()
+ */
+  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_too_many_elements_in_composite_t); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(3, 159, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__5);
+  __Pyx_GIVEREF(__pyx_tuple__5);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__6);
+  __Pyx_GIVEREF(__pyx_tuple__6);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__7);
+  __Pyx_GIVEREF(__pyx_tuple__7);
+
+  /* "asyncpg/protocol/codecs/base.pyx":467
+ *                 # Canonicalize type name to "elemtype[]"
+ *                 if name.startswith('_'):
+ *                     name = name[1:]             # <<<<<<<<<<<<<<
+ *                 name = '{}[]'.format(name)
+ * 
+ */
+  __pyx_slice__8 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__8)) __PYX_ERR(3, 467, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_slice__8);
+  __Pyx_GIVEREF(__pyx_slice__8);
+
+  /* "asyncpg/protocol/codecs/base.pyx":809
+ *     kind = 'scalar'
+ * 
+ *     codec = Codec(INVALIDOID)             # <<<<<<<<<<<<<<
+ *     codec.init(name, None, kind, CODEC_C, format, PG_XFORMAT_OBJECT,
+ *                encode, decode, None, None, None, None, None, None, 0)
+ */
+  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(3, 809, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__15);
+  __Pyx_GIVEREF(__pyx_tuple__15);
+
+  /* "asyncpg/protocol/codecs/array.pyx":59
+ * 
+ *     if mylen > _MAXINT32:
+ *         raise ValueError('too many elements in array value')             # <<<<<<<<<<<<<<
+ * 
+ *     if ndims[0] > ARRAY_MAXDIM:
+ */
+  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_u_too_many_elements_in_array_value); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(4, 59, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__16);
+  __Pyx_GIVEREF(__pyx_tuple__16);
+
+  /* "asyncpg/protocol/codecs/array.pyx":73
+ *                 elemlen = len(elem)
+ *                 if elemlen > _MAXINT32:
+ *                     raise ValueError('too many elements in array value')             # <<<<<<<<<<<<<<
+ *                 ndims[0] += 1
+ *                 _get_array_shape(elem, dims, ndims)
+ */
+  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_u_too_many_elements_in_array_value); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(4, 73, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__16);
+  __Pyx_GIVEREF(__pyx_tuple__16);
+
+  /* "asyncpg/protocol/codecs/array.pyx":78
+ *             else:
+ *                 if len(elem) != elemlen:
+ *                     raise ValueError('non-homogeneous array')             # <<<<<<<<<<<<<<
+ *         else:
+ *             if elemlen >= 0:
+ */
+  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_u_non_homogeneous_array); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(4, 78, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__17);
+  __Pyx_GIVEREF(__pyx_tuple__17);
+
+  /* "asyncpg/protocol/codecs/array.pyx":81
+ *         else:
+ *             if elemlen >= 0:
+ *                 raise ValueError('non-homogeneous array')             # <<<<<<<<<<<<<<
+ *             else:
+ *                 elemlen = -1
+ */
+  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_u_non_homogeneous_array); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(4, 81, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__17);
+  __Pyx_GIVEREF(__pyx_tuple__17);
+
+  /* "asyncpg/protocol/codecs/array.pyx":481
+ *         ptr = apg_parse_int32(ptr, &ubound)
+ *         if ptr == NULL:
+ *             raise ValueError('missing array dimension value')             # <<<<<<<<<<<<<<
+ * 
+ *         if ptr[0] == ':':
+ */
+  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_u_missing_array_dimension_value); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(4, 481, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__19);
+  __Pyx_GIVEREF(__pyx_tuple__19);
+
+  /* "asyncpg/protocol/codecs/array.pyx":490
+ *             ptr = apg_parse_int32(ptr, &ubound)
+ *             if ptr == NULL:
+ *                 raise ValueError('missing array dimension value')             # <<<<<<<<<<<<<<
+ *         else:
+ *             lbound = 1
+ */
+  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_u_missing_array_dimension_value); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(4, 490, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__19);
+  __Pyx_GIVEREF(__pyx_tuple__19);
+
+  /* "asyncpg/protocol/codecs/array.pyx":495
+ * 
+ *         if ptr[0] != ']':
+ *             raise ValueError('missing \']\' after array dimensions')             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1  # ']'
+ */
+  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_u_missing_after_array_dimensions); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(4, 495, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__20);
+  __Pyx_GIVEREF(__pyx_tuple__20);
+
+  /* "asyncpg/protocol/codecs/array.pyx":505
+ *         # If dimensions were given, the '=' token is expected.
+ *         if ptr[0] != '=':
+ *             raise ValueError('missing \'=\' after array dimensions')             # <<<<<<<<<<<<<<
+ * 
+ *         ptr += 1  # '='
+ */
+  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_u_missing_after_array_dimensions_2); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(4, 505, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__21);
+  __Pyx_GIVEREF(__pyx_tuple__21);
+
+  /* "asyncpg/protocol/codecs/array.pyx":520
+ * 
+ *         if inferred_ndims != ndims:
+ *             raise ValueError(             # <<<<<<<<<<<<<<
+ *                 'specified array dimensions do not match array content')
+ * 
+ */
+  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_u_specified_array_dimensions_do_no); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(4, 520, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__22);
+  __Pyx_GIVEREF(__pyx_tuple__22);
+
+  /* "asyncpg/protocol/codecs/array.pyx":525
+ *         for i in range(ndims):
+ *             if inferred_dims[i] != dims[i]:
+ *                 raise ValueError(             # <<<<<<<<<<<<<<
+ *                     'specified array dimensions do not match array content')
+ *     else:
+ */
+  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_u_specified_array_dimensions_do_no); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(4, 525, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__22);
+  __Pyx_GIVEREF(__pyx_tuple__22);
+
+  /* "asyncpg/protocol/codecs/array.pyx":697
+ *         while not end_of_item:
+ *             if ptr[0] == '\0':
+ *                 raise ValueError('unexpected end of string')             # <<<<<<<<<<<<<<
+ * 
+ *             elif ptr[0] == '"':
+ */
+  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_unexpected_end_of_string); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(4, 697, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__23);
+  __Pyx_GIVEREF(__pyx_tuple__23);
+
+  /* "asyncpg/protocol/codecs/array.pyx":722
+ *                     ptr += 1
+ *                 else:
+ *                     raise ValueError('unexpected end of string')             # <<<<<<<<<<<<<<
+ * 
+ *             elif in_quotes:
+ */
+  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_unexpected_end_of_string); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(4, 722, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__23);
+  __Pyx_GIVEREF(__pyx_tuple__23);
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":158
+ *                     value_repr = repr(arg)
+ *                     if len(value_repr) > 40:
+ *                         value_repr = value_repr[:40] + '...'             # <<<<<<<<<<<<<<
+ * 
+ *                     raise exceptions.DataError(
+ */
+  __pyx_slice__27 = PySlice_New(Py_None, __pyx_int_40, Py_None); if (unlikely(!__pyx_slice__27)) __PYX_ERR(6, 158, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_slice__27);
+  __Pyx_GIVEREF(__pyx_slice__27);
+
+  /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ */
+  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(2, 2, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__29);
+  __Pyx_GIVEREF(__pyx_tuple__29);
+
+  /* "(tree fragment)":4
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ *     raise TypeError("no default __reduce__ due to non-trivial __cinit__")             # <<<<<<<<<<<<<<
+ */
+  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(2, 4, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__30);
+  __Pyx_GIVEREF(__pyx_tuple__30);
+
+  /* "asyncpg/protocol/protocol.pyx":341
+ *                 self.resume_reading()
+ * 
+ *                 with timer:             # <<<<<<<<<<<<<<
+ *                     buffer, done, status_msg = await waiter
+ * 
+ */
+  __pyx_tuple__31 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 341, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__31);
+  __Pyx_GIVEREF(__pyx_tuple__31);
+
+  /* "asyncpg/protocol/protocol.pyx":348
+ *                 if buffer:
+ *                     try:
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await asyncio.wait_for(
+ *                                 sink(buffer),
+ */
+  __pyx_tuple__31 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 348, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__31);
+  __Pyx_GIVEREF(__pyx_tuple__31);
+
+  /* "asyncpg/protocol/protocol.pyx":433
+ * 
+ *                     if wbuf.len() >= _COPY_BUFFER_SIZE:
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await self.writing_allowed.wait()
+ *                         self._write_copy_data_msg(wbuf)
+ */
+  __pyx_tuple__31 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 433, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__31);
+  __Pyx_GIVEREF(__pyx_tuple__31);
+
+  /* "asyncpg/protocol/protocol.pyx":446
+ *                     aiter = reader.__aiter__
+ *                 except AttributeError:
+ *                     raise TypeError('reader is not an asynchronous iterable')             # <<<<<<<<<<<<<<
+ *                 else:
+ *                     iterator = aiter()
+ */
+  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_u_reader_is_not_an_asynchronous_it); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 446, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__32);
+  __Pyx_GIVEREF(__pyx_tuple__32);
+
+  /* "asyncpg/protocol/protocol.pyx":454
+ *                         # We rely on protocol flow control to moderate the
+ *                         # rate of data messages.
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             await self.writing_allowed.wait()
+ *                         with timer:
+ */
+  __pyx_tuple__31 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 454, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__31);
+  __Pyx_GIVEREF(__pyx_tuple__31);
+
+  /* "asyncpg/protocol/protocol.pyx":456
+ *                         with timer:
+ *                             await self.writing_allowed.wait()
+ *                         with timer:             # <<<<<<<<<<<<<<
+ *                             chunk = await asyncio.wait_for(
+ *                                 iterator.__anext__(),
+ */
+  __pyx_tuple__31 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 456, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__31);
+  __Pyx_GIVEREF(__pyx_tuple__31);
+
+  /* "asyncpg/protocol/pgtypes.pxi":102
+ * DEF REGROLEOID = 4096
+ * 
+ * cdef ARRAY_TYPES = (_TEXTOID, _OIDOID,)             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_OID_MAP = {
+ */
+  __pyx_tuple__33 = PyTuple_Pack(2, __pyx_int_1009, __pyx_int_1028); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(19, 102, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__33);
+  __Pyx_GIVEREF(__pyx_tuple__33);
+
+  /* "asyncpg/protocol/protocol.pyx":920
+ * 
+ * class Timer:
+ *     def __init__(self, budget):             # <<<<<<<<<<<<<<
+ *         self._budget = budget
+ *         self._started = 0
+ */
+  __pyx_tuple__34 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_budget); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 920, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__34);
+  __Pyx_GIVEREF(__pyx_tuple__34);
+  __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_asyncpg_protocol_protocol_pyx, __pyx_n_s_init, 920, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 920, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":924
+ *         self._started = 0
+ * 
+ *     def __enter__(self):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._started = time.monotonic()
+ */
+  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 924, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__36);
+  __Pyx_GIVEREF(__pyx_tuple__36);
+  __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_asyncpg_protocol_protocol_pyx, __pyx_n_s_enter, 924, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 924, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":928
+ *             self._started = time.monotonic()
+ * 
+ *     def __exit__(self, et, e, tb):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._budget -= time.monotonic() - self._started
+ */
+  __pyx_tuple__38 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_et, __pyx_n_s_e, __pyx_n_s_tb); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 928, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__38);
+  __Pyx_GIVEREF(__pyx_tuple__38);
+  __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__38, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_asyncpg_protocol_protocol_pyx, __pyx_n_s_exit, 928, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 928, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":932
+ *             self._budget -= time.monotonic() - self._started
+ * 
+ *     def get_remaining_budget(self):             # <<<<<<<<<<<<<<
+ *         return self._budget
+ * 
+ */
+  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 932, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__40);
+  __Pyx_GIVEREF(__pyx_tuple__40);
+  __pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__40, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_asyncpg_protocol_protocol_pyx, __pyx_n_s_get_remaining_budget, 932, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(0, 932, __pyx_L1_error)
+
+  /* "asyncpg/protocol/protocol.pyx":940
+ * 
+ * 
+ * def _create_record(object mapping, tuple elems):             # <<<<<<<<<<<<<<
+ *     # Exposed only for testing purposes.
+ * 
+ */
+  __pyx_tuple__42 = PyTuple_Pack(6, __pyx_n_s_mapping, __pyx_n_s_elems, __pyx_n_s_rec, __pyx_n_s_i, __pyx_n_s_desc, __pyx_n_s_elem); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 940, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__42);
+  __Pyx_GIVEREF(__pyx_tuple__42);
+  __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__42, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_asyncpg_protocol_protocol_pyx, __pyx_n_s_create_record, 940, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 940, __pyx_L1_error)
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x7336a95:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+  __pyx_tuple__44 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__44);
+  __Pyx_GIVEREF(__pyx_tuple__44);
+  __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__44, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_DataCodecConfig, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __pyx_tuple__46 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__46);
+  __Pyx_GIVEREF(__pyx_tuple__46);
+  __pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_CoreProtocol, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __pyx_tuple__48 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_tuple__48);
+  __Pyx_GIVEREF(__pyx_tuple__48);
+  __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__48, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_BaseProtocol, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
+  __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type;
+  __pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type;
+  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
+  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_16 = PyInt_FromLong(16); if (unlikely(!__pyx_int_16)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_17 = PyInt_FromLong(17); if (unlikely(!__pyx_int_17)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_18 = PyInt_FromLong(18); if (unlikely(!__pyx_int_18)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_19 = PyInt_FromLong(19); if (unlikely(!__pyx_int_19)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_21 = PyInt_FromLong(21); if (unlikely(!__pyx_int_21)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_23 = PyInt_FromLong(23); if (unlikely(!__pyx_int_23)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_24 = PyInt_FromLong(24); if (unlikely(!__pyx_int_24)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_25 = PyInt_FromLong(25); if (unlikely(!__pyx_int_25)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_26 = PyInt_FromLong(26); if (unlikely(!__pyx_int_26)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_27 = PyInt_FromLong(27); if (unlikely(!__pyx_int_27)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_28 = PyInt_FromLong(28); if (unlikely(!__pyx_int_28)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_29 = PyInt_FromLong(29); if (unlikely(!__pyx_int_29)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_32 = PyInt_FromLong(32); if (unlikely(!__pyx_int_32)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_40 = PyInt_FromLong(40); if (unlikely(!__pyx_int_40)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_114 = PyInt_FromLong(114); if (unlikely(!__pyx_int_114)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_142 = PyInt_FromLong(142); if (unlikely(!__pyx_int_142)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_194 = PyInt_FromLong(194); if (unlikely(!__pyx_int_194)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_210 = PyInt_FromLong(210); if (unlikely(!__pyx_int_210)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_325 = PyInt_FromLong(325); if (unlikely(!__pyx_int_325)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_600 = PyInt_FromLong(600); if (unlikely(!__pyx_int_600)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_601 = PyInt_FromLong(601); if (unlikely(!__pyx_int_601)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_602 = PyInt_FromLong(602); if (unlikely(!__pyx_int_602)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_603 = PyInt_FromLong(603); if (unlikely(!__pyx_int_603)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_604 = PyInt_FromLong(604); if (unlikely(!__pyx_int_604)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_628 = PyInt_FromLong(628); if (unlikely(!__pyx_int_628)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_650 = PyInt_FromLong(650); if (unlikely(!__pyx_int_650)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_700 = PyInt_FromLong(700); if (unlikely(!__pyx_int_700)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_701 = PyInt_FromLong(701); if (unlikely(!__pyx_int_701)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_702 = PyInt_FromLong(702); if (unlikely(!__pyx_int_702)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_703 = PyInt_FromLong(703); if (unlikely(!__pyx_int_703)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_704 = PyInt_FromLong(704); if (unlikely(!__pyx_int_704)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_705 = PyInt_FromLong(705); if (unlikely(!__pyx_int_705)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_718 = PyInt_FromLong(718); if (unlikely(!__pyx_int_718)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_774 = PyInt_FromLong(774); if (unlikely(!__pyx_int_774)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_790 = PyInt_FromLong(790); if (unlikely(!__pyx_int_790)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_829 = PyInt_FromLong(829); if (unlikely(!__pyx_int_829)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_869 = PyInt_FromLong(869); if (unlikely(!__pyx_int_869)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1009 = PyInt_FromLong(1009); if (unlikely(!__pyx_int_1009)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1028 = PyInt_FromLong(1028); if (unlikely(!__pyx_int_1028)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1033 = PyInt_FromLong(1033); if (unlikely(!__pyx_int_1033)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1042 = PyInt_FromLong(1042); if (unlikely(!__pyx_int_1042)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1043 = PyInt_FromLong(1043); if (unlikely(!__pyx_int_1043)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1082 = PyInt_FromLong(1082); if (unlikely(!__pyx_int_1082)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1083 = PyInt_FromLong(1083); if (unlikely(!__pyx_int_1083)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1114 = PyInt_FromLong(1114); if (unlikely(!__pyx_int_1114)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1184 = PyInt_FromLong(1184); if (unlikely(!__pyx_int_1184)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1186 = PyInt_FromLong(1186); if (unlikely(!__pyx_int_1186)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1266 = PyInt_FromLong(1266); if (unlikely(!__pyx_int_1266)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1560 = PyInt_FromLong(1560); if (unlikely(!__pyx_int_1560)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1562 = PyInt_FromLong(1562); if (unlikely(!__pyx_int_1562)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1700 = PyInt_FromLong(1700); if (unlikely(!__pyx_int_1700)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_1790 = PyInt_FromLong(1790); if (unlikely(!__pyx_int_1790)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2202 = PyInt_FromLong(2202); if (unlikely(!__pyx_int_2202)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2203 = PyInt_FromLong(2203); if (unlikely(!__pyx_int_2203)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2204 = PyInt_FromLong(2204); if (unlikely(!__pyx_int_2204)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2205 = PyInt_FromLong(2205); if (unlikely(!__pyx_int_2205)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2206 = PyInt_FromLong(2206); if (unlikely(!__pyx_int_2206)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2249 = PyInt_FromLong(2249); if (unlikely(!__pyx_int_2249)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2275 = PyInt_FromLong(2275); if (unlikely(!__pyx_int_2275)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2276 = PyInt_FromLong(2276); if (unlikely(!__pyx_int_2276)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2277 = PyInt_FromLong(2277); if (unlikely(!__pyx_int_2277)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2278 = PyInt_FromLong(2278); if (unlikely(!__pyx_int_2278)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2279 = PyInt_FromLong(2279); if (unlikely(!__pyx_int_2279)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2280 = PyInt_FromLong(2280); if (unlikely(!__pyx_int_2280)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2281 = PyInt_FromLong(2281); if (unlikely(!__pyx_int_2281)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2282 = PyInt_FromLong(2282); if (unlikely(!__pyx_int_2282)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2283 = PyInt_FromLong(2283); if (unlikely(!__pyx_int_2283)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2776 = PyInt_FromLong(2776); if (unlikely(!__pyx_int_2776)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2950 = PyInt_FromLong(2950); if (unlikely(!__pyx_int_2950)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_2970 = PyInt_FromLong(2970); if (unlikely(!__pyx_int_2970)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3115 = PyInt_FromLong(3115); if (unlikely(!__pyx_int_3115)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3220 = PyInt_FromLong(3220); if (unlikely(!__pyx_int_3220)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3310 = PyInt_FromLong(3310); if (unlikely(!__pyx_int_3310)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3361 = PyInt_FromLong(3361); if (unlikely(!__pyx_int_3361)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3402 = PyInt_FromLong(3402); if (unlikely(!__pyx_int_3402)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3500 = PyInt_FromLong(3500); if (unlikely(!__pyx_int_3500)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3614 = PyInt_FromLong(3614); if (unlikely(!__pyx_int_3614)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3615 = PyInt_FromLong(3615); if (unlikely(!__pyx_int_3615)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3642 = PyInt_FromLong(3642); if (unlikely(!__pyx_int_3642)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3734 = PyInt_FromLong(3734); if (unlikely(!__pyx_int_3734)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3769 = PyInt_FromLong(3769); if (unlikely(!__pyx_int_3769)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3802 = PyInt_FromLong(3802); if (unlikely(!__pyx_int_3802)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3831 = PyInt_FromLong(3831); if (unlikely(!__pyx_int_3831)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_3838 = PyInt_FromLong(3838); if (unlikely(!__pyx_int_3838)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_4089 = PyInt_FromLong(4089); if (unlikely(!__pyx_int_4089)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_4096 = PyInt_FromLong(4096); if (unlikely(!__pyx_int_4096)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_524288 = PyInt_FromLong(524288L); if (unlikely(!__pyx_int_524288)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_26708044 = PyInt_FromLong(26708044L); if (unlikely(!__pyx_int_26708044)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_81883559 = PyInt_FromLong(81883559L); if (unlikely(!__pyx_int_81883559)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_int_120810133 = PyInt_FromLong(120810133L); if (unlikely(!__pyx_int_120810133)) __PYX_ERR(0, 1, __pyx_L1_error)
+  return 0;
+  __pyx_L1_error:;
+  return -1;
+}
+
+static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
+static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
+
+static int __Pyx_modinit_global_init_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
+  /*--- Global init code ---*/
+  __pyx_v_7asyncpg_8protocol_8protocol_ARRAY_TYPES = Py_None; Py_INCREF(Py_None);
+  __pyx_7genexpr__pyx_v_7asyncpg_8protocol_8protocol_k = Py_None; Py_INCREF(Py_None);
+  __pyx_7genexpr__pyx_v_7asyncpg_8protocol_8protocol_v = Py_None; Py_INCREF(Py_None);
+  __pyx_v_7asyncpg_8protocol_8protocol_ENCODINGS_MAP = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  __pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  __pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  __pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k = Py_None; Py_INCREF(Py_None);
+  __pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v = Py_None; Py_INCREF(Py_None);
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+static int __Pyx_modinit_variable_export_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
+  /*--- Variable export code ---*/
+  if (__Pyx_ExportVoidPtr(__pyx_n_s_ARRAY_TYPES, (void *)&__pyx_v_7asyncpg_8protocol_8protocol_ARRAY_TYPES, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static int __Pyx_modinit_function_export_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
+  /*--- Function export code ---*/
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+static int __Pyx_modinit_type_init_code(void) {
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
+  /*--- Type init code ---*/
+  __pyx_vtabptr_7asyncpg_8protocol_8protocol_Codec = &__pyx_vtable_7asyncpg_8protocol_8protocol_Codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.init = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, PyObject *, PyObject *, PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, PyObject *, PyObject *, PyObject *, Py_UCS4))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_init;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode_scalar = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_scalar;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode_array = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode_array_text = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_array_text;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode_range = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_range;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode_composite = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_composite;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode_in_python = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode_in_python;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode_scalar = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_scalar;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode_array = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode_array_text = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_array_text;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode_range = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_range;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode_composite = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_composite;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode_in_python = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode_in_python;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.encode = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_encode;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.decode = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_decode;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.has_encoder = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_encoder;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.has_decoder = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_has_decoder;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.is_binary = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_is_binary;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.copy = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_copy;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.new_array_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(uint32_t, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *, Py_UCS4))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_array_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.new_range_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(uint32_t, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_range_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.new_composite_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(uint32_t, PyObject *, PyObject *, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, PyObject *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_composite_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_Codec.new_python_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(uint32_t, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, __pyx_t_7asyncpg_8protocol_8protocol_encode_func, __pyx_t_7asyncpg_8protocol_8protocol_decode_func, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat))__pyx_f_7asyncpg_8protocol_8protocol_5Codec_new_python_codec;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol_Codec) < 0) __PYX_ERR(3, 19, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol_Codec.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol_Codec.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol_Codec.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol_Codec.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_8protocol_8protocol_Codec.tp_dict, __pyx_vtabptr_7asyncpg_8protocol_8protocol_Codec) < 0) __PYX_ERR(3, 19, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_Codec, (PyObject *)&__pyx_type_7asyncpg_8protocol_8protocol_Codec) < 0) __PYX_ERR(3, 19, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_8protocol_8protocol_Codec) < 0) __PYX_ERR(3, 19, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_8protocol_8protocol_Codec = &__pyx_type_7asyncpg_8protocol_8protocol_Codec;
+  __pyx_vtabptr_7asyncpg_8protocol_8protocol_DataCodecConfig = &__pyx_vtable_7asyncpg_8protocol_8protocol_DataCodecConfig;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_DataCodecConfig.get_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, uint32_t, enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat))__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_DataCodecConfig.get_any_local_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_DataCodecConfig *, uint32_t))__pyx_f_7asyncpg_8protocol_8protocol_15DataCodecConfig_get_any_local_codec;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig) < 0) __PYX_ERR(3, 422, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig.tp_getattro = __Pyx_PyObject_GenericGetAttr;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig.tp_dict, __pyx_vtabptr_7asyncpg_8protocol_8protocol_DataCodecConfig) < 0) __PYX_ERR(3, 422, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_DataCodecConfig, (PyObject *)&__pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig) < 0) __PYX_ERR(3, 422, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig) < 0) __PYX_ERR(3, 422, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_8protocol_8protocol_DataCodecConfig = &__pyx_type_7asyncpg_8protocol_8protocol_DataCodecConfig;
+  __pyx_t_1 = PyImport_ImportModule("asyncpg.pgproto.pgproto"); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext = __Pyx_ImportType(__pyx_t_1, "asyncpg.pgproto.pgproto", "CodecContext", sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext = (struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_CodecContext*)__Pyx_GetVtable(__pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext->tp_dict); if (unlikely(!__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_vtabptr_7asyncpg_8protocol_8protocol_ConnectionSettings = &__pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.__pyx_base = *__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_CodecContext;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.__pyx_base.get_text_codec = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_text_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.__pyx_base.is_encoding_utf8 = (PyObject *(*)(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_is_encoding_utf8;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.add_setting = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_setting;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.register_data_types = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_register_data_types;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.add_python_codec = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_add_python_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.remove_python_codec = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_remove_python_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.clear_type_cache = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_clear_type_cache;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.set_builtin_type_codec = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_set_builtin_type_codec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_ConnectionSettings.get_data_codec = (struct __pyx_obj_7asyncpg_8protocol_8protocol_Codec *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_ConnectionSettings *, uint32_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec *__pyx_optional_args))__pyx_f_7asyncpg_8protocol_8protocol_18ConnectionSettings_get_data_codec;
+  __pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings.tp_base = __pyx_ptype_7asyncpg_7pgproto_7pgproto_CodecContext;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings) < 0) __PYX_ERR(1, 12, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings.tp_print = 0;
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings.tp_dict, __pyx_vtabptr_7asyncpg_8protocol_8protocol_ConnectionSettings) < 0) __PYX_ERR(1, 12, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ConnectionSettings, (PyObject *)&__pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings) < 0) __PYX_ERR(1, 12, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings) < 0) __PYX_ERR(1, 12, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_8protocol_8protocol_ConnectionSettings = &__pyx_type_7asyncpg_8protocol_8protocol_ConnectionSettings;
+  __pyx_vtabptr_7asyncpg_8protocol_8protocol_CoreProtocol = &__pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__auth = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__auth;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__prepare = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__prepare;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__bind_execute = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind_execute;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__bind_execute_many = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind_execute_many;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__close_stmt_portal = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__close_stmt_portal;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__simple_query = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__simple_query;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__bind = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__bind;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__copy_out = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_out;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__copy_out_data = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_out_data;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__copy_in = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_in;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._process__copy_in_data = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__process__copy_in_data;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_authentication = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_authentication;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_parameter_status = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_parameter_status;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_notification = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_notification;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_backend_key_data = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_backend_key_data;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_ready_for_query = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_ready_for_query;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_data_msgs = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_data_msgs;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_copy_data_msgs = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_copy_data_msgs;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_error_response = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_error_response;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._parse_msg_command_complete = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__parse_msg_command_complete;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._write_copy_data_msg = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_data_msg;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._write_copy_done_msg = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_done_msg;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._write_copy_fail_msg = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write_copy_fail_msg;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._auth_password_message_cleartext = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__auth_password_message_cleartext;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._auth_password_message_md5 = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__auth_password_message_md5;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._write = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__write;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._read_server_messages = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__read_server_messages;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._push_result = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__push_result;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._reset_result = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__reset_result;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._set_state = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__set_state;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._ensure_connected = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__ensure_connected;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._build_bind_message = (struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__build_bind_message;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._connect = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__connect;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._prepare = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__prepare;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._send_bind_message = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__send_bind_message;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._bind_execute = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, int32_t))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind_execute;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._bind_execute_many = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind_execute_many;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._bind = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__bind;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._execute = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, int32_t))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__execute;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._close = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, int))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__close;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._simple_query = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__simple_query;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._copy_out = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__copy_out;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._copy_in = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__copy_in;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._terminate = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__terminate;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._decode_row = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char const *, Py_ssize_t))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__decode_row;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._on_result = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_result;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._on_notification = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_notification;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._on_notice = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_notice;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._set_server_parameter = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__set_server_parameter;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_CoreProtocol._on_connection_lost = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12CoreProtocol__on_connection_lost;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol) < 0) __PYX_ERR(5, 11, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol.tp_getattro = __Pyx_PyObject_GenericGetAttr;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol.tp_dict, __pyx_vtabptr_7asyncpg_8protocol_8protocol_CoreProtocol) < 0) __PYX_ERR(5, 11, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_CoreProtocol, (PyObject *)&__pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol) < 0) __PYX_ERR(5, 11, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol) < 0) __PYX_ERR(5, 11, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_8protocol_8protocol_CoreProtocol = &__pyx_type_7asyncpg_8protocol_8protocol_CoreProtocol;
+  __pyx_vtabptr_7asyncpg_8protocol_8protocol_PreparedStatementState = &__pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._encode_bind_msg = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__encode_bind_msg;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._init_codecs = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, int __pyx_skip_dispatch))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__init_codecs;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._ensure_rows_decoder = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_rows_decoder;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._ensure_args_encoder = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__ensure_args_encoder;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._set_row_desc = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_row_desc;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._set_args_desc = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__set_args_desc;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_PreparedStatementState._decode_row = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_PreparedStatementState *, char const *, Py_ssize_t))__pyx_f_7asyncpg_8protocol_8protocol_22PreparedStatementState__decode_row;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState) < 0) __PYX_ERR(6, 12, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState.tp_dict, __pyx_vtabptr_7asyncpg_8protocol_8protocol_PreparedStatementState) < 0) __PYX_ERR(6, 12, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_PreparedStatementState, (PyObject *)&__pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState) < 0) __PYX_ERR(6, 12, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState) < 0) __PYX_ERR(6, 12, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_8protocol_8protocol_PreparedStatementState = &__pyx_type_7asyncpg_8protocol_8protocol_PreparedStatementState;
+  __pyx_vtabptr_7asyncpg_8protocol_8protocol_BaseProtocol = &__pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base = *__pyx_vtabptr_7asyncpg_8protocol_8protocol_CoreProtocol;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._write = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__write;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._decode_row = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, char const *, Py_ssize_t))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__decode_row;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._on_result = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._on_notification = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_notification;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._on_notice = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_notice;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._set_server_parameter = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__set_server_parameter;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.__pyx_base._on_connection_lost = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_CoreProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_connection_lost;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.get_connection = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_get_connection;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._get_timeout_impl = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__get_timeout_impl;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._check_state = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__check_state;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._new_waiter = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__new_waiter;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._coreproto_error = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__coreproto_error;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__connect = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__connect;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__prepare = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__prepare;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__bind_and_exec = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__bind_and_exec;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__close_stmt_or_portal = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__close_stmt_or_portal;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__simple_query = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__simple_query;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__bind = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__bind;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__copy_out = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__copy_out;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._on_result__copy_in = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__on_result__copy_in;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._handle_waiter_on_connection_lost = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *, PyObject *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__handle_waiter_on_connection_lost;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol._dispatch_result = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol__dispatch_result;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.resume_reading = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_resume_reading;
+  __pyx_vtable_7asyncpg_8protocol_8protocol_BaseProtocol.pause_reading = (PyObject *(*)(struct __pyx_obj_7asyncpg_8protocol_8protocol_BaseProtocol *))__pyx_f_7asyncpg_8protocol_8protocol_12BaseProtocol_pause_reading;
+  __pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol.tp_base = __pyx_ptype_7asyncpg_8protocol_8protocol_CoreProtocol;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol.tp_getattro = __Pyx_PyObject_GenericGetAttr;
+  }
+  if (__Pyx_SetVtable(__pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol.tp_dict, __pyx_vtabptr_7asyncpg_8protocol_8protocol_BaseProtocol) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
+  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BaseProtocol, (PyObject *)&__pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
+  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol = &__pyx_type_7asyncpg_8protocol_8protocol_BaseProtocol;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare) < 0) __PYX_ERR(0, 141, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct__prepare;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute) < 0) __PYX_ERR(0, 166, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_1_bind_execute;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many) < 0) __PYX_ERR(0, 199, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_2_bind_execute_many;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr) < 0) __PYX_ERR(0, 214, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_3_genexpr;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind) < 0) __PYX_ERR(0, 235, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_4_bind;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute) < 0) __PYX_ERR(0, 264, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_5_execute;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query) < 0) __PYX_ERR(0, 294, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_6_query;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out) < 0) __PYX_ERR(0, 319, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_7_copy_out;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in) < 0) __PYX_ERR(0, 374, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_8_copy_in;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement) < 0) __PYX_ERR(0, 493, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_9_close_statement;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close) < 0) __PYX_ERR(0, 533, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_10_close;
+  if (PyType_Ready(&__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation) < 0) __PYX_ERR(0, 669, __pyx_L1_error)
+  __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation.tp_print = 0;
+  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation.tp_dictoffset && __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation.tp_getattro == PyObject_GenericGetAttr)) {
+    __pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+  }
+  __pyx_ptype_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation = &__pyx_type_7asyncpg_8protocol_8protocol___pyx_scope_struct_11__wait_for_cancellation;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static int __Pyx_modinit_type_import_code(void) {
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
+  /*--- Type import code ---*/
+  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(16, 9, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", 
+  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
+  sizeof(PyTypeObject),
+  #else
+  sizeof(PyHeapTypeObject),
+  #endif
+  __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(16, 9, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(17, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(17, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(18, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(18, 15, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyImport_ImportModule("asyncpg.pgproto.pgproto"); if (unlikely(!__pyx_t_1)) __PYX_ERR(15, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer = __Pyx_ImportType(__pyx_t_1, "asyncpg.pgproto.pgproto", "WriteBuffer", sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer) __PYX_ERR(15, 8, __pyx_L1_error)
+  __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer = (struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer*)__Pyx_GetVtable(__pyx_ptype_7asyncpg_7pgproto_7pgproto_WriteBuffer->tp_dict); if (unlikely(!__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer)) __PYX_ERR(15, 8, __pyx_L1_error)
+  __pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer = __Pyx_ImportType(__pyx_t_1, "asyncpg.pgproto.pgproto", "ReadBuffer", sizeof(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_ReadBuffer), __Pyx_ImportType_CheckSize_Warn);
+   if (!__pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer) __PYX_ERR(15, 62, __pyx_L1_error)
+  __pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer = (struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_ReadBuffer*)__Pyx_GetVtable(__pyx_ptype_7asyncpg_7pgproto_7pgproto_ReadBuffer->tp_dict); if (unlikely(!__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_ReadBuffer)) __PYX_ERR(15, 62, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+static int __Pyx_modinit_variable_import_code(void) {
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
+  /*--- Variable import code ---*/
+  __Pyx_RefNannyFinishContext();
+  return 0;
+}
+
+static int __Pyx_modinit_function_import_code(void) {
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
+  /*--- Function import code ---*/
+  __pyx_t_1 = PyImport_ImportModule("asyncpg.pgproto.pgproto"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "frb_check", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_frb_check, "PyObject *(struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *, Py_ssize_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "date_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "date_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "date_encode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_date_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "date_decode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_date_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timestamp_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timestamp_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timestamp_encode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timestamp_decode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timestamp_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timestamptz_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timestamptz_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timestamptz_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "time_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "time_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "time_encode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_time_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "time_decode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_time_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timetz_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timetz_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timetz_encode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "timetz_decode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_timetz_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "interval_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "interval_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "interval_encode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_interval_encode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "interval_decode_tuple", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_interval_decode_tuple, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "bits_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_bits_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "bits_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_bits_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "bool_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_bool_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "bool_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_bool_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "box_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_box_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "box_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_box_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "line_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_line_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "line_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_line_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "lseg_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "lseg_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_lseg_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "point_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_point_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "point_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_point_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "path_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_path_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "path_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_path_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "poly_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_poly_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "poly_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_poly_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "circle_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_circle_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "circle_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_circle_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "hstore_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "hstore_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_hstore_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "int2_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_int2_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "int2_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_int2_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "int4_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_int4_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "int4_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_int4_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "uint4_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "uint4_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_uint4_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "int8_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_int8_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "int8_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_int8_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "float4_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_float4_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "float4_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_float4_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "float8_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_float8_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "float8_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_float8_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "jsonb_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "jsonb_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_jsonb_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "as_pg_string_and_size", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_as_pg_string_and_size, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, PyObject *, char **, Py_ssize_t *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "text_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_text_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "text_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_text_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "bytea_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "bytea_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_bytea_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "uuid_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "uuid_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_uuid_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "numeric_encode_text", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_text, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "numeric_decode_text", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_text, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "numeric_encode_binary", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_encode_binary, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "numeric_decode_binary", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_numeric_decode_binary, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "void_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_void_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "void_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_void_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "tid_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_tid_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "tid_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_tid_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "net_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_net_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "cidr_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_cidr_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "inet_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_inet_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "txid_snapshot_encode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_encode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  if (__Pyx_ImportFunction(__pyx_t_1, "txid_snapshot_decode", (void (**)(void))&__pyx_f_7asyncpg_7pgproto_7pgproto_txid_snapshot_decode, "PyObject *(struct __pyx_obj_7asyncpg_7pgproto_7pgproto_CodecContext *, struct __pyx_t_7asyncpg_7pgproto_7pgproto_FRBuffer *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_RefNannyFinishContext();
+  return 0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+}
+
+
+#if PY_MAJOR_VERSION < 3
+#ifdef CYTHON_NO_PYINIT_EXPORT
+#define __Pyx_PyMODINIT_FUNC void
+#else
+#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
+#endif
+#else
+#ifdef CYTHON_NO_PYINIT_EXPORT
+#define __Pyx_PyMODINIT_FUNC PyObject *
+#else
+#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
+#endif
+#endif
+
+
+#if PY_MAJOR_VERSION < 3
+__Pyx_PyMODINIT_FUNC initprotocol(void) CYTHON_SMALL_CODE; /*proto*/
+__Pyx_PyMODINIT_FUNC initprotocol(void)
+#else
+__Pyx_PyMODINIT_FUNC PyInit_protocol(void) CYTHON_SMALL_CODE; /*proto*/
+__Pyx_PyMODINIT_FUNC PyInit_protocol(void)
+#if CYTHON_PEP489_MULTI_PHASE_INIT
+{
+  return PyModuleDef_Init(&__pyx_moduledef);
+}
+static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
+    #if PY_VERSION_HEX >= 0x030700A1
+    static PY_INT64_T main_interpreter_id = -1;
+    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
+    if (main_interpreter_id == -1) {
+        main_interpreter_id = current_id;
+        return (unlikely(current_id == -1)) ? -1 : 0;
+    } else if (unlikely(main_interpreter_id != current_id))
+    #else
+    static PyInterpreterState *main_interpreter = NULL;
+    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
+    if (!main_interpreter) {
+        main_interpreter = current_interpreter;
+    } else if (unlikely(main_interpreter != current_interpreter))
+    #endif
+    {
+        PyErr_SetString(
+            PyExc_ImportError,
+            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
+        return -1;
+    }
+    return 0;
+}
+static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
+    PyObject *value = PyObject_GetAttrString(spec, from_name);
+    int result = 0;
+    if (likely(value)) {
+        result = PyDict_SetItemString(moddict, to_name, value);
+        Py_DECREF(value);
+    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+        PyErr_Clear();
+    } else {
+        result = -1;
+    }
+    return result;
+}
+static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
+    PyObject *module = NULL, *moddict, *modname;
+    if (__Pyx_check_single_interpreter())
+        return NULL;
+    if (__pyx_m)
+        return __Pyx_NewRef(__pyx_m);
+    modname = PyObject_GetAttrString(spec, "name");
+    if (unlikely(!modname)) goto bad;
+    module = PyModule_NewObject(modname);
+    Py_DECREF(modname);
+    if (unlikely(!module)) goto bad;
+    moddict = PyModule_GetDict(module);
+    if (unlikely(!moddict)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
+    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
+    return module;
+bad:
+    Py_XDECREF(module);
+    return NULL;
+}
+
+
+static CYTHON_SMALL_CODE int __pyx_pymod_exec_protocol(PyObject *__pyx_pyinit_module)
+#endif
+#endif
+{
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  Py_ssize_t __pyx_t_4;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  int __pyx_t_8;
+  static Py_UCS4 __pyx_t_9[5];
+  PyTypeObject *__pyx_t_10;
+  __Pyx_RefNannyDeclarations
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+  if (__pyx_m) {
+    if (__pyx_m == __pyx_pyinit_module) return 0;
+    PyErr_SetString(PyExc_RuntimeError, "Module 'protocol' has already been imported. Re-initialisation is not supported.");
+    return -1;
+  }
+  #elif PY_MAJOR_VERSION >= 3
+  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
+  #endif
+  #if CYTHON_REFNANNY
+__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+if (!__Pyx_RefNanny) {
+  PyErr_Clear();
+  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+  if (!__Pyx_RefNanny)
+      Py_FatalError("failed to import 'refnanny' module");
+}
+#endif
+  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_protocol(void)", 0);
+  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #ifdef __Pxy_PyFrame_Initialize_Offsets
+  __Pxy_PyFrame_Initialize_Offsets();
+  #endif
+  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
+  #ifdef __Pyx_CyFunction_USED
+  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_FusedFunction_USED
+  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_Coroutine_USED
+  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_Generator_USED
+  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_AsyncGen_USED
+  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  #ifdef __Pyx_StopAsyncIteration_USED
+  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  /*--- Library function declarations ---*/
+  /*--- Threads initialization code ---*/
+  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+  #ifdef WITH_THREAD /* Python build with threading support? */
+  PyEval_InitThreads();
+  #endif
+  #endif
+  /*--- Module creation code ---*/
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+  __pyx_m = __pyx_pyinit_module;
+  Py_INCREF(__pyx_m);
+  #else
+  #if PY_MAJOR_VERSION < 3
+  __pyx_m = Py_InitModule4("protocol", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+  #else
+  __pyx_m = PyModule_Create(&__pyx_moduledef);
+  #endif
+  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
+  Py_INCREF(__pyx_d);
+  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
+  #if CYTHON_COMPILING_IN_PYPY
+  Py_INCREF(__pyx_b);
+  #endif
+  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
+  /*--- Initialize various global constants etc. ---*/
+  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
+  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+  if (__pyx_module_is_main_asyncpg__protocol__protocol) {
+    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  }
+  #if PY_MAJOR_VERSION >= 3
+  {
+    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
+    if (!PyDict_GetItemString(modules, "asyncpg.protocol.protocol")) {
+      if (unlikely(PyDict_SetItemString(modules, "asyncpg.protocol.protocol", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
+    }
+  }
+  #endif
+  /*--- Builtin init code ---*/
+  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  /*--- Constants init code ---*/
+  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  /*--- Global type/function init code ---*/
+  (void)__Pyx_modinit_global_init_code();
+  if (unlikely(__Pyx_modinit_variable_export_code() != 0)) goto __pyx_L1_error;
+  (void)__Pyx_modinit_function_export_code();
+  if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error;
+  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
+  (void)__Pyx_modinit_variable_import_code();
+  if (unlikely(__Pyx_modinit_function_import_code() != 0)) goto __pyx_L1_error;
+  /*--- Execution code ---*/
+  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  #endif
+
+  /* "asyncpg/protocol/protocol.pyx":13
+ * cimport cpython
+ * 
+ * import asyncio             # <<<<<<<<<<<<<<
+ * import builtins
+ * import codecs
+ */
+  __pyx_t_1 = __Pyx_patch_asyncio(__Pyx_Import(__pyx_n_s_asyncio, 0, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_asyncio, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":14
+ * 
+ * import asyncio
+ * import builtins             # <<<<<<<<<<<<<<
+ * import codecs
+ * import collections
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_builtins, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_builtins, __pyx_t_1) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":15
+ * import asyncio
+ * import builtins
+ * import codecs             # <<<<<<<<<<<<<<
+ * import collections
+ * import socket
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_codecs, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_codecs, __pyx_t_1) < 0) __PYX_ERR(0, 15, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":16
+ * import builtins
+ * import codecs
+ * import collections             # <<<<<<<<<<<<<<
+ * import socket
+ * import time
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":17
+ * import codecs
+ * import collections
+ * import socket             # <<<<<<<<<<<<<<
+ * import time
+ * import weakref
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_socket, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_socket, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":18
+ * import collections
+ * import socket
+ * import time             # <<<<<<<<<<<<<<
+ * import weakref
+ * 
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":19
+ * import socket
+ * import time
+ * import weakref             # <<<<<<<<<<<<<<
+ * 
+ * from asyncpg.pgproto.pgproto cimport (
+ */
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_weakref, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_weakref, __pyx_t_1) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":43
+ *                          UINT32_MAX
+ * 
+ * from asyncpg.exceptions import _base as apg_exc_base             # <<<<<<<<<<<<<<
+ * from asyncpg import compat
+ * from asyncpg import types as apg_types
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_base);
+  __Pyx_GIVEREF(__pyx_n_s_base);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_base);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_asyncpg_exceptions, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_apg_exc_base, __pyx_t_1) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":44
+ * 
+ * from asyncpg.exceptions import _base as apg_exc_base
+ * from asyncpg import compat             # <<<<<<<<<<<<<<
+ * from asyncpg import types as apg_types
+ * from asyncpg import exceptions as apg_exc
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_compat);
+  __Pyx_GIVEREF(__pyx_n_s_compat);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_compat);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_compat); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compat, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":45
+ * from asyncpg.exceptions import _base as apg_exc_base
+ * from asyncpg import compat
+ * from asyncpg import types as apg_types             # <<<<<<<<<<<<<<
+ * from asyncpg import exceptions as apg_exc
+ * 
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_types);
+  __Pyx_GIVEREF(__pyx_n_s_types);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_types);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_apg_types, __pyx_t_1) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":46
+ * from asyncpg import compat
+ * from asyncpg import types as apg_types
+ * from asyncpg import exceptions as apg_exc             # <<<<<<<<<<<<<<
+ * 
+ * from asyncpg.pgproto cimport hton
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_apg_exc, __pyx_t_2) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":102
+ * DEF REGROLEOID = 4096
+ * 
+ * cdef ARRAY_TYPES = (_TEXTOID, _OIDOID,)             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_OID_MAP = {
+ */
+  __Pyx_INCREF(__pyx_tuple__33);
+  __Pyx_XGOTREF(__pyx_v_7asyncpg_8protocol_8protocol_ARRAY_TYPES);
+  __Pyx_DECREF_SET(__pyx_v_7asyncpg_8protocol_8protocol_ARRAY_TYPES, __pyx_tuple__33);
+  __Pyx_GIVEREF(__pyx_tuple__33);
+
+  /* "asyncpg/protocol/pgtypes.pxi":105
+ * 
+ * BUILTIN_TYPE_OID_MAP = {
+ *     ABSTIMEOID: 'abstime',             # <<<<<<<<<<<<<<
+ *     ACLITEMOID: 'aclitem',
+ *     ANYARRAYOID: 'anyarray',
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(86); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 105, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_702, __pyx_n_u_abstime) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1033, __pyx_n_u_aclitem) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2277, __pyx_n_u_anyarray) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2283, __pyx_n_u_anyelement) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3500, __pyx_n_u_anyenum) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2776, __pyx_n_u_anynonarray) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2276, __pyx_n_u_any) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3831, __pyx_n_u_anyrange) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1560, __pyx_n_u_bit) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_16, __pyx_n_u_bool) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_603, __pyx_n_u_box) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1042, __pyx_n_u_bpchar) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_17, __pyx_n_u_bytea) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_18, __pyx_n_u_char) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_29, __pyx_n_u_cid) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_650, __pyx_n_u_cidr) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_718, __pyx_n_u_circle) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2275, __pyx_n_u_cstring) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1082, __pyx_n_u_date) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3838, __pyx_n_u_event_trigger) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3115, __pyx_n_u_fdw_handler) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_700, __pyx_n_u_float4) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_701, __pyx_n_u_float8) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3642, __pyx_n_u_gtsvector) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_325, __pyx_n_u_index_am_handler) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_869, __pyx_n_u_inet) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_21, __pyx_n_u_int2) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_23, __pyx_n_u_int4) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_20, __pyx_n_u_int8) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2281, __pyx_n_u_internal) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1186, __pyx_n_u_interval) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3802, __pyx_n_u_jsonb) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_114, __pyx_n_u_json) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2280, __pyx_n_u_language_handler) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_628, __pyx_n_u_line) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_601, __pyx_n_u_lseg) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_774, __pyx_n_u_macaddr8) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_829, __pyx_n_u_macaddr) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_790, __pyx_n_u_money) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_19, __pyx_n_u_name) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1700, __pyx_n_u_numeric) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_26, __pyx_n_u_oid) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2282, __pyx_n_u_opaque) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_602, __pyx_n_u_path) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_32, __pyx_n_u_pg_ddl_command) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3402, __pyx_n_u_pg_dependencies) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3220, __pyx_n_u_pg_lsn) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3361, __pyx_n_u_pg_ndistinct) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_194, __pyx_n_u_pg_node_tree) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_600, __pyx_n_u_point) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_604, __pyx_n_u_polygon) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2249, __pyx_n_u_record) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1790, __pyx_n_u_refcursor) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2205, __pyx_n_u_regclass) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3734, __pyx_n_u_regconfig) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3769, __pyx_n_u_regdictionary) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_4089, __pyx_n_u_regnamespace) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2204, __pyx_n_u_regoperator) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2203, __pyx_n_u_regoper) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2202, __pyx_n_u_regprocedure) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_24, __pyx_n_u_regproc) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_4096, __pyx_n_u_regrole) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2206, __pyx_n_u_regtype) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_703, __pyx_n_u_reltime) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_210, __pyx_n_u_smgr) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_25, __pyx_n_u_text) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_27, __pyx_n_u_tid) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1083, __pyx_n_u_time) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1114, __pyx_n_u_timestamp) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1184, __pyx_n_u_timestamptz) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1266, __pyx_n_u_timetz) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_704, __pyx_n_u_tinterval) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2279, __pyx_n_u_trigger) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3310, __pyx_n_u_tsm_handler) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3615, __pyx_n_u_tsquery) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_3614, __pyx_n_u_tsvector) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2970, __pyx_n_u_txid_snapshot) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_705, __pyx_n_u_unknown) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2950, __pyx_n_u_uuid) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1562, __pyx_n_u_varbit) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1043, __pyx_n_u_varchar) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2278, __pyx_n_u_void) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_28, __pyx_n_u_xid) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_142, __pyx_n_u_xml) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1028, __pyx_kp_u_oid_2) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1009, __pyx_kp_u_text_2) < 0) __PYX_ERR(19, 105, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_BUILTIN_TYPE_OID_MAP, __pyx_t_1) < 0) __PYX_ERR(19, 104, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":193
+ * }
+ * 
+ * BUILTIN_TYPE_NAME_MAP = {v: k for k, v in BUILTIN_TYPE_OID_MAP.items()}             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['smallint'] = \
+ */
+  { /* enter inner scope */
+    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 193, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = 0;
+    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_BUILTIN_TYPE_OID_MAP); if (unlikely(!__pyx_t_6)) __PYX_ERR(19, 193, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_6);
+    if (unlikely(__pyx_t_6 == Py_None)) {
+      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items");
+      __PYX_ERR(19, 193, __pyx_L4_error)
+    }
+    __pyx_t_7 = __Pyx_dict_iterator(__pyx_t_6, 0, __pyx_n_s_items, (&__pyx_t_4), (&__pyx_t_5)); if (unlikely(!__pyx_t_7)) __PYX_ERR(19, 193, __pyx_L4_error)
+    __Pyx_GOTREF(__pyx_t_7);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __Pyx_XDECREF(__pyx_t_2);
+    __pyx_t_2 = __pyx_t_7;
+    __pyx_t_7 = 0;
+    while (1) {
+      __pyx_t_8 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_4, &__pyx_t_3, &__pyx_t_7, &__pyx_t_6, NULL, __pyx_t_5);
+      if (unlikely(__pyx_t_8 == 0)) break;
+      if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(19, 193, __pyx_L4_error)
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_GOTREF(__pyx_t_6);
+      __Pyx_XGOTREF(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k);
+      __Pyx_DECREF_SET(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k, __pyx_t_7);
+      __Pyx_GIVEREF(__pyx_t_7);
+      __pyx_t_7 = 0;
+      __Pyx_XGOTREF(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v);
+      __Pyx_DECREF_SET(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v, __pyx_t_6);
+      __Pyx_GIVEREF(__pyx_t_6);
+      __pyx_t_6 = 0;
+      if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v, (PyObject*)__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k))) __PYX_ERR(19, 193, __pyx_L4_error)
+    }
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_GOTREF(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k);
+    __Pyx_DECREF_SET(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k, Py_None);
+    __Pyx_GOTREF(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v);
+    __Pyx_DECREF_SET(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v, Py_None);
+    goto __pyx_L7_exit_scope;
+    __pyx_L4_error:;
+    __Pyx_GOTREF(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k);
+    __Pyx_DECREF_SET(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_k, Py_None);
+    __Pyx_GOTREF(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v);
+    __Pyx_DECREF_SET(__pyx_8genexpr1__pyx_v_7asyncpg_8protocol_8protocol_v, Py_None);
+    goto __pyx_L1_error;
+    __pyx_L7_exit_scope:;
+  } /* exit inner scope */
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_BUILTIN_TYPE_NAME_MAP, __pyx_t_1) < 0) __PYX_ERR(19, 193, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":196
+ * 
+ * BUILTIN_TYPE_NAME_MAP['smallint'] = \
+ *     BUILTIN_TYPE_NAME_MAP['int2']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['int'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 196, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_int2); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 196, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":195
+ * BUILTIN_TYPE_NAME_MAP = {v: k for k, v in BUILTIN_TYPE_OID_MAP.items()}
+ * 
+ * BUILTIN_TYPE_NAME_MAP['smallint'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['int2']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 195, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_n_u_smallint, __pyx_t_2) < 0)) __PYX_ERR(19, 195, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":199
+ * 
+ * BUILTIN_TYPE_NAME_MAP['int'] = \
+ *     BUILTIN_TYPE_NAME_MAP['int4']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['integer'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 199, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_int4); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 199, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":198
+ *     BUILTIN_TYPE_NAME_MAP['int2']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['int'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['int4']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 198, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_n_u_int, __pyx_t_1) < 0)) __PYX_ERR(19, 198, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":202
+ * 
+ * BUILTIN_TYPE_NAME_MAP['integer'] = \
+ *     BUILTIN_TYPE_NAME_MAP['int4']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['bigint'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 202, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_int4); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 202, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":201
+ *     BUILTIN_TYPE_NAME_MAP['int4']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['integer'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['int4']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 201, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_n_u_integer, __pyx_t_2) < 0)) __PYX_ERR(19, 201, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":205
+ * 
+ * BUILTIN_TYPE_NAME_MAP['bigint'] = \
+ *     BUILTIN_TYPE_NAME_MAP['int8']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['decimal'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 205, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_int8); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 205, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":204
+ *     BUILTIN_TYPE_NAME_MAP['int4']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['bigint'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['int8']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 204, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_n_u_bigint, __pyx_t_1) < 0)) __PYX_ERR(19, 204, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":208
+ * 
+ * BUILTIN_TYPE_NAME_MAP['decimal'] = \
+ *     BUILTIN_TYPE_NAME_MAP['numeric']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['real'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 208, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_numeric); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 208, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":207
+ *     BUILTIN_TYPE_NAME_MAP['int8']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['decimal'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['numeric']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 207, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_n_u_decimal, __pyx_t_2) < 0)) __PYX_ERR(19, 207, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":211
+ * 
+ * BUILTIN_TYPE_NAME_MAP['real'] = \
+ *     BUILTIN_TYPE_NAME_MAP['float4']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['double precision'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 211, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_float4); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 211, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":210
+ *     BUILTIN_TYPE_NAME_MAP['numeric']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['real'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['float4']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 210, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_n_u_real, __pyx_t_1) < 0)) __PYX_ERR(19, 210, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":214
+ * 
+ * BUILTIN_TYPE_NAME_MAP['double precision'] = \
+ *     BUILTIN_TYPE_NAME_MAP['float8']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['timestamp with timezone'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 214, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_float8); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 214, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":213
+ *     BUILTIN_TYPE_NAME_MAP['float4']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['double precision'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['float8']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 213, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_kp_u_double_precision, __pyx_t_2) < 0)) __PYX_ERR(19, 213, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":217
+ * 
+ * BUILTIN_TYPE_NAME_MAP['timestamp with timezone'] = \
+ *     BUILTIN_TYPE_NAME_MAP['timestamptz']             # <<<<<<<<<<<<<<
+ * 
+ * BUILTIN_TYPE_NAME_MAP['time with timezone'] = \
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 217, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_2, __pyx_n_u_timestamptz); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 217, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":216
+ *     BUILTIN_TYPE_NAME_MAP['float8']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['timestamp with timezone'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['timestamptz']
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 216, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_kp_u_timestamp_with_timezone, __pyx_t_1) < 0)) __PYX_ERR(19, 216, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":220
+ * 
+ * BUILTIN_TYPE_NAME_MAP['time with timezone'] = \
+ *     BUILTIN_TYPE_NAME_MAP['timetz']             # <<<<<<<<<<<<<<
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 220, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_t_1, __pyx_n_u_timetz); if (unlikely(!__pyx_t_2)) __PYX_ERR(19, 220, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/pgtypes.pxi":219
+ *     BUILTIN_TYPE_NAME_MAP['timestamptz']
+ * 
+ * BUILTIN_TYPE_NAME_MAP['time with timezone'] = \             # <<<<<<<<<<<<<<
+ *     BUILTIN_TYPE_NAME_MAP['timetz']
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_BUILTIN_TYPE_NAME_MAP); if (unlikely(!__pyx_t_1)) __PYX_ERR(19, 219, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_kp_u_time_with_timezone, __pyx_t_2) < 0)) __PYX_ERR(19, 219, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/encodings.pyx":14
+ * 
+ * cdef dict ENCODINGS_MAP = {
+ *     'abc': 'cp1258',             # <<<<<<<<<<<<<<
+ *     'alt': 'cp866',
+ *     'euc_cn': 'euccn',
+ */
+  __pyx_t_2 = __Pyx_PyDict_NewPresized(45); if (unlikely(!__pyx_t_2)) __PYX_ERR(7, 14, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_abc, __pyx_n_u_cp1258) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_alt, __pyx_n_u_cp866) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_euc_cn, __pyx_n_u_euccn) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_euc_jp, __pyx_n_u_eucjp) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_euc_kr, __pyx_n_u_euckr) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_koi8r, __pyx_n_u_koi8_r) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_koi8u, __pyx_n_u_koi8_u) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_shift_jis_2004, __pyx_n_u_euc_jis_2004) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_sjis, __pyx_n_u_shift_jis) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_sql_ascii, __pyx_n_u_ascii) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_vscii, __pyx_n_u_cp1258) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_tcvn, __pyx_n_u_cp1258) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_tcvn5712, __pyx_n_u_cp1258) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_unicode, __pyx_n_u_utf_8_2) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win, __pyx_n_u_cp1521) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1250, __pyx_n_u_cp1250) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1251, __pyx_n_u_cp1251) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1252, __pyx_n_u_cp1252) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1253, __pyx_n_u_cp1253) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1254, __pyx_n_u_cp1254) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1255, __pyx_n_u_cp1255) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1256, __pyx_n_u_cp1256) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1257, __pyx_n_u_cp1257) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win1258, __pyx_n_u_cp1258) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win866, __pyx_n_u_cp866) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win874, __pyx_n_u_cp874) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win932, __pyx_n_u_cp932) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win936, __pyx_n_u_cp936) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win949, __pyx_n_u_cp949) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_win950, __pyx_n_u_cp950) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1250, __pyx_n_u_cp1250) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1251, __pyx_n_u_cp1251) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1252, __pyx_n_u_cp1252) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1253, __pyx_n_u_cp1253) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1254, __pyx_n_u_cp1254) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1255, __pyx_n_u_cp1255) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1256, __pyx_n_u_cp1256) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1257, __pyx_n_u_cp1257) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows1258, __pyx_n_u_cp1258) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows866, __pyx_n_u_cp866) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows874, __pyx_n_u_cp874) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows932, __pyx_n_u_cp932) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows936, __pyx_n_u_cp936) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows949, __pyx_n_u_cp949) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_windows950, __pyx_n_u_cp950) < 0) __PYX_ERR(7, 14, __pyx_L1_error)
+  __Pyx_XGOTREF(__pyx_v_7asyncpg_8protocol_8protocol_ENCODINGS_MAP);
+  __Pyx_DECREF_SET(__pyx_v_7asyncpg_8protocol_8protocol_ENCODINGS_MAP, ((PyObject*)__pyx_t_2));
+  __Pyx_GIVEREF(__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":8
+ * 
+ * 
+ * from asyncpg import exceptions             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exceptions, __pyx_t_2) < 0) __PYX_ERR(1, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/settings.pyx":90
+ * 
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):             # <<<<<<<<<<<<<<
+ *         if format == PG_FORMAT_ANY:
+ *             codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+ */
+  __pyx_k_ = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY;
+
+  /* "asyncpg/protocol/settings.pyx":89
+ *                                                  typekind, alias_to, _format)
+ * 
+ *     cpdef inline Codec get_data_codec(self, uint32_t oid,             # <<<<<<<<<<<<<<
+ *                                       ServerDataFormat format=PG_FORMAT_ANY):
+ *         if format == PG_FORMAT_ANY:
+ */
+  __pyx_k_ = __pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY;
+
+  /* "asyncpg/protocol/codecs/base.pyx":8
+ * 
+ * 
+ * from collections.abc import Mapping as MappingABC             # <<<<<<<<<<<<<<
+ * 
+ * from asyncpg import exceptions
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_Mapping);
+  __Pyx_GIVEREF(__pyx_n_s_Mapping);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Mapping);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_collections_abc, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MappingABC, __pyx_t_1) < 0) __PYX_ERR(3, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":10
+ * from collections.abc import Mapping as MappingABC
+ * 
+ * from asyncpg import exceptions             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 10, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exceptions, __pyx_t_2) < 0) __PYX_ERR(3, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":15
+ * cdef void* binary_codec_map[(MAXSUPPORTEDOID + 1) * 2]
+ * cdef void* text_codec_map[(MAXSUPPORTEDOID + 1) * 2]
+ * cdef dict EXTRA_CODECS = {}             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 15, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_XGOTREF(__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS);
+  __Pyx_DECREF_SET(__pyx_v_7asyncpg_8protocol_8protocol_EXTRA_CODECS, ((PyObject*)__pyx_t_1));
+  __Pyx_GIVEREF(__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":607
+ * 
+ *     def _set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+ *                                 alias_to, format=PG_FORMAT_ANY):             # <<<<<<<<<<<<<<
+ *         cdef:
+ *             Codec codec
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 607, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_k__10 = __pyx_t_1;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":656
+ * 
+ *     def set_builtin_type_codec(self, typeoid, typename, typeschema, typekind,
+ *                                alias_to, format=PG_FORMAT_ANY):             # <<<<<<<<<<<<<<
+ *         self._set_builtin_type_codec(typeoid, typename, typeschema, typekind,
+ *                                      alias_to, format)
+ */
+  __pyx_t_1 = __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(__pyx_e_7asyncpg_8protocol_8protocol_PG_FORMAT_ANY); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 656, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_k__11 = __pyx_t_1;
+  __Pyx_GIVEREF(__pyx_t_1);
+  __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/base.pyx":728
+ * cdef inline Codec get_core_codec(
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):             # <<<<<<<<<<<<<<
+ *     cdef:
+ *         void *ptr = NULL
+ */
+  __pyx_k__12 = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT;
+
+  /* "asyncpg/protocol/codecs/base.pyx":747
+ * cdef inline Codec get_any_core_codec(
+ *         uint32_t oid, ServerDataFormat format,
+ *         ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):             # <<<<<<<<<<<<<<
+ *     """A version of get_core_codec that accepts PG_FORMAT_ANY."""
+ *     cdef:
+ */
+  __pyx_k__13 = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT;
+
+  /* "asyncpg/protocol/codecs/base.pyx":770
+ *                          decode_func decode,
+ *                          ServerDataFormat format,
+ *                          ClientExchangeFormat xformat=PG_XFORMAT_OBJECT):             # <<<<<<<<<<<<<<
+ * 
+ *     if oid > MAXSUPPORTEDOID:
+ */
+  __pyx_k__14 = __pyx_e_7asyncpg_8protocol_8protocol_PG_XFORMAT_OBJECT;
+
+  /* "asyncpg/protocol/codecs/pgproto.pyx":441
+ * 
+ * 
+ * init_all_pgproto_codecs()             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_all_pgproto_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 441, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":8
+ * 
+ * 
+ * from collections.abc import (Iterable as IterableABC,             # <<<<<<<<<<<<<<
+ *                              Mapping as MappingABC,
+ *                              Sized as SizedABC)
+ */
+  __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_Iterable);
+  __Pyx_GIVEREF(__pyx_n_s_Iterable);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Iterable);
+  __Pyx_INCREF(__pyx_n_s_Mapping);
+  __Pyx_GIVEREF(__pyx_n_s_Mapping);
+  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_Mapping);
+  __Pyx_INCREF(__pyx_n_s_Sized);
+  __Pyx_GIVEREF(__pyx_n_s_Sized);
+  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_Sized);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_collections_abc, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Iterable); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_IterableABC, __pyx_t_1) < 0) __PYX_ERR(4, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MappingABC, __pyx_t_1) < 0) __PYX_ERR(4, 9, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Sized); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_SizedABC, __pyx_t_1) < 0) __PYX_ERR(4, 10, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":12
+ *                              Sized as SizedABC)
+ * 
+ * from asyncpg import exceptions             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(4, 12, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exceptions, __pyx_t_2) < 0) __PYX_ERR(4, 12, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/array.pyx":18
+ * 
+ * # "NULL"
+ * cdef Py_UCS4 *APG_NULL = [0x004E, 0x0055, 0x004C, 0x004C, 0x0000]             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_9[0] = 0x004E;
+  __pyx_t_9[1] = 0x0055;
+  __pyx_t_9[2] = 0x004C;
+  __pyx_t_9[3] = 0x004C;
+  __pyx_t_9[4] = 0x0000;
+  __pyx_v_7asyncpg_8protocol_8protocol_APG_NULL = __pyx_t_9;
+
+  /* "asyncpg/protocol/codecs/array.pyx":876
+ *                         PG_FORMAT_BINARY)
+ * 
+ * init_array_codecs()             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_array_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 876, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":8
+ * 
+ * 
+ * from asyncpg import types as apg_types             # <<<<<<<<<<<<<<
+ * 
+ * # defined in postgresql/src/include/utils/rangetypes.h
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_types);
+  __Pyx_GIVEREF(__pyx_n_s_types);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_types);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_apg_types, __pyx_t_1) < 0) __PYX_ERR(9, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/range.pyx":149
+ * 
+ * 
+ * init_range_codecs()             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_2 = __pyx_f_7asyncpg_8protocol_8protocol_init_range_codecs(); if (unlikely(!__pyx_t_2)) __PYX_ERR(9, 149, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":8
+ * 
+ * 
+ * from asyncpg import exceptions             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(10, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exceptions, __pyx_t_2) < 0) __PYX_ERR(10, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/codecs/record.pyx":60
+ *                         PG_FORMAT_BINARY)
+ * 
+ * init_record_codecs()             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_1 = __pyx_f_7asyncpg_8protocol_8protocol_init_record_codecs(); if (unlikely(!__pyx_t_1)) __PYX_ERR(10, 60, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":8
+ * 
+ * 
+ * from hashlib import md5 as hashlib_md5  # for MD5 authentication             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(__pyx_n_s_md5);
+  __Pyx_GIVEREF(__pyx_n_s_md5);
+  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_md5);
+  __pyx_t_2 = __Pyx_Import(__pyx_n_s_hashlib, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_md5); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_hashlib_md5, __pyx_t_1) < 0) __PYX_ERR(5, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/coreproto.pyx":942
+ * 
+ * 
+ * cdef bytes SYNC_MESSAGE = bytes(WriteBuffer.new_message(b'S').end_message())             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_2 = ((PyObject *)__pyx_vtabptr_7asyncpg_7pgproto_7pgproto_WriteBuffer->new_message('S')); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 942, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = ((struct __pyx_vtabstruct_7asyncpg_7pgproto_7pgproto_WriteBuffer *)((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_2)->__pyx_vtab)->end_message(((struct __pyx_obj_7asyncpg_7pgproto_7pgproto_WriteBuffer *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 942, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 942, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __Pyx_XGOTREF(__pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE);
+  __Pyx_DECREF_SET(__pyx_v_7asyncpg_8protocol_8protocol_SYNC_MESSAGE, ((PyObject*)__pyx_t_2));
+  __Pyx_GIVEREF(__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/prepared_stmt.pyx":8
+ * 
+ * 
+ * from asyncpg import exceptions             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(6, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(__pyx_n_s_exceptions);
+  __Pyx_GIVEREF(__pyx_n_s_exceptions);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exceptions);
+  __pyx_t_1 = __Pyx_Import(__pyx_n_s_asyncpg, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(6, 8, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exceptions, __pyx_t_2) < 0) __PYX_ERR(6, 8, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":72
+ * 
+ * 
+ * NO_TIMEOUT = object()             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NO_TIMEOUT, __pyx_t_1) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":919
+ * 
+ * 
+ * class Timer:             # <<<<<<<<<<<<<<
+ *     def __init__(self, budget):
+ *         self._budget = budget
+ */
+  __pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_Timer, __pyx_n_s_Timer, (PyObject *) NULL, __pyx_n_s_asyncpg_protocol_protocol, (PyObject *) NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 919, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+
+  /* "asyncpg/protocol/protocol.pyx":920
+ * 
+ * class Timer:
+ *     def __init__(self, budget):             # <<<<<<<<<<<<<<
+ *         self._budget = budget
+ *         self._started = 0
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_1__init__, 0, __pyx_n_s_Timer___init, NULL, __pyx_n_s_asyncpg_protocol_protocol, __pyx_d, ((PyObject *)__pyx_codeobj__35)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 920, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_2) < 0) __PYX_ERR(0, 920, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":924
+ *         self._started = 0
+ * 
+ *     def __enter__(self):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._started = time.monotonic()
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_3__enter__, 0, __pyx_n_s_Timer___enter, NULL, __pyx_n_s_asyncpg_protocol_protocol, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_enter, __pyx_t_2) < 0) __PYX_ERR(0, 924, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":928
+ *             self._started = time.monotonic()
+ * 
+ *     def __exit__(self, et, e, tb):             # <<<<<<<<<<<<<<
+ *         if self._budget is not None:
+ *             self._budget -= time.monotonic() - self._started
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_5__exit__, 0, __pyx_n_s_Timer___exit, NULL, __pyx_n_s_asyncpg_protocol_protocol, __pyx_d, ((PyObject *)__pyx_codeobj__39)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_exit, __pyx_t_2) < 0) __PYX_ERR(0, 928, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":932
+ *             self._budget -= time.monotonic() - self._started
+ * 
+ *     def get_remaining_budget(self):             # <<<<<<<<<<<<<<
+ *         return self._budget
+ * 
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_5Timer_7get_remaining_budget, 0, __pyx_n_s_Timer_get_remaining_budget, NULL, __pyx_n_s_asyncpg_protocol_protocol, __pyx_d, ((PyObject *)__pyx_codeobj__41)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 932, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_get_remaining_budget, __pyx_t_2) < 0) __PYX_ERR(0, 932, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":919
+ * 
+ * 
+ * class Timer:             # <<<<<<<<<<<<<<
+ *     def __init__(self, budget):
+ *         self._budget = budget
+ */
+  __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_Timer, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 919, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Timer, __pyx_t_2) < 0) __PYX_ERR(0, 919, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":936
+ * 
+ * 
+ * class Protocol(BaseProtocol, asyncio.Protocol):             # <<<<<<<<<<<<<<
+ *     pass
+ * 
+ */
+  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_asyncio); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Protocol); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_INCREF(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol));
+  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol));
+  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_7asyncpg_8protocol_8protocol_BaseProtocol));
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_6 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_Protocol, __pyx_n_s_Protocol, (PyObject *) NULL, __pyx_n_s_asyncpg_protocol_protocol, (PyObject *) NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_7 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_Protocol, __pyx_t_1, __pyx_t_6, NULL, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_7);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Protocol, __pyx_t_7) < 0) __PYX_ERR(0, 936, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":940
+ * 
+ * 
+ * def _create_record(object mapping, tuple elems):             # <<<<<<<<<<<<<<
+ *     # Exposed only for testing purposes.
+ * 
+ */
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_1_create_record, NULL, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 940, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_create_record, __pyx_t_1) < 0) __PYX_ERR(0, 940, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":961
+ * 
+ * 
+ * Record = <object>record.ApgRecord_InitTypes()             # <<<<<<<<<<<<<<
+ */
+  __pyx_t_10 = ApgRecord_InitTypes(); if (unlikely(__pyx_t_10 == ((PyTypeObject *)NULL))) __PYX_ERR(0, 961, __pyx_L1_error)
+  __pyx_t_1 = ((PyObject *)__pyx_t_10);
+  __Pyx_INCREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Record, __pyx_t_1) < 0) __PYX_ERR(0, 961, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_DataCodecConfig(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x7336a95:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_3__pyx_unpickle_DataCodecConfig, NULL, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_DataCodecConfig, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":9
+ *         __pyx_unpickle_DataCodecConfig__set_state(<DataCodecConfig> __pyx_result, __pyx_state)
+ *     return __pyx_result
+ * cdef __pyx_unpickle_DataCodecConfig__set_state(DataCodecConfig __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
+ *     __pyx_result._custom_type_codecs = __pyx_state[0]; __pyx_result._derived_type_codecs = __pyx_state[1]
+ *     if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'):
+ */
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_5__pyx_unpickle_CoreProtocol, NULL, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_CoreProtocol, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "(tree fragment)":1
+ * def __pyx_unpickle_BaseProtocol(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
+ *     if __pyx_checksum != 0x4e171a7:
+ *         from pickle import PickleError as __pyx_PickleError
+ */
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7asyncpg_8protocol_8protocol_7__pyx_unpickle_BaseProtocol, NULL, __pyx_n_s_asyncpg_protocol_protocol); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BaseProtocol, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/protocol/protocol.pyx":1
+ * # Copyright (C) 2016-present the asyncpg authors and contributors             # <<<<<<<<<<<<<<
+ * # <see AUTHORS file>
+ * #
+ */
+  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
+  __Pyx_GOTREF(__pyx_t_1);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "asyncpg/pgproto/buffer.pxd":103
+ *         return self._current_message_len
+ * 
+ *     cdef inline read_utf8(self):             # <<<<<<<<<<<<<<
+ *         return self.read_cstr().decode('utf-8')
+ * 
+ */
+
+  /*--- Wrapped vars code ---*/
+
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  if (__pyx_m) {
+    if (__pyx_d) {
+      __Pyx_AddTraceback("init asyncpg.protocol.protocol", __pyx_clineno, __pyx_lineno, __pyx_filename);
+    }
+    Py_CLEAR(__pyx_m);
+  } else if (!PyErr_Occurred()) {
+    PyErr_SetString(PyExc_ImportError, "init asyncpg.protocol.protocol");
+  }
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  #if CYTHON_PEP489_MULTI_PHASE_INIT
+  return (__pyx_m != NULL) ? 0 : -1;
+  #elif PY_MAJOR_VERSION >= 3
+  return __pyx_m;
+  #else
+  return;
+  #endif
+}
+
+/* --- Runtime support code --- */
+/* Refnanny */
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+    PyObject *m = NULL, *p = NULL;
+    void *r = NULL;
+    m = PyImport_ImportModule(modname);
+    if (!m) goto end;
+    p = PyObject_GetAttrString(m, "RefNannyAPI");
+    if (!p) goto end;
+    r = PyLong_AsVoidPtr(p);
+end:
+    Py_XDECREF(p);
+    Py_XDECREF(m);
+    return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif
+
+/* PyObjectGetAttrStr */
+#if CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
+    PyTypeObject* tp = Py_TYPE(obj);
+    if (likely(tp->tp_getattro))
+        return tp->tp_getattro(obj, attr_name);
+#if PY_MAJOR_VERSION < 3
+    if (likely(tp->tp_getattr))
+        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
+#endif
+    return PyObject_GetAttr(obj, attr_name);
+}
+#endif
+
+/* GetBuiltinName */
+static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
+    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
+    if (unlikely(!result)) {
+        PyErr_Format(PyExc_NameError,
+#if PY_MAJOR_VERSION >= 3
+            "name '%U' is not defined", name);
+#else
+            "name '%.200s' is not defined", PyString_AS_STRING(name));
+#endif
+    }
+    return result;
+}
+
+/* PyObjectCall */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
+    PyObject *result;
+    ternaryfunc call = func->ob_type->tp_call;
+    if (unlikely(!call))
+        return PyObject_Call(func, arg, kw);
+    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
+        return NULL;
+    result = (*call)(func, arg, kw);
+    Py_LeaveRecursiveCall();
+    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
+        PyErr_SetString(
+            PyExc_SystemError,
+            "NULL result without error in PyObject_Call");
+    }
+    return result;
+}
+#endif
+
+/* UnpackUnboundCMethod */
+static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
+    PyObject *method;
+    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
+    if (unlikely(!method))
+        return -1;
+    target->method = method;
+#if CYTHON_COMPILING_IN_CPYTHON
+    #if PY_MAJOR_VERSION >= 3
+    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
+    #endif
+    {
+        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
+        target->func = descr->d_method->ml_meth;
+        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
+    }
+#endif
+    return 0;
+}
+
+/* CallUnboundCMethod1 */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
+    if (likely(cfunc->func)) {
+        int flag = cfunc->flag;
+        if (flag == METH_O) {
+            return (*(cfunc->func))(self, arg);
+        } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) {
+            if (PY_VERSION_HEX >= 0x030700A0) {
+                return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
+            } else {
+                return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
+            }
+        } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) {
+            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
+        }
+    }
+    return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
+}
+#endif
+static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
+    PyObject *args, *result = NULL;
+    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
+        args = PyTuple_New(1);
+        if (unlikely(!args)) goto bad;
+        Py_INCREF(arg);
+        PyTuple_SET_ITEM(args, 0, arg);
+        if (cfunc->flag & METH_KEYWORDS)
+            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
+        else
+            result = (*cfunc->func)(self, args);
+    } else {
+        args = PyTuple_New(2);
+        if (unlikely(!args)) goto bad;
+        Py_INCREF(self);
+        PyTuple_SET_ITEM(args, 0, self);
+        Py_INCREF(arg);
+        PyTuple_SET_ITEM(args, 1, arg);
+        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
+    }
+#else
+    args = PyTuple_Pack(2, self, arg);
+    if (unlikely(!args)) goto bad;
+    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
+#endif
+bad:
+    Py_XDECREF(args);
+    return result;
+}
+
+/* CallUnboundCMethod2 */
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
+static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
+    if (likely(cfunc->func)) {
+        PyObject *args[2] = {arg1, arg2};
+        if (cfunc->flag == METH_FASTCALL) {
+            #if PY_VERSION_HEX >= 0x030700A0
+            return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
+            #else
+            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
+            #endif
+        }
+        #if PY_VERSION_HEX >= 0x030700A0
+        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
+            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
+        #endif
+    }
+    return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
+}
+#endif
+static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
+    PyObject *args, *result = NULL;
+    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
+        args = PyTuple_New(2);
+        if (unlikely(!args)) goto bad;
+        Py_INCREF(arg1);
+        PyTuple_SET_ITEM(args, 0, arg1);
+        Py_INCREF(arg2);
+        PyTuple_SET_ITEM(args, 1, arg2);
+        if (cfunc->flag & METH_KEYWORDS)
+            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
+        else
+            result = (*cfunc->func)(self, args);
+    } else {
+        args = PyTuple_New(3);
+        if (unlikely(!args)) goto bad;
+        Py_INCREF(self);
+        PyTuple_SET_ITEM(args, 0, self);
+        Py_INCREF(arg1);
+        PyTuple_SET_ITEM(args, 1, arg1);
+        Py_INCREF(arg2);
+        PyTuple_SET_ITEM(args, 2, arg2);
+        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
+    }
+#else
+    args = PyTuple_Pack(3, self, arg1, arg2);
+    if (unlikely(!args)) goto bad;
+    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
+#endif
+bad:
+    Py_XDECREF(args);
+    return result;
+}
+
+/* dict_getitem_default */
+static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
+    PyObject* value;
+#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
+    value = PyDict_GetItemWithError(d, key);
+    if (unlikely(!value)) {
+        if (unlikely(PyErr_Occurred()))
+            return NULL;
+        value = default_value;
+    }
+    Py_INCREF(value);
+    if ((1));
+#else
+    if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
+        value = PyDict_GetItem(d, key);
+        if (unlikely(!value)) {
+            value = default_value;
+        }
+        Py_INCREF(value);
+    }
+#endif
+    else {
+        if (default_value == Py_None)
+            value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key);
+        else
+            value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value);
+    }
+    return value;
+}
+
+/* PyFunctionFastCall */
+#if CYTHON_FAST_PYCALL
+static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
+                                               PyObject *globals) {
+    PyFrameObject *f;
+    PyThreadState *tstate = __Pyx_PyThreadState_Current;
+    PyObject **fastlocals;
+    Py_ssize_t i;
+    PyObject *result;
+    assert(globals != NULL);
+    /* XXX Perhaps we should create a specialized
+       PyFrame_New() that doesn't take locals, but does
+       take builtins without sanity checking them.
+       */
+    assert(tstate != NULL);
+    f = PyFrame_New(tstate, co, globals, NULL);
+    if (f == NULL) {
+        return NULL;
+    }
+    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
+    for (i = 0; i < na; i++) {
+        Py_INCREF(*args);
+        fastlocals[i] = *args++;
+    }
+    result = PyEval_EvalFrameEx(f,0);
+    ++tstate->recursion_depth;
+    Py_DECREF(f);
+    --tstate->recursion_depth;
+    return result;
+}
+#if 1 || PY_VERSION_HEX < 0x030600B1
+static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
+    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
+    PyObject *globals = PyFunction_GET_GLOBALS(func);
+    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
+    PyObject *closure;
+#if PY_MAJOR_VERSION >= 3
+    PyObject *kwdefs;
+#endif
+    PyObject *kwtuple, **k;
+    PyObject **d;
+    Py_ssize_t nd;
+    Py_ssize_t nk;
+    PyObject *result;
+    assert(kwargs == NULL || PyDict_Check(kwargs));
+    nk = kwargs ? PyDict_Size(kwargs) : 0;
+    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
+        return NULL;
+    }
+    if (
+#if PY_MAJOR_VERSION >= 3
+            co->co_kwonlyargcount == 0 &&
+#endif
+            likely(kwargs == NULL || nk == 0) &&
+            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
+        if (argdefs == NULL && co->co_argcount == nargs) {
+            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
+            goto done;
+        }
+        else if (nargs == 0 && argdefs != NULL
+                 && co->co_argcount == Py_SIZE(argdefs)) {
+            /* function called with no arguments, but all parameters have
+               a default value: use default values as arguments .*/
+            args = &PyTuple_GET_ITEM(argdefs, 0);
+            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
+            goto done;
+        }
+    }
+    if (kwargs != NULL) {
+        Py_ssize_t pos, i;
+        kwtuple = PyTuple_New(2 * nk);
+        if (kwtuple == NULL) {
+            result = NULL;
+            goto done;
+        }
+        k = &PyTuple_GET_ITEM(kwtuple, 0);
+        pos = i = 0;
+        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
+            Py_INCREF(k[i]);
+            Py_INCREF(k[i+1]);
+            i += 2;
+        }
+        nk = i / 2;
+    }
+    else {
+        kwtuple = NULL;
+        k = NULL;
+    }
+    closure = PyFunction_GET_CLOSURE(func);
+#if PY_MAJOR_VERSION >= 3
+    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
+#endif
+    if (argdefs != NULL) {
+        d = &PyTuple_GET_ITEM(argdefs, 0);
+        nd = Py_SIZE(argdefs);
+    }
+    else {
+        d = NULL;
+        nd = 0;
+    }
+#if PY_MAJOR_VERSION >= 3
+    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
+                               args, nargs,
+                               k, (int)nk,
+                               d, (int)nd, kwdefs, closure);
+#else
+    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
+                               args, nargs,
+                               k, (int)nk,
+                               d, (int)nd, closure);
+#endif
+    Py_XDECREF(kwtuple);
+done:
+    Py_LeaveRecursiveCall();
+    return result;
+}
+#endif
+#endif
+
+/* PyObjectCallMethO */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
+    PyObject *self, *result;
+    PyCFunction cfunc;
+    cfunc = PyCFunction_GET_FUNCTION(func);
+    self = PyCFunction_GET_SELF(func);
+    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
+        return NULL;
+    result = cfunc(self, arg);
+    Py_LeaveRecursiveCall();
+    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
+        PyErr_SetString(
+            PyExc_SystemError,
+            "NULL result without error in PyObject_Call");
+    }
+    return result;
+}
+#endif
+
+/* PyObjectCallNoArg */
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
+#if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(func)) {
+        return __Pyx_PyFunction_FastCall(func, NULL, 0);
+    }
+#endif
+#ifdef __Pyx_CyFunction_USED
+    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
+#else
+    if (likely(PyCFunction_Check(func)))
+#endif
+    {
+        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
+            return __Pyx_PyObject_CallMethO(func, NULL);
+        }
+    }
+    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
+}
+#endif
+
+/* PyCFunctionFastCall */
+#if CYTHON_FAST_PYCCALL
+static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
+    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
+    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
+    PyObject *self = PyCFunction_GET_SELF(func);
+    int flags = PyCFunction_GET_FLAGS(func);
+    assert(PyCFunction_Check(func));
+    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
+    assert(nargs >= 0);
+    assert(nargs == 0 || args != NULL);
+    /* _PyCFunction_FastCallDict() must not be called with an exception set,
+       because it may clear it (directly or indirectly) and so the
+       caller loses its exception */
+    assert(!PyErr_Occurred());
+    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
+        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
+    } else {
+        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
+    }
+}
+#endif
+
+/* PyObjectCallOneArg */
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+    PyObject *result;
+    PyObject *args = PyTuple_New(1);
+    if (unlikely(!args)) return NULL;
+    Py_INCREF(arg);
+    PyTuple_SET_ITEM(args, 0, arg);
+    result = __Pyx_PyObject_Call(func, args, NULL);
+    Py_DECREF(args);
+    return result;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+#if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(func)) {
+        return __Pyx_PyFunction_FastCall(func, &arg, 1);
+    }
+#endif
+    if (likely(PyCFunction_Check(func))) {
+        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
+            return __Pyx_PyObject_CallMethO(func, arg);
+#if CYTHON_FAST_PYCCALL
+        } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
+            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
+#endif
+        }
+    }
+    return __Pyx__PyObject_CallOneArg(func, arg);
+}
+#else
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+    PyObject *result;
+    PyObject *args = PyTuple_Pack(1, arg);
+    if (unlikely(!args)) return NULL;
+    result = __Pyx_PyObject_Call(func, args, NULL);
+    Py_DECREF(args);
+    return result;
+}
+#endif
+
+/* RaiseDoubleKeywords */
+static void __Pyx_RaiseDoubleKeywordsError(
+    const char* func_name,
+    PyObject* kw_name)
+{
+    PyErr_Format(PyExc_TypeError,
+        #if PY_MAJOR_VERSION >= 3
+        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+        #else
+        "%s() got multiple values for keyword argument '%s'", func_name,
+        PyString_AsString(kw_name));
+        #endif
+}
+
+/* ParseKeywords */
+static int __Pyx_ParseOptionalKeywords(
+    PyObject *kwds,
+    PyObject **argnames[],
+    PyObject *kwds2,
+    PyObject *values[],
+    Py_ssize_t num_pos_args,
+    const char* function_name)
+{
+    PyObject *key = 0, *value = 0;
+    Py_ssize_t pos = 0;
+    PyObject*** name;
+    PyObject*** first_kw_arg = argnames + num_pos_args;
+    while (PyDict_Next(kwds, &pos, &key, &value)) {
+        name = first_kw_arg;
+        while (*name && (**name != key)) name++;
+        if (*name) {
+            values[name-argnames] = value;
+            continue;
+        }
+        name = first_kw_arg;
+        #if PY_MAJOR_VERSION < 3
+        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
+            while (*name) {
+                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
+                        && _PyString_Eq(**name, key)) {
+                    values[name-argnames] = value;
+                    break;
+                }
+                name++;
+            }
+            if (*name) continue;
+            else {
+                PyObject*** argname = argnames;
+                while (argname != first_kw_arg) {
+                    if ((**argname == key) || (
+                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
+                             && _PyString_Eq(**argname, key))) {
+                        goto arg_passed_twice;
+                    }
+                    argname++;
+                }
+            }
+        } else
+        #endif
+        if (likely(PyUnicode_Check(key))) {
+            while (*name) {
+                int cmp = (**name == key) ? 0 :
+                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
+                #endif
+                    PyUnicode_Compare(**name, key);
+                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+                if (cmp == 0) {
+                    values[name-argnames] = value;
+                    break;
+                }
+                name++;
+            }
+            if (*name) continue;
+            else {
+                PyObject*** argname = argnames;
+                while (argname != first_kw_arg) {
+                    int cmp = (**argname == key) ? 0 :
+                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
+                    #endif
+                        PyUnicode_Compare(**argname, key);
+                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+                    if (cmp == 0) goto arg_passed_twice;
+                    argname++;
+                }
+            }
+        } else
+            goto invalid_keyword_type;
+        if (kwds2) {
+            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+        } else {
+            goto invalid_keyword;
+        }
+    }
+    return 0;
+arg_passed_twice:
+    __Pyx_RaiseDoubleKeywordsError(function_name, key);
+    goto bad;
+invalid_keyword_type:
+    PyErr_Format(PyExc_TypeError,
+        "%.200s() keywords must be strings", function_name);
+    goto bad;
+invalid_keyword:
+    PyErr_Format(PyExc_TypeError,
+    #if PY_MAJOR_VERSION < 3
+        "%.200s() got an unexpected keyword argument '%.200s'",
+        function_name, PyString_AsString(key));
+    #else
+        "%s() got an unexpected keyword argument '%U'",
+        function_name, key);
+    #endif
+bad:
+    return -1;
+}
+
+/* RaiseArgTupleInvalid */
+static void __Pyx_RaiseArgtupleInvalid(
+    const char* func_name,
+    int exact,
+    Py_ssize_t num_min,
+    Py_ssize_t num_max,
+    Py_ssize_t num_found)
+{
+    Py_ssize_t num_expected;
+    const char *more_or_less;
+    if (num_found < num_min) {
+        num_expected = num_min;
+        more_or_less = "at least";
+    } else {
+        num_expected = num_max;
+        more_or_less = "at most";
+    }
+    if (exact) {
+        more_or_less = "exactly";
+    }
+    PyErr_Format(PyExc_TypeError,
+                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
+                 func_name, more_or_less, num_expected,
+                 (num_expected == 1) ? "" : "s", num_found);
+}
+
+/* GetModuleGlobalName */
+#if CYTHON_USE_DICT_VERSIONS
+static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
+#else
+static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
+#endif
+{
+    PyObject *result;
+#if !CYTHON_AVOID_BORROWED_REFS
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
+    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
+    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
+    if (likely(result)) {
+        return __Pyx_NewRef(result);
+    } else if (unlikely(PyErr_Occurred())) {
+        return NULL;
+    }
+#else
+    result = PyDict_GetItem(__pyx_d, name);
+    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
+    if (likely(result)) {
+        return __Pyx_NewRef(result);
+    }
+#endif
+#else
+    result = PyObject_GetItem(__pyx_d, name);
+    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
+    if (likely(result)) {
+        return __Pyx_NewRef(result);
+    }
+    PyErr_Clear();
+#endif
+    return __Pyx_GetBuiltinName(name);
+}
+
+/* PyObjectCall2Args */
+static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
+    PyObject *args, *result = NULL;
+    #if CYTHON_FAST_PYCALL
+    if (PyFunction_Check(function)) {
+        PyObject *args[2] = {arg1, arg2};
+        return __Pyx_PyFunction_FastCall(function, args, 2);
+    }
+    #endif
+    #if CYTHON_FAST_PYCCALL
+    if (__Pyx_PyFastCFunction_Check(function)) {
+        PyObject *args[2] = {arg1, arg2};
+        return __Pyx_PyCFunction_FastCall(function, args, 2);
+    }
+    #endif
+    args = PyTuple_New(2);
+    if (unlikely(!args)) goto done;
+    Py_INCREF(arg1);
+    PyTuple_SET_ITEM(args, 0, arg1);
+    Py_INCREF(arg2);
+    PyTuple_SET_ITEM(args, 1, arg2);
+    Py_INCREF(function);
+    result = __Pyx_PyObject_Call(function, args, NULL);
+    Py_DECREF(args);
+    Py_DECREF(function);
+done:
+    return result;
+}
+
+/* BytesEquals */
+static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
+#if CYTHON_COMPILING_IN_PYPY
+    return PyObject_RichCompareBool(s1, s2, equals);
+#else
+    if (s1 == s2) {
+        return (equals == Py_EQ);
+    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
+        const char *ps1, *ps2;
+        Py_ssize_t length = PyBytes_GET_SIZE(s1);
+        if (length != PyBytes_GET_SIZE(s2))
+            return (equals == Py_NE);
+        ps1 = PyBytes_AS_STRING(s1);
+        ps2 = PyBytes_AS_STRING(s2);
+        if (ps1[0] != ps2[0]) {
+            return (equals == Py_NE);
+        } else if (length == 1) {
+            return (equals == Py_EQ);
+        } else {
+            int result;
+#if CYTHON_USE_UNICODE_INTERNALS
+            Py_hash_t hash1, hash2;
+            hash1 = ((PyBytesObject*)s1)->ob_shash;
+            hash2 = ((PyBytesObject*)s2)->ob_shash;
+            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
+                return (equals == Py_NE);
+            }
+#endif
+            result = memcmp(ps1, ps2, (size_t)length);
+            return (equals == Py_EQ) ? (result == 0) : (result != 0);
+        }
+    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
+        return (equals == Py_NE);
+    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
+        return (equals == Py_NE);
+    } else {
+        int result;
+        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
+        if (!py_result)
+            return -1;
+        result = __Pyx_PyObject_IsTrue(py_result);
+        Py_DECREF(py_result);
+        return result;
+    }
+#endif
+}
+
+/* UnicodeEquals */
+static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
+#if CYTHON_COMPILING_IN_PYPY
+    return PyObject_RichCompareBool(s1, s2, equals);
+#else
+#if PY_MAJOR_VERSION < 3
+    PyObject* owned_ref = NULL;
+#endif
+    int s1_is_unicode, s2_is_unicode;
+    if (s1 == s2) {
+        goto return_eq;
+    }
+    s1_is_unicode = PyUnicode_CheckExact(s1);
+    s2_is_unicode = PyUnicode_CheckExact(s2);
+#if PY_MAJOR_VERSION < 3
+    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
+        owned_ref = PyUnicode_FromObject(s2);
+        if (unlikely(!owned_ref))
+            return -1;
+        s2 = owned_ref;
+        s2_is_unicode = 1;
+    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
+        owned_ref = PyUnicode_FromObject(s1);
+        if (unlikely(!owned_ref))
+            return -1;
+        s1 = owned_ref;
+        s1_is_unicode = 1;
+    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
+        return __Pyx_PyBytes_Equals(s1, s2, equals);
+    }
+#endif
+    if (s1_is_unicode & s2_is_unicode) {
+        Py_ssize_t length;
+        int kind;
+        void *data1, *data2;
+        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
+            return -1;
+        length = __Pyx_PyUnicode_GET_LENGTH(s1);
+        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
+            goto return_ne;
+        }
+#if CYTHON_USE_UNICODE_INTERNALS
+        {
+            Py_hash_t hash1, hash2;
+        #if CYTHON_PEP393_ENABLED
+            hash1 = ((PyASCIIObject*)s1)->hash;
+            hash2 = ((PyASCIIObject*)s2)->hash;
+        #else
+            hash1 = ((PyUnicodeObject*)s1)->hash;
+            hash2 = ((PyUnicodeObject*)s2)->hash;
+        #endif
+            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
+                goto return_ne;
+            }
+        }
+#endif
+        kind = __Pyx_PyUnicode_KIND(s1);
+        if (kind != __Pyx_PyUnicode_KIND(s2)) {
+            goto return_ne;
+        }
+        data1 = __Pyx_PyUnicode_DATA(s1);
+        data2 = __Pyx_PyUnicode_DATA(s2);
+        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
+            goto return_ne;
+        } else if (length == 1) {
+            goto return_eq;
+        } else {
+            int result = memcmp(data1, data2, (size_t)(length * kind));
+            #if PY_MAJOR_VERSION < 3
+            Py_XDECREF(owned_ref);
+            #endif
+            return (equals == Py_EQ) ? (result == 0) : (result != 0);
+        }
+    } else if ((s1 == Py_None) & s2_is_unicode) {
+        goto return_ne;
+    } else if ((s2 == Py_None) & s1_is_unicode) {
+        goto return_ne;
+    } else {
+        int result;
+        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
+        #if PY_MAJOR_VERSION < 3
+        Py_XDECREF(owned_ref);
+        #endif
+        if (!py_result)
+            return -1;
+        result = __Pyx_PyObject_IsTrue(py_result);
+        Py_DECREF(py_result);
+        return result;
+    }
+return_eq:
+    #if PY_MAJOR_VERSION < 3
+    Py_XDECREF(owned_ref);
+    #endif
+    return (equals == Py_EQ);
+return_ne:
+    #if PY_MAJOR_VERSION < 3
+    Py_XDECREF(owned_ref);
+    #endif
+    return (equals == Py_NE);
+#endif
+}
+
+/* PyErrFetchRestore */
+#if CYTHON_FAST_THREAD_STATE
+static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    tmp_type = tstate->curexc_type;
+    tmp_value = tstate->curexc_value;
+    tmp_tb = tstate->curexc_traceback;
+    tstate->curexc_type = type;
+    tstate->curexc_value = value;
+    tstate->curexc_traceback = tb;
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+}
+static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
+    *type = tstate->curexc_type;
+    *value = tstate->curexc_value;
+    *tb = tstate->curexc_traceback;
+    tstate->curexc_type = 0;
+    tstate->curexc_value = 0;
+    tstate->curexc_traceback = 0;
+}
+#endif
+
+/* RaiseException */
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
+                        CYTHON_UNUSED PyObject *cause) {
+    __Pyx_PyThreadState_declare
+    Py_XINCREF(type);
+    if (!value || value == Py_None)
+        value = NULL;
+    else
+        Py_INCREF(value);
+    if (!tb || tb == Py_None)
+        tb = NULL;
+    else {
+        Py_INCREF(tb);
+        if (!PyTraceBack_Check(tb)) {
+            PyErr_SetString(PyExc_TypeError,
+                "raise: arg 3 must be a traceback or None");
+            goto raise_error;
+        }
+    }
+    if (PyType_Check(type)) {
+#if CYTHON_COMPILING_IN_PYPY
+        if (!value) {
+            Py_INCREF(Py_None);
+            value = Py_None;
+        }
+#endif
+        PyErr_NormalizeException(&type, &value, &tb);
+    } else {
+        if (value) {
+            PyErr_SetString(PyExc_TypeError,
+                "instance exception may not have a separate value");
+            goto raise_error;
+        }
+        value = type;
+        type = (PyObject*) Py_TYPE(type);
+        Py_INCREF(type);
+        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+            PyErr_SetString(PyExc_TypeError,
+                "raise: exception class must be a subclass of BaseException");
+            goto raise_error;
+        }
+    }
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrRestore(type, value, tb);
+    return;
+raise_error:
+    Py_XDECREF(value);
+    Py_XDECREF(type);
+    Py_XDECREF(tb);
+    return;
+}
+#else
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+    PyObject* owned_instance = NULL;
+    if (tb == Py_None) {
+        tb = 0;
+    } else if (tb && !PyTraceBack_Check(tb)) {
+        PyErr_SetString(PyExc_TypeError,
+            "raise: arg 3 must be a traceback or None");
+        goto bad;
+    }
+    if (value == Py_None)
+        value = 0;
+    if (PyExceptionInstance_Check(type)) {
+        if (value) {
+            PyErr_SetString(PyExc_TypeError,
+                "instance exception may not have a separate value");
+            goto bad;
+        }
+        value = type;
+        type = (PyObject*) Py_TYPE(value);
+    } else if (PyExceptionClass_Check(type)) {
+        PyObject *instance_class = NULL;
+        if (value && PyExceptionInstance_Check(value)) {
+            instance_class = (PyObject*) Py_TYPE(value);
+            if (instance_class != type) {
+                int is_subclass = PyObject_IsSubclass(instance_class, type);
+                if (!is_subclass) {
+                    instance_class = NULL;
+                } else if (unlikely(is_subclass == -1)) {
+                    goto bad;
+                } else {
+                    type = instance_class;
+                }
+            }
+        }
+        if (!instance_class) {
+            PyObject *args;
+            if (!value)
+                args = PyTuple_New(0);
+            else if (PyTuple_Check(value)) {
+                Py_INCREF(value);
+                args = value;
+            } else
+                args = PyTuple_Pack(1, value);
+            if (!args)
+                goto bad;
+            owned_instance = PyObject_Call(type, args, NULL);
+            Py_DECREF(args);
+            if (!owned_instance)
+                goto bad;
+            value = owned_instance;
+            if (!PyExceptionInstance_Check(value)) {
+                PyErr_Format(PyExc_TypeError,
+                             "calling %R should have returned an instance of "
+                             "BaseException, not %R",
+                             type, Py_TYPE(value));
+                goto bad;
+            }
+        }
+    } else {
+        PyErr_SetString(PyExc_TypeError,
+            "raise: exception class must be a subclass of BaseException");
+        goto bad;
+    }
+    if (cause) {
+        PyObject *fixed_cause;
+        if (cause == Py_None) {
+            fixed_cause = NULL;
+        } else if (PyExceptionClass_Check(cause)) {
+            fixed_cause = PyObject_CallObject(cause, NULL);
+            if (fixed_cause == NULL)
+                goto bad;
+        } else if (PyExceptionInstance_Check(cause)) {
+            fixed_cause = cause;
+            Py_INCREF(fixed_cause);
+        } else {
+            PyErr_SetString(PyExc_TypeError,
+                            "exception causes must derive from "
+                            "BaseException");
+            goto bad;
+        }
+        PyException_SetCause(value, fixed_cause);
+    }
+    PyErr_SetObject(type, value);
+    if (tb) {
+#if CYTHON_COMPILING_IN_PYPY
+        PyObject *tmp_type, *tmp_value, *tmp_tb;
+        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
+        Py_INCREF(tb);
+        PyErr_Restore(tmp_type, tmp_value, tb);
+        Py_XDECREF(tmp_tb);
+#else
+        PyThreadState *tstate = __Pyx_PyThreadState_Current;
+        PyObject* tmp_tb = tstate->curexc_traceback;
+        if (tb != tmp_tb) {
+            Py_INCREF(tb);
+            tstate->curexc_traceback = tb;
+            Py_XDECREF(tmp_tb);
+        }
+#endif
+    }
+bad:
+    Py_XDECREF(owned_instance);
+    return;
+}
+#endif
+
+/* DictGetItem */
+#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
+static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
+    PyObject *value;
+    value = PyDict_GetItemWithError(d, key);
+    if (unlikely(!value)) {
+        if (!PyErr_Occurred()) {
+            if (unlikely(PyTuple_Check(key))) {
+                PyObject* args = PyTuple_Pack(1, key);
+                if (likely(args)) {
+                    PyErr_SetObject(PyExc_KeyError, args);
+                    Py_DECREF(args);
+                }
+            } else {
+                PyErr_SetObject(PyExc_KeyError, key);
+            }
+        }
+        return NULL;
+    }
+    Py_INCREF(value);
+    return value;
+}
+#endif
+
+/* GetTopmostException */
+#if CYTHON_USE_EXC_INFO_STACK
+static _PyErr_StackItem *
+__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
+{
+    _PyErr_StackItem *exc_info = tstate->exc_info;
+    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
+           exc_info->previous_item != NULL)
+    {
+        exc_info = exc_info->previous_item;
+    }
+    return exc_info;
+}
+#endif
+
+/* SaveResetException */
+#if CYTHON_FAST_THREAD_STATE
+static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
+    #if CYTHON_USE_EXC_INFO_STACK
+    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
+    *type = exc_info->exc_type;
+    *value = exc_info->exc_value;
+    *tb = exc_info->exc_traceback;
+    #else
+    *type = tstate->exc_type;
+    *value = tstate->exc_value;
+    *tb = tstate->exc_traceback;
+    #endif
+    Py_XINCREF(*type);
+    Py_XINCREF(*value);
+    Py_XINCREF(*tb);
+}
+static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    #if CYTHON_USE_EXC_INFO_STACK
+    _PyErr_StackItem *exc_info = tstate->exc_info;
+    tmp_type = exc_info->exc_type;
+    tmp_value = exc_info->exc_value;
+    tmp_tb = exc_info->exc_traceback;
+    exc_info->exc_type = type;
+    exc_info->exc_value = value;
+    exc_info->exc_traceback = tb;
+    #else
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = type;
+    tstate->exc_value = value;
+    tstate->exc_traceback = tb;
+    #endif
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+}
+#endif
+
+/* PyErrExceptionMatches */
+#if CYTHON_FAST_THREAD_STATE
+static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
+    Py_ssize_t i, n;
+    n = PyTuple_GET_SIZE(tuple);
+#if PY_MAJOR_VERSION >= 3
+    for (i=0; i<n; i++) {
+        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
+    }
+#endif
+    for (i=0; i<n; i++) {
+        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
+    }
+    return 0;
+}
+static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
+    PyObject *exc_type = tstate->curexc_type;
+    if (exc_type == err) return 1;
+    if (unlikely(!exc_type)) return 0;
+    if (unlikely(PyTuple_Check(err)))
+        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
+    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
+}
+#endif
+
+/* GetException */
+#if CYTHON_FAST_THREAD_STATE
+static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
+#else
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
+#endif
+{
+    PyObject *local_type, *local_value, *local_tb;
+#if CYTHON_FAST_THREAD_STATE
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    local_type = tstate->curexc_type;
+    local_value = tstate->curexc_value;
+    local_tb = tstate->curexc_traceback;
+    tstate->curexc_type = 0;
+    tstate->curexc_value = 0;
+    tstate->curexc_traceback = 0;
+#else
+    PyErr_Fetch(&local_type, &local_value, &local_tb);
+#endif
+    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
+#if CYTHON_FAST_THREAD_STATE
+    if (unlikely(tstate->curexc_type))
+#else
+    if (unlikely(PyErr_Occurred()))
+#endif
+        goto bad;
+    #if PY_MAJOR_VERSION >= 3
+    if (local_tb) {
+        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
+            goto bad;
+    }
+    #endif
+    Py_XINCREF(local_tb);
+    Py_XINCREF(local_type);
+    Py_XINCREF(local_value);
+    *type = local_type;
+    *value = local_value;
+    *tb = local_tb;
+#if CYTHON_FAST_THREAD_STATE
+    #if CYTHON_USE_EXC_INFO_STACK
+    {
+        _PyErr_StackItem *exc_info = tstate->exc_info;
+        tmp_type = exc_info->exc_type;
+        tmp_value = exc_info->exc_value;
+        tmp_tb = exc_info->exc_traceback;
+        exc_info->exc_type = local_type;
+        exc_info->exc_value = local_value;
+        exc_info->exc_traceback = local_tb;
+    }
+    #else
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = local_type;
+    tstate->exc_value = local_value;
+    tstate->exc_traceback = local_tb;
+    #endif
+    Py_XDECREF(tmp_type);
+    Py_XDECREF(tmp_value);
+    Py_XDECREF(tmp_tb);
+#else
+    PyErr_SetExcInfo(local_type, local_value, local_tb);
+#endif
+    return 0;
+bad:
+    *type = 0;
+    *value = 0;
+    *tb = 0;
+    Py_XDECREF(local_type);
+    Py_XDECREF(local_value);
+    Py_XDECREF(local_tb);
+    return -1;
+}
+
+/* GetItemInt */
+static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+    PyObject *r;
+    if (!j) return NULL;
+    r = PyObject_GetItem(o, j);
+    Py_DECREF(j);
+    return r;
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    Py_ssize_t wrapped_i = i;
+    if (wraparound & unlikely(i < 0)) {
+        wrapped_i += PyList_GET_SIZE(o);
+    }
+    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
+        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    Py_ssize_t wrapped_i = i;
+    if (wraparound & unlikely(i < 0)) {
+        wrapped_i += PyTuple_GET_SIZE(o);
+    }
+    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
+        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
+                                                     CYTHON_NCP_UNUSED int wraparound,
+                                                     CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
+    if (is_list || PyList_CheckExact(o)) {
+        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
+            PyObject *r = PyList_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    }
+    else if (PyTuple_CheckExact(o)) {
+        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
+            PyObject *r = PyTuple_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    } else {
+        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+        if (likely(m && m->sq_item)) {
+            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
+                Py_ssize_t l = m->sq_length(o);
+                if (likely(l >= 0)) {
+                    i += l;
+                } else {
+                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
+                        return NULL;
+                    PyErr_Clear();
+                }
+            }
+            return m->sq_item(o, i);
+        }
+    }
+#else
+    if (is_list || PySequence_Check(o)) {
+        return PySequence_GetItem(o, i);
+    }
+#endif
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+/* ObjectGetItem */
+#if CYTHON_USE_TYPE_SLOTS
+static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
+    PyObject *runerr;
+    Py_ssize_t key_value;
+    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
+    if (unlikely(!(m && m->sq_item))) {
+        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
+        return NULL;
+    }
+    key_value = __Pyx_PyIndex_AsSsize_t(index);
+    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
+        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
+    }
+    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
+        PyErr_Clear();
+        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
+    }
+    return NULL;
+}
+static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
+    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
+    if (likely(m && m->mp_subscript)) {
+        return m->mp_subscript(obj, key);
+    }
+    return __Pyx_PyObject_GetIndex(obj, key);
+}
+#endif
+
+/* ExtTypeTest */
+static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+    if (unlikely(!type)) {
+        PyErr_SetString(PyExc_SystemError, "Missing type object");
+        return 0;
+    }
+    if (likely(__Pyx_TypeCheck(obj, type)))
+        return 1;
+    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
+                 Py_TYPE(obj)->tp_name, type->tp_name);
+    return 0;
+}
+
+/* SliceObject */
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
+        Py_ssize_t cstart, Py_ssize_t cstop,
+        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
+        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
+#if CYTHON_USE_TYPE_SLOTS
+    PyMappingMethods* mp;
+#if PY_MAJOR_VERSION < 3
+    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
+    if (likely(ms && ms->sq_slice)) {
+        if (!has_cstart) {
+            if (_py_start && (*_py_start != Py_None)) {
+                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
+                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
+            } else
+                cstart = 0;
+        }
+        if (!has_cstop) {
+            if (_py_stop && (*_py_stop != Py_None)) {
+                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
+                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
+            } else
+                cstop = PY_SSIZE_T_MAX;
+        }
+        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
+            Py_ssize_t l = ms->sq_length(obj);
+            if (likely(l >= 0)) {
+                if (cstop < 0) {
+                    cstop += l;
+                    if (cstop < 0) cstop = 0;
+                }
+                if (cstart < 0) {
+                    cstart += l;
+                    if (cstart < 0) cstart = 0;
+                }
+            } else {
+                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
+                    goto bad;
+                PyErr_Clear();
+            }
+        }
+        return ms->sq_slice(obj, cstart, cstop);
+    }
+#endif
+    mp = Py_TYPE(obj)->tp_as_mapping;
+    if (likely(mp && mp->mp_subscript))
+#endif
+    {
+        PyObject* result;
+        PyObject *py_slice, *py_start, *py_stop;
+        if (_py_slice) {
+            py_slice = *_py_slice;
+        } else {
+            PyObject* owned_start = NULL;
+            PyObject* owned_stop = NULL;
+            if (_py_start) {
+                py_start = *_py_start;
+            } else {
+                if (has_cstart) {
+                    owned_start = py_start = PyInt_FromSsize_t(cstart);
+                    if (unlikely(!py_start)) goto bad;
+                } else
+                    py_start = Py_None;
+            }
+            if (_py_stop) {
+                py_stop = *_py_stop;
+            } else {
+                if (has_cstop) {
+                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
+                    if (unlikely(!py_stop)) {
+                        Py_XDECREF(owned_start);
+                        goto bad;
+                    }
+                } else
+                    py_stop = Py_None;
+            }
+            py_slice = PySlice_New(py_start, py_stop, Py_None);
+            Py_XDECREF(owned_start);
+            Py_XDECREF(owned_stop);
+            if (unlikely(!py_slice)) goto bad;
+        }
+#if CYTHON_USE_TYPE_SLOTS
+        result = mp->mp_subscript(obj, py_slice);
+#else
+        result = PyObject_GetItem(obj, py_slice);
+#endif
+        if (!_py_slice) {
+            Py_DECREF(py_slice);
+        }
+        return result;
+    }
+    PyErr_Format(PyExc_TypeError,
+        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
+bad:
+    return NULL;
+}
+
+/* PyIntBinop */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_CheckExact(op1))) {
+        const long b = intval;
+        long x;
+        long a = PyInt_AS_LONG(op1);
+            x = (long)((unsigned long)a + b);
+            if (likely((x^a) >= 0 || (x^b) >= 0))
+                return PyInt_FromLong(x);
+            return PyLong_Type.tp_as_number->nb_add(op1, op2);
+    }
+    #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    if (likely(PyLong_CheckExact(op1))) {
+        const long b = intval;
+        long a, x;
+#ifdef HAVE_LONG_LONG
+        const PY_LONG_LONG llb = intval;
+        PY_LONG_LONG lla, llx;
+#endif
+        const digit* digits = ((PyLongObject*)op1)->ob_digit;
+        const Py_ssize_t size = Py_SIZE(op1);
+        if (likely(__Pyx_sst_abs(size) <= 1)) {
+            a = likely(size) ? digits[0] : 0;
+            if (size == -1) a = -a;
+        } else {
+            switch (size) {
+                case -2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
+            }
+        }
+                x = a + b;
+            return PyLong_FromLong(x);
+#ifdef HAVE_LONG_LONG
+        long_long:
+                llx = lla + llb;
+            return PyLong_FromLongLong(llx);
+#endif
+        
+        
+    }
+    #endif
+    if (PyFloat_CheckExact(op1)) {
+        const long b = intval;
+        double a = PyFloat_AS_DOUBLE(op1);
+            double result;
+            PyFPE_START_PROTECT("add", return NULL)
+            result = ((double)a) + (double)b;
+            PyFPE_END_PROTECT(result)
+            return PyFloat_FromDouble(result);
+    }
+    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
+}
+#endif
+
+/* py_dict_pop */
+static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) {
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B3
+    if ((1)) {
+        return _PyDict_Pop(d, key, default_value);
+    } else
+#endif
+    if (default_value) {
+        return __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_pop, d, key, default_value);
+    } else {
+        return __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_pop, d, key);
+    }
+}
+
+/* JoinPyUnicode */
+static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
+                                      CYTHON_UNUSED Py_UCS4 max_char) {
+#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    PyObject *result_uval;
+    int result_ukind;
+    Py_ssize_t i, char_pos;
+    void *result_udata;
+#if CYTHON_PEP393_ENABLED
+    result_uval = PyUnicode_New(result_ulength, max_char);
+    if (unlikely(!result_uval)) return NULL;
+    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
+    result_udata = PyUnicode_DATA(result_uval);
+#else
+    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
+    if (unlikely(!result_uval)) return NULL;
+    result_ukind = sizeof(Py_UNICODE);
+    result_udata = PyUnicode_AS_UNICODE(result_uval);
+#endif
+    char_pos = 0;
+    for (i=0; i < value_count; i++) {
+        int ukind;
+        Py_ssize_t ulength;
+        void *udata;
+        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
+        if (unlikely(__Pyx_PyUnicode_READY(uval)))
+            goto bad;
+        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
+        if (unlikely(!ulength))
+            continue;
+        if (unlikely(char_pos + ulength < 0))
+            goto overflow;
+        ukind = __Pyx_PyUnicode_KIND(uval);
+        udata = __Pyx_PyUnicode_DATA(uval);
+        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
+            memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind));
+        } else {
+            #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
+            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
+            #else
+            Py_ssize_t j;
+            for (j=0; j < ulength; j++) {
+                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
+                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
+            }
+            #endif
+        }
+        char_pos += ulength;
+    }
+    return result_uval;
+overflow:
+    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
+bad:
+    Py_DECREF(result_uval);
+    return NULL;
+#else
+    result_ulength++;
+    value_count++;
+    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
+#endif
+}
+
+/* ArgTypeTest */
+static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
+{
+    if (unlikely(!type)) {
+        PyErr_SetString(PyExc_SystemError, "Missing type object");
+        return 0;
+    }
+    else if (exact) {
+        #if PY_MAJOR_VERSION == 2
+        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
+        #endif
+    }
+    else {
+        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
+    }
+    PyErr_Format(PyExc_TypeError,
+        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
+        name, type->tp_name, Py_TYPE(obj)->tp_name);
+    return 0;
+}
+
+/* GetAttr */
+static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
+#if CYTHON_USE_TYPE_SLOTS
+#if PY_MAJOR_VERSION >= 3
+    if (likely(PyUnicode_Check(n)))
+#else
+    if (likely(PyString_Check(n)))
+#endif
+        return __Pyx_PyObject_GetAttrStr(o, n);
+#endif
+    return PyObject_GetAttr(o, n);
+}
+
+/* GetAttr3 */
+static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
+        return NULL;
+    __Pyx_PyErr_Clear();
+    Py_INCREF(d);
+    return d;
+}
+static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
+    PyObject *r = __Pyx_GetAttr(o, n);
+    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
+}
+
+/* SwapException */
+#if CYTHON_FAST_THREAD_STATE
+static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    #if CYTHON_USE_EXC_INFO_STACK
+    _PyErr_StackItem *exc_info = tstate->exc_info;
+    tmp_type = exc_info->exc_type;
+    tmp_value = exc_info->exc_value;
+    tmp_tb = exc_info->exc_traceback;
+    exc_info->exc_type = *type;
+    exc_info->exc_value = *value;
+    exc_info->exc_traceback = *tb;
+    #else
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = *type;
+    tstate->exc_value = *value;
+    tstate->exc_traceback = *tb;
+    #endif
+    *type = tmp_type;
+    *value = tmp_value;
+    *tb = tmp_tb;
+}
+#else
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
+    PyErr_SetExcInfo(*type, *value, *tb);
+    *type = tmp_type;
+    *value = tmp_value;
+    *tb = tmp_tb;
+}
+#endif
+
+/* PyIntBinop */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_CheckExact(op1))) {
+        const long b = intval;
+        long x;
+        long a = PyInt_AS_LONG(op1);
+            x = (long)((unsigned long)a - b);
+            if (likely((x^a) >= 0 || (x^~b) >= 0))
+                return PyInt_FromLong(x);
+            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
+    }
+    #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    if (likely(PyLong_CheckExact(op1))) {
+        const long b = intval;
+        long a, x;
+#ifdef HAVE_LONG_LONG
+        const PY_LONG_LONG llb = intval;
+        PY_LONG_LONG lla, llx;
+#endif
+        const digit* digits = ((PyLongObject*)op1)->ob_digit;
+        const Py_ssize_t size = Py_SIZE(op1);
+        if (likely(__Pyx_sst_abs(size) <= 1)) {
+            a = likely(size) ? digits[0] : 0;
+            if (size == -1) a = -a;
+        } else {
+            switch (size) {
+                case -2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
+            }
+        }
+                x = a - b;
+            return PyLong_FromLong(x);
+#ifdef HAVE_LONG_LONG
+        long_long:
+                llx = lla - llb;
+            return PyLong_FromLongLong(llx);
+#endif
+        
+        
+    }
+    #endif
+    if (PyFloat_CheckExact(op1)) {
+        const long b = intval;
+        double a = PyFloat_AS_DOUBLE(op1);
+            double result;
+            PyFPE_START_PROTECT("subtract", return NULL)
+            result = ((double)a) - (double)b;
+            PyFPE_END_PROTECT(result)
+            return PyFloat_FromDouble(result);
+    }
+    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
+}
+#endif
+
+/* None */
+static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
+    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
+}
+
+/* WriteUnraisableException */
+static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
+                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
+                                  int full_traceback, CYTHON_UNUSED int nogil) {
+    PyObject *old_exc, *old_val, *old_tb;
+    PyObject *ctx;
+    __Pyx_PyThreadState_declare
+#ifdef WITH_THREAD
+    PyGILState_STATE state;
+    if (nogil)
+        state = PyGILState_Ensure();
+#ifdef _MSC_VER
+    else state = (PyGILState_STATE)-1;
+#endif
+#endif
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
+    if (full_traceback) {
+        Py_XINCREF(old_exc);
+        Py_XINCREF(old_val);
+        Py_XINCREF(old_tb);
+        __Pyx_ErrRestore(old_exc, old_val, old_tb);
+        PyErr_PrintEx(1);
+    }
+    #if PY_MAJOR_VERSION < 3
+    ctx = PyString_FromString(name);
+    #else
+    ctx = PyUnicode_FromString(name);
+    #endif
+    __Pyx_ErrRestore(old_exc, old_val, old_tb);
+    if (!ctx) {
+        PyErr_WriteUnraisable(Py_None);
+    } else {
+        PyErr_WriteUnraisable(ctx);
+        Py_DECREF(ctx);
+    }
+#ifdef WITH_THREAD
+    if (nogil)
+        PyGILState_Release(state);
+#endif
+}
+
+/* PyIntBinop */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_CheckExact(op2))) {
+        const long a = intval;
+        long x;
+        long b = PyInt_AS_LONG(op2);
+            x = (long)((unsigned long)a + b);
+            if (likely((x^a) >= 0 || (x^b) >= 0))
+                return PyInt_FromLong(x);
+            return PyLong_Type.tp_as_number->nb_add(op1, op2);
+    }
+    #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    if (likely(PyLong_CheckExact(op2))) {
+        const long a = intval;
+        long b, x;
+#ifdef HAVE_LONG_LONG
+        const PY_LONG_LONG lla = intval;
+        PY_LONG_LONG llb, llx;
+#endif
+        const digit* digits = ((PyLongObject*)op2)->ob_digit;
+        const Py_ssize_t size = Py_SIZE(op2);
+        if (likely(__Pyx_sst_abs(size) <= 1)) {
+            b = likely(size) ? digits[0] : 0;
+            if (size == -1) b = -b;
+        } else {
+            switch (size) {
+                case -2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        llb = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        llb = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        llb = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                case 4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+#ifdef HAVE_LONG_LONG
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        llb = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+#endif
+                    }
+                    CYTHON_FALLTHROUGH;
+                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
+            }
+        }
+                x = a + b;
+            return PyLong_FromLong(x);
+#ifdef HAVE_LONG_LONG
+        long_long:
+                llx = lla + llb;
+            return PyLong_FromLongLong(llx);
+#endif
+        
+        
+    }
+    #endif
+    if (PyFloat_CheckExact(op2)) {
+        const long a = intval;
+        double b = PyFloat_AS_DOUBLE(op2);
+            double result;
+            PyFPE_START_PROTECT("add", return NULL)
+            result = ((double)a) + (double)b;
+            PyFPE_END_PROTECT(result)
+            return PyFloat_FromDouble(result);
+    }
+    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
+}
+#endif
+
+/* PyObjectSetAttrStr */
+#if CYTHON_USE_TYPE_SLOTS
+static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
+    PyTypeObject* tp = Py_TYPE(obj);
+    if (likely(tp->tp_setattro))
+        return tp->tp_setattro(obj, attr_name, value);
+#if PY_MAJOR_VERSION < 3
+    if (likely(tp->tp_setattr))
+        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
+#endif
+    return PyObject_SetAttr(obj, attr_name, value);
+}
+#endif
+
+/* PyObjectFormatAndDecref */
+static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) {
+    if (unlikely(!s)) return NULL;
+    if (likely(PyUnicode_CheckExact(s))) return s;
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyString_CheckExact(s))) {
+        PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict");
+        Py_DECREF(s);
+        return result;
+    }
+    #endif
+    return __Pyx_PyObject_FormatAndDecref(s, f);
+}
+static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) {
+    PyObject *result = PyObject_Format(s, f);
+    Py_DECREF(s);
+    return result;
+}
+
+/* CIntToDigits */
+static const char DIGIT_PAIRS_10[2*10*10+1] = {
+    "00010203040506070809"
+    "10111213141516171819"
+    "20212223242526272829"
+    "30313233343536373839"
+    "40414243444546474849"
+    "50515253545556575859"
+    "60616263646566676869"
+    "70717273747576777879"
+    "80818283848586878889"
+    "90919293949596979899"
+};
+static const char DIGIT_PAIRS_8[2*8*8+1] = {
+    "0001020304050607"
+    "1011121314151617"
+    "2021222324252627"
+    "3031323334353637"
+    "4041424344454647"
+    "5051525354555657"
+    "6061626364656667"
+    "7071727374757677"
+};
+static const char DIGITS_HEX[2*16+1] = {
+    "0123456789abcdef"
+    "0123456789ABCDEF"
+};
+
+/* BuildPyUnicode */
+static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
+                                                int prepend_sign, char padding_char) {
+    PyObject *uval;
+    Py_ssize_t uoffset = ulength - clength;
+#if CYTHON_USE_UNICODE_INTERNALS
+    Py_ssize_t i;
+#if CYTHON_PEP393_ENABLED
+    void *udata;
+    uval = PyUnicode_New(ulength, 127);
+    if (unlikely(!uval)) return NULL;
+    udata = PyUnicode_DATA(uval);
+#else
+    Py_UNICODE *udata;
+    uval = PyUnicode_FromUnicode(NULL, ulength);
+    if (unlikely(!uval)) return NULL;
+    udata = PyUnicode_AS_UNICODE(uval);
+#endif
+    if (uoffset > 0) {
+        i = 0;
+        if (prepend_sign) {
+            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
+            i++;
+        }
+        for (; i < uoffset; i++) {
+            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
+        }
+    }
+    for (i=0; i < clength; i++) {
+        __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
+    }
+#else
+    {
+        uval = NULL;
+        PyObject *sign = NULL, *padding = NULL;
+        if (uoffset > 0) {
+            prepend_sign = !!prepend_sign;
+            if (uoffset > prepend_sign) {
+                padding = PyUnicode_FromOrdinal(padding_char);
+                if (likely(padding) && uoffset > prepend_sign + 1) {
+                    PyObject *tmp;
+                    PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign);
+                    if (unlikely(!repeat)) goto done_or_error;
+                    tmp = PyNumber_Multiply(padding, repeat);
+                    Py_DECREF(repeat);
+                    Py_DECREF(padding);
+                    padding = tmp;
+                }
+                if (unlikely(!padding)) goto done_or_error;
+            }
+            if (prepend_sign) {
+                sign = PyUnicode_FromOrdinal('-');
+                if (unlikely(!sign)) goto done_or_error;
+            }
+        }
+        uval = PyUnicode_DecodeASCII(chars, clength, NULL);
+        if (likely(uval) && padding) {
+            PyObject *tmp = PyNumber_Add(padding, uval);
+            Py_DECREF(uval);
+            uval = tmp;
+        }
+        if (likely(uval) && sign) {
+            PyObject *tmp = PyNumber_Add(sign, uval);
+            Py_DECREF(uval);
+            uval = tmp;
+        }
+done_or_error:
+        Py_XDECREF(padding);
+        Py_XDECREF(sign);
+    }
+#endif
+    return uval;
+}
+
+/* CIntToPyUnicode */
+#ifdef _MSC_VER
+    #ifndef _MSC_STDINT_H_
+        #if _MSC_VER < 1300
+           typedef unsigned short    uint16_t;
+        #else
+           typedef unsigned __int16  uint16_t;
+        #endif
+    #endif
+#else
+   #include <stdint.h>
+#endif
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState value, Py_ssize_t width, char padding_char, char format_char) {
+    char digits[sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)*3+2];
+    char *dpos, *end = digits + sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)*3+2;
+    const char *hex_digits = DIGITS_HEX;
+    Py_ssize_t length, ulength;
+    int prepend_sign, last_one_off;
+    enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState remaining;
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (format_char == 'X') {
+        hex_digits += 16;
+        format_char = 'x';
+    }
+    remaining = value;
+    last_one_off = 0;
+    dpos = end;
+    do {
+        int digit_pos;
+        switch (format_char) {
+        case 'o':
+            digit_pos = abs((int)(remaining % (8*8)));
+            remaining = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (remaining / (8*8));
+            dpos -= 2;
+            *(uint16_t*)dpos = ((uint16_t*)DIGIT_PAIRS_8)[digit_pos];
+            last_one_off = (digit_pos < 8);
+            break;
+        case 'd':
+            digit_pos = abs((int)(remaining % (10*10)));
+            remaining = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (remaining / (10*10));
+            dpos -= 2;
+            *(uint16_t*)dpos = ((uint16_t*)DIGIT_PAIRS_10)[digit_pos];
+            last_one_off = (digit_pos < 10);
+            break;
+        case 'x':
+            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
+            remaining = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (remaining / 16);
+            break;
+        default:
+            assert(0);
+            break;
+        }
+    } while (unlikely(remaining != 0));
+    if (last_one_off) {
+        assert(*dpos == '0');
+        dpos++;
+    }
+    length = end - dpos;
+    ulength = length;
+    prepend_sign = 0;
+    if (!is_unsigned && value <= neg_one) {
+        if (padding_char == ' ' || width <= length + 1) {
+            *(--dpos) = '-';
+            ++length;
+        } else {
+            prepend_sign = 1;
+        }
+        ++ulength;
+    }
+    if (width > ulength) {
+        ulength = width;
+    }
+    if (ulength == 1) {
+        return PyUnicode_FromOrdinal(*dpos);
+    }
+    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
+}
+
+/* IterNext */
+static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) {
+    PyObject* exc_type;
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    exc_type = __Pyx_PyErr_Occurred();
+    if (unlikely(exc_type)) {
+        if (!defval || unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
+            return NULL;
+        __Pyx_PyErr_Clear();
+        Py_INCREF(defval);
+        return defval;
+    }
+    if (defval) {
+        Py_INCREF(defval);
+        return defval;
+    }
+    __Pyx_PyErr_SetNone(PyExc_StopIteration);
+    return NULL;
+}
+static void __Pyx_PyIter_Next_ErrorNoIterator(PyObject *iterator) {
+    PyErr_Format(PyExc_TypeError,
+        "%.200s object is not an iterator", Py_TYPE(iterator)->tp_name);
+}
+static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) {
+    PyObject* next;
+    iternextfunc iternext = Py_TYPE(iterator)->tp_iternext;
+    if (likely(iternext)) {
+#if CYTHON_USE_TYPE_SLOTS
+        next = iternext(iterator);
+        if (likely(next))
+            return next;
+        #if PY_VERSION_HEX >= 0x02070000
+        if (unlikely(iternext == &_PyObject_NextNotImplemented))
+            return NULL;
+        #endif
+#else
+        next = PyIter_Next(iterator);
+        if (likely(next))
+            return next;
+#endif
+    } else if (CYTHON_USE_TYPE_SLOTS || unlikely(!PyIter_Check(iterator))) {
+        __Pyx_PyIter_Next_ErrorNoIterator(iterator);
+        return NULL;
+    }
+#if !CYTHON_USE_TYPE_SLOTS
+    else {
+        next = PyIter_Next(iterator);
+        if (likely(next))
+            return next;
+    }
+#endif
+    return __Pyx_PyIter_Next2Default(defval);
+}
+
+/* decode_c_bytes */
+static CYTHON_INLINE PyObject* __Pyx_decode_c_bytes(
+         const char* cstring, Py_ssize_t length, Py_ssize_t start, Py_ssize_t stop,
+         const char* encoding, const char* errors,
+         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
+    if (unlikely((start < 0) | (stop < 0))) {
+        if (start < 0) {
+            start += length;
+            if (start < 0)
+                start = 0;
+        }
+        if (stop < 0)
+            stop += length;
+    }
+    if (stop > length)
+        stop = length;
+    length = stop - start;
+    if (unlikely(length <= 0))
+        return PyUnicode_FromUnicode(NULL, 0);
+    cstring += start;
+    if (decode_func) {
+        return decode_func(cstring, length, errors);
+    } else {
+        return PyUnicode_Decode(cstring, length, encoding, errors);
+    }
+}
+
+/* IterFinish */
+static CYTHON_INLINE int __Pyx_IterFinish(void) {
+#if CYTHON_FAST_THREAD_STATE
+    PyThreadState *tstate = __Pyx_PyThreadState_Current;
+    PyObject* exc_type = tstate->curexc_type;
+    if (unlikely(exc_type)) {
+        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
+            PyObject *exc_value, *exc_tb;
+            exc_value = tstate->curexc_value;
+            exc_tb = tstate->curexc_traceback;
+            tstate->curexc_type = 0;
+            tstate->curexc_value = 0;
+            tstate->curexc_traceback = 0;
+            Py_DECREF(exc_type);
+            Py_XDECREF(exc_value);
+            Py_XDECREF(exc_tb);
+            return 0;
+        } else {
+            return -1;
+        }
+    }
+    return 0;
+#else
+    if (unlikely(PyErr_Occurred())) {
+        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
+            PyErr_Clear();
+            return 0;
+        } else {
+            return -1;
+        }
+    }
+    return 0;
+#endif
+}
+
+/* PyObjectGetMethod */
+static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
+    PyObject *attr;
+#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
+    PyTypeObject *tp = Py_TYPE(obj);
+    PyObject *descr;
+    descrgetfunc f = NULL;
+    PyObject **dictptr, *dict;
+    int meth_found = 0;
+    assert (*method == NULL);
+    if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
+        attr = __Pyx_PyObject_GetAttrStr(obj, name);
+        goto try_unpack;
+    }
+    if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
+        return 0;
+    }
+    descr = _PyType_Lookup(tp, name);
+    if (likely(descr != NULL)) {
+        Py_INCREF(descr);
+#if PY_MAJOR_VERSION >= 3
+        #ifdef __Pyx_CyFunction_USED
+        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
+        #else
+        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type)))
+        #endif
+#else
+        #ifdef __Pyx_CyFunction_USED
+        if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
+        #else
+        if (likely(PyFunction_Check(descr)))
+        #endif
+#endif
+        {
+            meth_found = 1;
+        } else {
+            f = Py_TYPE(descr)->tp_descr_get;
+            if (f != NULL && PyDescr_IsData(descr)) {
+                attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
+                Py_DECREF(descr);
+                goto try_unpack;
+            }
+        }
+    }
+    dictptr = _PyObject_GetDictPtr(obj);
+    if (dictptr != NULL && (dict = *dictptr) != NULL) {
+        Py_INCREF(dict);
+        attr = __Pyx_PyDict_GetItemStr(dict, name);
+        if (attr != NULL) {
+            Py_INCREF(attr);
+            Py_DECREF(dict);
+            Py_XDECREF(descr);
+            goto try_unpack;
+        }
+        Py_DECREF(dict);
+    }
+    if (meth_found) {
+        *method = descr;
+        return 1;
+    }
+    if (f != NULL) {
+        attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
+        Py_DECREF(descr);
+        goto try_unpack;
+    }
+    if (descr != NULL) {
+        *method = descr;
+        return 0;
+    }
+    PyErr_Format(PyExc_AttributeError,
+#if PY_MAJOR_VERSION >= 3
+                 "'%.50s' object has no attribute '%U'",
+                 tp->tp_name, name);
+#else
+                 "'%.50s' object has no attribute '%.400s'",
+                 tp->tp_name, PyString_AS_STRING(name));
+#endif
+    return 0;
+#else
+    attr = __Pyx_PyObject_GetAttrStr(obj, name);
+    goto try_unpack;
+#endif
+try_unpack:
+#if CYTHON_UNPACK_METHODS
+    if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
+        PyObject *function = PyMethod_GET_FUNCTION(attr);
+        Py_INCREF(function);
+        Py_DECREF(attr);
+        *method = function;
+        return 1;
+    }
+#endif
+    *method = attr;
+    return 0;
+}
+
+/* PyObjectCallMethod0 */
+static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
+    PyObject *method = NULL, *result = NULL;
+    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
+    if (likely(is_method)) {
+        result = __Pyx_PyObject_CallOneArg(method, obj);
+        Py_DECREF(method);
+        return result;
+    }
+    if (unlikely(!method)) goto bad;
+    result = __Pyx_PyObject_CallNoArg(method);
+    Py_DECREF(method);
+bad:
+    return result;
+}
+
+/* RaiseNeedMoreValuesToUnpack */
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
+    PyErr_Format(PyExc_ValueError,
+                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
+                 index, (index == 1) ? "" : "s");
+}
+
+/* RaiseTooManyValuesToUnpack */
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
+    PyErr_Format(PyExc_ValueError,
+                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
+}
+
+/* UnpackItemEndCheck */
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
+    if (unlikely(retval)) {
+        Py_DECREF(retval);
+        __Pyx_RaiseTooManyValuesError(expected);
+        return -1;
+    } else {
+        return __Pyx_IterFinish();
+    }
+    return 0;
+}
+
+/* RaiseNoneIterError */
+static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
+    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
+}
+
+/* UnpackTupleError */
+static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
+    if (t == Py_None) {
+      __Pyx_RaiseNoneNotIterableError();
+    } else if (PyTuple_GET_SIZE(t) < index) {
+      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
+    } else {
+      __Pyx_RaiseTooManyValuesError(index);
+    }
+}
+
+/* UnpackTuple2 */
+static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
+        PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
+    PyObject *value1 = NULL, *value2 = NULL;
+#if CYTHON_COMPILING_IN_PYPY
+    value1 = PySequence_ITEM(tuple, 0);  if (unlikely(!value1)) goto bad;
+    value2 = PySequence_ITEM(tuple, 1);  if (unlikely(!value2)) goto bad;
+#else
+    value1 = PyTuple_GET_ITEM(tuple, 0);  Py_INCREF(value1);
+    value2 = PyTuple_GET_ITEM(tuple, 1);  Py_INCREF(value2);
+#endif
+    if (decref_tuple) {
+        Py_DECREF(tuple);
+    }
+    *pvalue1 = value1;
+    *pvalue2 = value2;
+    return 0;
+#if CYTHON_COMPILING_IN_PYPY
+bad:
+    Py_XDECREF(value1);
+    Py_XDECREF(value2);
+    if (decref_tuple) { Py_XDECREF(tuple); }
+    return -1;
+#endif
+}
+static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
+                                       int has_known_size, int decref_tuple) {
+    Py_ssize_t index;
+    PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
+    iternextfunc iternext;
+    iter = PyObject_GetIter(tuple);
+    if (unlikely(!iter)) goto bad;
+    if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
+    iternext = Py_TYPE(iter)->tp_iternext;
+    value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
+    value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
+    if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
+    Py_DECREF(iter);
+    *pvalue1 = value1;
+    *pvalue2 = value2;
+    return 0;
+unpacking_failed:
+    if (!has_known_size && __Pyx_IterFinish() == 0)
+        __Pyx_RaiseNeedMoreValuesError(index);
+bad:
+    Py_XDECREF(iter);
+    Py_XDECREF(value1);
+    Py_XDECREF(value2);
+    if (decref_tuple) { Py_XDECREF(tuple); }
+    return -1;
+}
+
+/* dict_iter */
+static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
+                                                   Py_ssize_t* p_orig_length, int* p_source_is_dict) {
+    is_dict = is_dict || likely(PyDict_CheckExact(iterable));
+    *p_source_is_dict = is_dict;
+    if (is_dict) {
+#if !CYTHON_COMPILING_IN_PYPY
+        *p_orig_length = PyDict_Size(iterable);
+        Py_INCREF(iterable);
+        return iterable;
+#elif PY_MAJOR_VERSION >= 3
+        static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL;
+        PyObject **pp = NULL;
+        if (method_name) {
+            const char *name = PyUnicode_AsUTF8(method_name);
+            if (strcmp(name, "iteritems") == 0) pp = &py_items;
+            else if (strcmp(name, "iterkeys") == 0) pp = &py_keys;
+            else if (strcmp(name, "itervalues") == 0) pp = &py_values;
+            if (pp) {
+                if (!*pp) {
+                    *pp = PyUnicode_FromString(name + 4);
+                    if (!*pp)
+                        return NULL;
+                }
+                method_name = *pp;
+            }
+        }
+#endif
+    }
+    *p_orig_length = 0;
+    if (method_name) {
+        PyObject* iter;
+        iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
+        if (!iterable)
+            return NULL;
+#if !CYTHON_COMPILING_IN_PYPY
+        if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
+            return iterable;
+#endif
+        iter = PyObject_GetIter(iterable);
+        Py_DECREF(iterable);
+        return iter;
+    }
+    return PyObject_GetIter(iterable);
+}
+static CYTHON_INLINE int __Pyx_dict_iter_next(
+        PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
+        PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
+    PyObject* next_item;
+#if !CYTHON_COMPILING_IN_PYPY
+    if (source_is_dict) {
+        PyObject *key, *value;
+        if (unlikely(orig_length != PyDict_Size(iter_obj))) {
+            PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
+            return -1;
+        }
+        if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
+            return 0;
+        }
+        if (pitem) {
+            PyObject* tuple = PyTuple_New(2);
+            if (unlikely(!tuple)) {
+                return -1;
+            }
+            Py_INCREF(key);
+            Py_INCREF(value);
+            PyTuple_SET_ITEM(tuple, 0, key);
+            PyTuple_SET_ITEM(tuple, 1, value);
+            *pitem = tuple;
+        } else {
+            if (pkey) {
+                Py_INCREF(key);
+                *pkey = key;
+            }
+            if (pvalue) {
+                Py_INCREF(value);
+                *pvalue = value;
+            }
+        }
+        return 1;
+    } else if (PyTuple_CheckExact(iter_obj)) {
+        Py_ssize_t pos = *ppos;
+        if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
+        *ppos = pos + 1;
+        next_item = PyTuple_GET_ITEM(iter_obj, pos);
+        Py_INCREF(next_item);
+    } else if (PyList_CheckExact(iter_obj)) {
+        Py_ssize_t pos = *ppos;
+        if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
+        *ppos = pos + 1;
+        next_item = PyList_GET_ITEM(iter_obj, pos);
+        Py_INCREF(next_item);
+    } else
+#endif
+    {
+        next_item = PyIter_Next(iter_obj);
+        if (unlikely(!next_item)) {
+            return __Pyx_IterFinish();
+        }
+    }
+    if (pitem) {
+        *pitem = next_item;
+    } else if (pkey && pvalue) {
+        if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
+            return -1;
+    } else if (pkey) {
+        *pkey = next_item;
+    } else {
+        *pvalue = next_item;
+    }
+    return 1;
+}
+
+/* FastTypeChecks */
+#if CYTHON_COMPILING_IN_CPYTHON
+static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
+    while (a) {
+        a = a->tp_base;
+        if (a == b)
+            return 1;
+    }
+    return b == &PyBaseObject_Type;
+}
+static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
+    PyObject *mro;
+    if (a == b) return 1;
+    mro = a->tp_mro;
+    if (likely(mro)) {
+        Py_ssize_t i, n;
+        n = PyTuple_GET_SIZE(mro);
+        for (i = 0; i < n; i++) {
+            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
+                return 1;
+        }
+        return 0;
+    }
+    return __Pyx_InBases(a, b);
+}
+#if PY_MAJOR_VERSION == 2
+static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
+    PyObject *exception, *value, *tb;
+    int res;
+    __Pyx_PyThreadState_declare
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrFetch(&exception, &value, &tb);
+    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
+    if (unlikely(res == -1)) {
+        PyErr_WriteUnraisable(err);
+        res = 0;
+    }
+    if (!res) {
+        res = PyObject_IsSubclass(err, exc_type2);
+        if (unlikely(res == -1)) {
+            PyErr_WriteUnraisable(err);
+            res = 0;
+        }
+    }
+    __Pyx_ErrRestore(exception, value, tb);
+    return res;
+}
+#else
+static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
+    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
+    if (!res) {
+        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
+    }
+    return res;
+}
+#endif
+static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
+    Py_ssize_t i, n;
+    assert(PyExceptionClass_Check(exc_type));
+    n = PyTuple_GET_SIZE(tuple);
+#if PY_MAJOR_VERSION >= 3
+    for (i=0; i<n; i++) {
+        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
+    }
+#endif
+    for (i=0; i<n; i++) {
+        PyObject *t = PyTuple_GET_ITEM(tuple, i);
+        #if PY_MAJOR_VERSION < 3
+        if (likely(exc_type == t)) return 1;
+        #endif
+        if (likely(PyExceptionClass_Check(t))) {
+            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
+        } else {
+        }
+    }
+    return 0;
+}
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
+    if (likely(err == exc_type)) return 1;
+    if (likely(PyExceptionClass_Check(err))) {
+        if (likely(PyExceptionClass_Check(exc_type))) {
+            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
+        } else if (likely(PyTuple_Check(exc_type))) {
+            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
+        } else {
+        }
+    }
+    return PyErr_GivenExceptionMatches(err, exc_type);
+}
+static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
+    assert(PyExceptionClass_Check(exc_type1));
+    assert(PyExceptionClass_Check(exc_type2));
+    if (likely(err == exc_type1 || err == exc_type2)) return 1;
+    if (likely(PyExceptionClass_Check(err))) {
+        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
+    }
+    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
+}
+#endif
+
+/* FetchCommonType */
+static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
+    PyObject* fake_module;
+    PyTypeObject* cached_type = NULL;
+    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
+    if (!fake_module) return NULL;
+    Py_INCREF(fake_module);
+    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
+    if (cached_type) {
+        if (!PyType_Check((PyObject*)cached_type)) {
+            PyErr_Format(PyExc_TypeError,
+                "Shared Cython type %.200s is not a type object",
+                type->tp_name);
+            goto bad;
+        }
+        if (cached_type->tp_basicsize != type->tp_basicsize) {
+            PyErr_Format(PyExc_TypeError,
+                "Shared Cython type %.200s has the wrong size, try recompiling",
+                type->tp_name);
+            goto bad;
+        }
+    } else {
+        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
+        PyErr_Clear();
+        if (PyType_Ready(type) < 0) goto bad;
+        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
+            goto bad;
+        Py_INCREF(type);
+        cached_type = type;
+    }
+done:
+    Py_DECREF(fake_module);
+    return cached_type;
+bad:
+    Py_XDECREF(cached_type);
+    cached_type = NULL;
+    goto done;
+}
+
+/* PyObjectCallMethod1 */
+static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
+    PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
+    Py_DECREF(method);
+    return result;
+}
+static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
+    PyObject *method = NULL, *result;
+    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
+    if (likely(is_method)) {
+        result = __Pyx_PyObject_Call2Args(method, obj, arg);
+        Py_DECREF(method);
+        return result;
+    }
+    if (unlikely(!method)) return NULL;
+    return __Pyx__PyObject_CallMethod1(method, arg);
+}
+
+/* CoroutineBase */
+#include <structmember.h>
+#include <frameobject.h>
+#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
+static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject **pvalue) {
+    PyObject *et, *ev, *tb;
+    PyObject *value = NULL;
+    __Pyx_ErrFetch(&et, &ev, &tb);
+    if (!et) {
+        Py_XDECREF(tb);
+        Py_XDECREF(ev);
+        Py_INCREF(Py_None);
+        *pvalue = Py_None;
+        return 0;
+    }
+    if (likely(et == PyExc_StopIteration)) {
+        if (!ev) {
+            Py_INCREF(Py_None);
+            value = Py_None;
+        }
+#if PY_VERSION_HEX >= 0x030300A0
+        else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
+            value = ((PyStopIterationObject *)ev)->value;
+            Py_INCREF(value);
+            Py_DECREF(ev);
+        }
+#endif
+        else if (unlikely(PyTuple_Check(ev))) {
+            if (PyTuple_GET_SIZE(ev) >= 1) {
+#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+                value = PyTuple_GET_ITEM(ev, 0);
+                Py_INCREF(value);
+#else
+                value = PySequence_ITEM(ev, 0);
+#endif
+            } else {
+                Py_INCREF(Py_None);
+                value = Py_None;
+            }
+            Py_DECREF(ev);
+        }
+        else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
+            value = ev;
+        }
+        if (likely(value)) {
+            Py_XDECREF(tb);
+            Py_DECREF(et);
+            *pvalue = value;
+            return 0;
+        }
+    } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
+        __Pyx_ErrRestore(et, ev, tb);
+        return -1;
+    }
+    PyErr_NormalizeException(&et, &ev, &tb);
+    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
+        __Pyx_ErrRestore(et, ev, tb);
+        return -1;
+    }
+    Py_XDECREF(tb);
+    Py_DECREF(et);
+#if PY_VERSION_HEX >= 0x030300A0
+    value = ((PyStopIterationObject *)ev)->value;
+    Py_INCREF(value);
+    Py_DECREF(ev);
+#else
+    {
+        PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
+        Py_DECREF(ev);
+        if (likely(args)) {
+            value = PySequence_GetItem(args, 0);
+            Py_DECREF(args);
+        }
+        if (unlikely(!value)) {
+            __Pyx_ErrRestore(NULL, NULL, NULL);
+            Py_INCREF(Py_None);
+            value = Py_None;
+        }
+    }
+#endif
+    *pvalue = value;
+    return 0;
+}
+static CYTHON_INLINE
+void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) {
+    PyObject *t, *v, *tb;
+    t = exc_state->exc_type;
+    v = exc_state->exc_value;
+    tb = exc_state->exc_traceback;
+    exc_state->exc_type = NULL;
+    exc_state->exc_value = NULL;
+    exc_state->exc_traceback = NULL;
+    Py_XDECREF(t);
+    Py_XDECREF(v);
+    Py_XDECREF(tb);
+}
+#define __Pyx_Coroutine_AlreadyRunningError(gen)  (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL)
+static void __Pyx__Coroutine_AlreadyRunningError(CYTHON_UNUSED __pyx_CoroutineObject *gen) {
+    const char *msg;
+    if (0) {
+    #ifdef __Pyx_Coroutine_USED
+    } else if (__Pyx_Coroutine_Check((PyObject*)gen)) {
+        msg = "coroutine already executing";
+    #endif
+    #ifdef __Pyx_AsyncGen_USED
+    } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) {
+        msg = "async generator already executing";
+    #endif
+    } else {
+        msg = "generator already executing";
+    }
+    PyErr_SetString(PyExc_ValueError, msg);
+}
+#define __Pyx_Coroutine_NotStartedError(gen)  (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL)
+static void __Pyx__Coroutine_NotStartedError(CYTHON_UNUSED PyObject *gen) {
+    const char *msg;
+    if (0) {
+    #ifdef __Pyx_Coroutine_USED
+    } else if (__Pyx_Coroutine_Check(gen)) {
+        msg = "can't send non-None value to a just-started coroutine";
+    #endif
+    #ifdef __Pyx_AsyncGen_USED
+    } else if (__Pyx_AsyncGen_CheckExact(gen)) {
+        msg = "can't send non-None value to a just-started async generator";
+    #endif
+    } else {
+        msg = "can't send non-None value to a just-started generator";
+    }
+    PyErr_SetString(PyExc_TypeError, msg);
+}
+#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing)  (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL)
+static void __Pyx__Coroutine_AlreadyTerminatedError(CYTHON_UNUSED PyObject *gen, PyObject *value, CYTHON_UNUSED int closing) {
+    #ifdef __Pyx_Coroutine_USED
+    if (!closing && __Pyx_Coroutine_Check(gen)) {
+        PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine");
+    } else
+    #endif
+    if (value) {
+        #ifdef __Pyx_AsyncGen_USED
+        if (__Pyx_AsyncGen_CheckExact(gen))
+            PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration);
+        else
+        #endif
+        PyErr_SetNone(PyExc_StopIteration);
+    }
+}
+static
+PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) {
+    __Pyx_PyThreadState_declare
+    PyThreadState *tstate;
+    __Pyx_ExcInfoStruct *exc_state;
+    PyObject *retval;
+    assert(!self->is_running);
+    if (unlikely(self->resume_label == 0)) {
+        if (unlikely(value && value != Py_None)) {
+            return __Pyx_Coroutine_NotStartedError((PyObject*)self);
+        }
+    }
+    if (unlikely(self->resume_label == -1)) {
+        return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing);
+    }
+#if CYTHON_FAST_THREAD_STATE
+    __Pyx_PyThreadState_assign
+    tstate = __pyx_tstate;
+#else
+    tstate = __Pyx_PyThreadState_Current;
+#endif
+    exc_state = &self->gi_exc_state;
+    if (exc_state->exc_type) {
+        #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
+        #else
+        if (exc_state->exc_traceback) {
+            PyTracebackObject *tb = (PyTracebackObject *) exc_state->exc_traceback;
+            PyFrameObject *f = tb->tb_frame;
+            Py_XINCREF(tstate->frame);
+            assert(f->f_back == NULL);
+            f->f_back = tstate->frame;
+        }
+        #endif
+    }
+#if CYTHON_USE_EXC_INFO_STACK
+    exc_state->previous_item = tstate->exc_info;
+    tstate->exc_info = exc_state;
+#else
+    if (exc_state->exc_type) {
+        __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
+    } else {
+        __Pyx_Coroutine_ExceptionClear(exc_state);
+        __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
+    }
+#endif
+    self->is_running = 1;
+    retval = self->body((PyObject *) self, tstate, value);
+    self->is_running = 0;
+#if CYTHON_USE_EXC_INFO_STACK
+    exc_state = &self->gi_exc_state;
+    tstate->exc_info = exc_state->previous_item;
+    exc_state->previous_item = NULL;
+    __Pyx_Coroutine_ResetFrameBackpointer(exc_state);
+#endif
+    return retval;
+}
+static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) {
+    PyObject *exc_tb = exc_state->exc_traceback;
+    if (likely(exc_tb)) {
+#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
+#else
+        PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
+        PyFrameObject *f = tb->tb_frame;
+        Py_CLEAR(f->f_back);
+#endif
+    }
+}
+static CYTHON_INLINE
+PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) {
+    if (unlikely(!retval)) {
+        __Pyx_PyThreadState_declare
+        __Pyx_PyThreadState_assign
+        if (!__Pyx_PyErr_Occurred()) {
+            PyObject *exc = PyExc_StopIteration;
+            #ifdef __Pyx_AsyncGen_USED
+            if (__Pyx_AsyncGen_CheckExact(gen))
+                exc = __Pyx_PyExc_StopAsyncIteration;
+            #endif
+            __Pyx_PyErr_SetNone(exc);
+        }
+    }
+    return retval;
+}
+static CYTHON_INLINE
+PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
+    PyObject *ret;
+    PyObject *val = NULL;
+    __Pyx_Coroutine_Undelegate(gen);
+    __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val);
+    ret = __Pyx_Coroutine_SendEx(gen, val, 0);
+    Py_XDECREF(val);
+    return ret;
+}
+static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
+    PyObject *retval;
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
+    PyObject *yf = gen->yieldfrom;
+    if (unlikely(gen->is_running))
+        return __Pyx_Coroutine_AlreadyRunningError(gen);
+    if (yf) {
+        PyObject *ret;
+        gen->is_running = 1;
+        #ifdef __Pyx_Generator_USED
+        if (__Pyx_Generator_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Send(yf, value);
+        } else
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+        if (__Pyx_Coroutine_Check(yf)) {
+            ret = __Pyx_Coroutine_Send(yf, value);
+        } else
+        #endif
+        #ifdef __Pyx_AsyncGen_USED
+        if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
+            ret = __Pyx_async_gen_asend_send(yf, value);
+        } else
+        #endif
+        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
+        if (PyGen_CheckExact(yf)) {
+            ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
+        } else
+        #endif
+        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
+        if (PyCoro_CheckExact(yf)) {
+            ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
+        } else
+        #endif
+        {
+            if (value == Py_None)
+                ret = Py_TYPE(yf)->tp_iternext(yf);
+            else
+                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
+        }
+        gen->is_running = 0;
+        if (likely(ret)) {
+            return ret;
+        }
+        retval = __Pyx_Coroutine_FinishDelegation(gen);
+    } else {
+        retval = __Pyx_Coroutine_SendEx(gen, value, 0);
+    }
+    return __Pyx_Coroutine_MethodReturn(self, retval);
+}
+static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
+    PyObject *retval = NULL;
+    int err = 0;
+    #ifdef __Pyx_Generator_USED
+    if (__Pyx_Generator_CheckExact(yf)) {
+        retval = __Pyx_Coroutine_Close(yf);
+        if (!retval)
+            return -1;
+    } else
+    #endif
+    #ifdef __Pyx_Coroutine_USED
+    if (__Pyx_Coroutine_Check(yf)) {
+        retval = __Pyx_Coroutine_Close(yf);
+        if (!retval)
+            return -1;
+    } else
+    if (__Pyx_CoroutineAwait_CheckExact(yf)) {
+        retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf, NULL);
+        if (!retval)
+            return -1;
+    } else
+    #endif
+    #ifdef __Pyx_AsyncGen_USED
+    if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
+        retval = __Pyx_async_gen_asend_close(yf, NULL);
+    } else
+    if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) {
+        retval = __Pyx_async_gen_athrow_close(yf, NULL);
+    } else
+    #endif
+    {
+        PyObject *meth;
+        gen->is_running = 1;
+        meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close);
+        if (unlikely(!meth)) {
+            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+                PyErr_WriteUnraisable(yf);
+            }
+            PyErr_Clear();
+        } else {
+            retval = PyObject_CallFunction(meth, NULL);
+            Py_DECREF(meth);
+            if (!retval)
+                err = -1;
+        }
+        gen->is_running = 0;
+    }
+    Py_XDECREF(retval);
+    return err;
+}
+static PyObject *__Pyx_Generator_Next(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
+    PyObject *yf = gen->yieldfrom;
+    if (unlikely(gen->is_running))
+        return __Pyx_Coroutine_AlreadyRunningError(gen);
+    if (yf) {
+        PyObject *ret;
+        gen->is_running = 1;
+        #ifdef __Pyx_Generator_USED
+        if (__Pyx_Generator_CheckExact(yf)) {
+            ret = __Pyx_Generator_Next(yf);
+        } else
+        #endif
+        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
+        if (PyGen_CheckExact(yf)) {
+            ret = _PyGen_Send((PyGenObject*)yf, NULL);
+        } else
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+        if (__Pyx_Coroutine_Check(yf)) {
+            ret = __Pyx_Coroutine_Send(yf, Py_None);
+        } else
+        #endif
+            ret = Py_TYPE(yf)->tp_iternext(yf);
+        gen->is_running = 0;
+        if (likely(ret)) {
+            return ret;
+        }
+        return __Pyx_Coroutine_FinishDelegation(gen);
+    }
+    return __Pyx_Coroutine_SendEx(gen, Py_None, 0);
+}
+static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, CYTHON_UNUSED PyObject *arg) {
+    return __Pyx_Coroutine_Close(self);
+}
+static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    PyObject *retval, *raised_exception;
+    PyObject *yf = gen->yieldfrom;
+    int err = 0;
+    if (unlikely(gen->is_running))
+        return __Pyx_Coroutine_AlreadyRunningError(gen);
+    if (yf) {
+        Py_INCREF(yf);
+        err = __Pyx_Coroutine_CloseIter(gen, yf);
+        __Pyx_Coroutine_Undelegate(gen);
+        Py_DECREF(yf);
+    }
+    if (err == 0)
+        PyErr_SetNone(PyExc_GeneratorExit);
+    retval = __Pyx_Coroutine_SendEx(gen, NULL, 1);
+    if (unlikely(retval)) {
+        const char *msg;
+        Py_DECREF(retval);
+        if ((0)) {
+        #ifdef __Pyx_Coroutine_USED
+        } else if (__Pyx_Coroutine_Check(self)) {
+            msg = "coroutine ignored GeneratorExit";
+        #endif
+        #ifdef __Pyx_AsyncGen_USED
+        } else if (__Pyx_AsyncGen_CheckExact(self)) {
+#if PY_VERSION_HEX < 0x03060000
+            msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)";
+#else
+            msg = "async generator ignored GeneratorExit";
+#endif
+        #endif
+        } else {
+            msg = "generator ignored GeneratorExit";
+        }
+        PyErr_SetString(PyExc_RuntimeError, msg);
+        return NULL;
+    }
+    raised_exception = PyErr_Occurred();
+    if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) {
+        if (raised_exception) PyErr_Clear();
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+    return NULL;
+}
+static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb,
+                                        PyObject *args, int close_on_genexit) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    PyObject *yf = gen->yieldfrom;
+    if (unlikely(gen->is_running))
+        return __Pyx_Coroutine_AlreadyRunningError(gen);
+    if (yf) {
+        PyObject *ret;
+        Py_INCREF(yf);
+        if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) {
+            int err = __Pyx_Coroutine_CloseIter(gen, yf);
+            Py_DECREF(yf);
+            __Pyx_Coroutine_Undelegate(gen);
+            if (err < 0)
+                return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0));
+            goto throw_here;
+        }
+        gen->is_running = 1;
+        if (0
+        #ifdef __Pyx_Generator_USED
+            || __Pyx_Generator_CheckExact(yf)
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+            || __Pyx_Coroutine_Check(yf)
+        #endif
+            ) {
+            ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit);
+        #ifdef __Pyx_Coroutine_USED
+        } else if (__Pyx_CoroutineAwait_CheckExact(yf)) {
+            ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit);
+        #endif
+        } else {
+            PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw);
+            if (unlikely(!meth)) {
+                Py_DECREF(yf);
+                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+                    gen->is_running = 0;
+                    return NULL;
+                }
+                PyErr_Clear();
+                __Pyx_Coroutine_Undelegate(gen);
+                gen->is_running = 0;
+                goto throw_here;
+            }
+            if (likely(args)) {
+                ret = PyObject_CallObject(meth, args);
+            } else {
+                ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL);
+            }
+            Py_DECREF(meth);
+        }
+        gen->is_running = 0;
+        Py_DECREF(yf);
+        if (!ret) {
+            ret = __Pyx_Coroutine_FinishDelegation(gen);
+        }
+        return __Pyx_Coroutine_MethodReturn(self, ret);
+    }
+throw_here:
+    __Pyx_Raise(typ, val, tb, NULL);
+    return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0));
+}
+static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
+    PyObject *typ;
+    PyObject *val = NULL;
+    PyObject *tb = NULL;
+    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
+        return NULL;
+    return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1);
+}
+static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) {
+    Py_VISIT(exc_state->exc_type);
+    Py_VISIT(exc_state->exc_value);
+    Py_VISIT(exc_state->exc_traceback);
+    return 0;
+}
+static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) {
+    Py_VISIT(gen->closure);
+    Py_VISIT(gen->classobj);
+    Py_VISIT(gen->yieldfrom);
+    return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg);
+}
+static int __Pyx_Coroutine_clear(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    Py_CLEAR(gen->closure);
+    Py_CLEAR(gen->classobj);
+    Py_CLEAR(gen->yieldfrom);
+    __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state);
+#ifdef __Pyx_AsyncGen_USED
+    if (__Pyx_AsyncGen_CheckExact(self)) {
+        Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer);
+    }
+#endif
+    Py_CLEAR(gen->gi_code);
+    Py_CLEAR(gen->gi_name);
+    Py_CLEAR(gen->gi_qualname);
+    Py_CLEAR(gen->gi_modulename);
+    return 0;
+}
+static void __Pyx_Coroutine_dealloc(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    PyObject_GC_UnTrack(gen);
+    if (gen->gi_weakreflist != NULL)
+        PyObject_ClearWeakRefs(self);
+    if (gen->resume_label >= 0) {
+        PyObject_GC_Track(self);
+#if PY_VERSION_HEX >= 0x030400a1 && CYTHON_USE_TP_FINALIZE
+        if (PyObject_CallFinalizerFromDealloc(self))
+#else
+        Py_TYPE(gen)->tp_del(self);
+        if (self->ob_refcnt > 0)
+#endif
+        {
+            return;
+        }
+        PyObject_GC_UnTrack(self);
+    }
+#ifdef __Pyx_AsyncGen_USED
+    if (__Pyx_AsyncGen_CheckExact(self)) {
+        /* We have to handle this case for asynchronous generators
+           right here, because this code has to be between UNTRACK
+           and GC_Del. */
+        Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer);
+    }
+#endif
+    __Pyx_Coroutine_clear(self);
+    PyObject_GC_Del(gen);
+}
+static void __Pyx_Coroutine_del(PyObject *self) {
+    PyObject *error_type, *error_value, *error_traceback;
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    __Pyx_PyThreadState_declare
+    if (gen->resume_label < 0) {
+        return;
+    }
+#if !CYTHON_USE_TP_FINALIZE
+    assert(self->ob_refcnt == 0);
+    self->ob_refcnt = 1;
+#endif
+    __Pyx_PyThreadState_assign
+    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
+#ifdef __Pyx_AsyncGen_USED
+    if (__Pyx_AsyncGen_CheckExact(self)) {
+        __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self;
+        PyObject *finalizer = agen->ag_finalizer;
+        if (finalizer && !agen->ag_closed) {
+            PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self);
+            if (unlikely(!res)) {
+                PyErr_WriteUnraisable(self);
+            } else {
+                Py_DECREF(res);
+            }
+            __Pyx_ErrRestore(error_type, error_value, error_traceback);
+            return;
+        }
+    }
+#endif
+    if (unlikely(gen->resume_label == 0 && !error_value)) {
+#ifdef __Pyx_Coroutine_USED
+#ifdef __Pyx_Generator_USED
+    if (!__Pyx_Generator_CheckExact(self))
+#endif
+        {
+        PyObject_GC_UnTrack(self);
+#if PY_MAJOR_VERSION >= 3  || defined(PyErr_WarnFormat)
+        if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0))
+            PyErr_WriteUnraisable(self);
+#else
+        {PyObject *msg;
+        char *cmsg;
+        #if CYTHON_COMPILING_IN_PYPY
+        msg = NULL;
+        cmsg = (char*) "coroutine was never awaited";
+        #else
+        char *cname;
+        PyObject *qualname;
+        qualname = gen->gi_qualname;
+        cname = PyString_AS_STRING(qualname);
+        msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname);
+        if (unlikely(!msg)) {
+            PyErr_Clear();
+            cmsg = (char*) "coroutine was never awaited";
+        } else {
+            cmsg = PyString_AS_STRING(msg);
+        }
+        #endif
+        if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0))
+            PyErr_WriteUnraisable(self);
+        Py_XDECREF(msg);}
+#endif
+        PyObject_GC_Track(self);
+        }
+#endif
+    } else {
+        PyObject *res = __Pyx_Coroutine_Close(self);
+        if (unlikely(!res)) {
+            if (PyErr_Occurred())
+                PyErr_WriteUnraisable(self);
+        } else {
+            Py_DECREF(res);
+        }
+    }
+    __Pyx_ErrRestore(error_type, error_value, error_traceback);
+#if !CYTHON_USE_TP_FINALIZE
+    assert(self->ob_refcnt > 0);
+    if (--self->ob_refcnt == 0) {
+        return;
+    }
+    {
+        Py_ssize_t refcnt = self->ob_refcnt;
+        _Py_NewReference(self);
+        self->ob_refcnt = refcnt;
+    }
+#if CYTHON_COMPILING_IN_CPYTHON
+    assert(PyType_IS_GC(self->ob_type) &&
+           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
+    _Py_DEC_REFTOTAL;
+#endif
+#ifdef COUNT_ALLOCS
+    --Py_TYPE(self)->tp_frees;
+    --Py_TYPE(self)->tp_allocs;
+#endif
+#endif
+}
+static PyObject *
+__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
+{
+    PyObject *name = self->gi_name;
+    if (unlikely(!name)) name = Py_None;
+    Py_INCREF(name);
+    return name;
+}
+static int
+__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, CYTHON_UNUSED void *context)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value)))
+#else
+    if (unlikely(value == NULL || !PyString_Check(value)))
+#endif
+    {
+        PyErr_SetString(PyExc_TypeError,
+                        "__name__ must be set to a string object");
+        return -1;
+    }
+    tmp = self->gi_name;
+    Py_INCREF(value);
+    self->gi_name = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
+{
+    PyObject *name = self->gi_qualname;
+    if (unlikely(!name)) name = Py_None;
+    Py_INCREF(name);
+    return name;
+}
+static int
+__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, CYTHON_UNUSED void *context)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value)))
+#else
+    if (unlikely(value == NULL || !PyString_Check(value)))
+#endif
+    {
+        PyErr_SetString(PyExc_TypeError,
+                        "__qualname__ must be set to a string object");
+        return -1;
+    }
+    tmp = self->gi_qualname;
+    Py_INCREF(value);
+    self->gi_qualname = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static __pyx_CoroutineObject *__Pyx__Coroutine_New(
+            PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
+            PyObject *name, PyObject *qualname, PyObject *module_name) {
+    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
+    if (unlikely(!gen))
+        return NULL;
+    return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name);
+}
+static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
+            __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
+            PyObject *name, PyObject *qualname, PyObject *module_name) {
+    gen->body = body;
+    gen->closure = closure;
+    Py_XINCREF(closure);
+    gen->is_running = 0;
+    gen->resume_label = 0;
+    gen->classobj = NULL;
+    gen->yieldfrom = NULL;
+    gen->gi_exc_state.exc_type = NULL;
+    gen->gi_exc_state.exc_value = NULL;
+    gen->gi_exc_state.exc_traceback = NULL;
+#if CYTHON_USE_EXC_INFO_STACK
+    gen->gi_exc_state.previous_item = NULL;
+#endif
+    gen->gi_weakreflist = NULL;
+    Py_XINCREF(qualname);
+    gen->gi_qualname = qualname;
+    Py_XINCREF(name);
+    gen->gi_name = name;
+    Py_XINCREF(module_name);
+    gen->gi_modulename = module_name;
+    Py_XINCREF(code);
+    gen->gi_code = code;
+    PyObject_GC_Track(gen);
+    return gen;
+}
+
+/* PyObject_GenericGetAttrNoDict */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
+    PyErr_Format(PyExc_AttributeError,
+#if PY_MAJOR_VERSION >= 3
+                 "'%.50s' object has no attribute '%U'",
+                 tp->tp_name, attr_name);
+#else
+                 "'%.50s' object has no attribute '%.400s'",
+                 tp->tp_name, PyString_AS_STRING(attr_name));
+#endif
+    return NULL;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
+    PyObject *descr;
+    PyTypeObject *tp = Py_TYPE(obj);
+    if (unlikely(!PyString_Check(attr_name))) {
+        return PyObject_GenericGetAttr(obj, attr_name);
+    }
+    assert(!tp->tp_dictoffset);
+    descr = _PyType_Lookup(tp, attr_name);
+    if (unlikely(!descr)) {
+        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
+    }
+    Py_INCREF(descr);
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
+    #endif
+    {
+        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
+        if (unlikely(f)) {
+            PyObject *res = f(descr, obj, (PyObject *)tp);
+            Py_DECREF(descr);
+            return res;
+        }
+    }
+    return descr;
+}
+#endif
+
+/* PatchModuleWithCoroutine */
+static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+    int result;
+    PyObject *globals, *result_obj;
+    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
+    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
+    #ifdef __Pyx_Coroutine_USED
+        (PyObject*)__pyx_CoroutineType);
+    #else
+        Py_None);
+    #endif
+    if (unlikely(result < 0)) goto ignore;
+    result = PyDict_SetItemString(globals, "_cython_generator_type",
+    #ifdef __Pyx_Generator_USED
+        (PyObject*)__pyx_GeneratorType);
+    #else
+        Py_None);
+    #endif
+    if (unlikely(result < 0)) goto ignore;
+    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
+    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
+    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
+    if (unlikely(!result_obj)) goto ignore;
+    Py_DECREF(result_obj);
+    Py_DECREF(globals);
+    return module;
+ignore:
+    Py_XDECREF(globals);
+    PyErr_WriteUnraisable(module);
+    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
+        Py_DECREF(module);
+        module = NULL;
+    }
+#else
+    py_code++;
+#endif
+    return module;
+}
+
+/* PatchGeneratorABC */
+#ifndef CYTHON_REGISTER_ABCS
+#define CYTHON_REGISTER_ABCS 1
+#endif
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+static PyObject* __Pyx_patch_abc_module(PyObject *module);
+static PyObject* __Pyx_patch_abc_module(PyObject *module) {
+    module = __Pyx_Coroutine_patch_module(
+        module, ""
+"if _cython_generator_type is not None:\n"
+"    try: Generator = _module.Generator\n"
+"    except AttributeError: pass\n"
+"    else: Generator.register(_cython_generator_type)\n"
+"if _cython_coroutine_type is not None:\n"
+"    try: Coroutine = _module.Coroutine\n"
+"    except AttributeError: pass\n"
+"    else: Coroutine.register(_cython_coroutine_type)\n"
+    );
+    return module;
+}
+#endif
+static int __Pyx_patch_abc(void) {
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+    static int abc_patched = 0;
+    if (CYTHON_REGISTER_ABCS && !abc_patched) {
+        PyObject *module;
+        module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections");
+        if (!module) {
+            PyErr_WriteUnraisable(NULL);
+            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
+                    ((PY_MAJOR_VERSION >= 3) ?
+                        "Cython module failed to register with collections.abc module" :
+                        "Cython module failed to register with collections module"), 1) < 0)) {
+                return -1;
+            }
+        } else {
+            module = __Pyx_patch_abc_module(module);
+            abc_patched = 1;
+            if (unlikely(!module))
+                return -1;
+            Py_DECREF(module);
+        }
+        module = PyImport_ImportModule("backports_abc");
+        if (module) {
+            module = __Pyx_patch_abc_module(module);
+            Py_XDECREF(module);
+        }
+        if (!module) {
+            PyErr_Clear();
+        }
+    }
+#else
+    if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL);
+#endif
+    return 0;
+}
+
+/* Coroutine */
+static void __Pyx_CoroutineAwait_dealloc(PyObject *self) {
+    PyObject_GC_UnTrack(self);
+    Py_CLEAR(((__pyx_CoroutineAwaitObject*)self)->coroutine);
+    PyObject_GC_Del(self);
+}
+static int __Pyx_CoroutineAwait_traverse(__pyx_CoroutineAwaitObject *self, visitproc visit, void *arg) {
+    Py_VISIT(self->coroutine);
+    return 0;
+}
+static int __Pyx_CoroutineAwait_clear(__pyx_CoroutineAwaitObject *self) {
+    Py_CLEAR(self->coroutine);
+    return 0;
+}
+static PyObject *__Pyx_CoroutineAwait_Next(__pyx_CoroutineAwaitObject *self) {
+    return __Pyx_Generator_Next(self->coroutine);
+}
+static PyObject *__Pyx_CoroutineAwait_Send(__pyx_CoroutineAwaitObject *self, PyObject *value) {
+    return __Pyx_Coroutine_Send(self->coroutine, value);
+}
+static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args) {
+    return __Pyx_Coroutine_Throw(self->coroutine, args);
+}
+static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self, CYTHON_UNUSED PyObject *arg) {
+    return __Pyx_Coroutine_Close(self->coroutine);
+}
+static PyObject *__Pyx_CoroutineAwait_self(PyObject *self) {
+    Py_INCREF(self);
+    return self;
+}
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject *__Pyx_CoroutineAwait_no_new(CYTHON_UNUSED PyTypeObject *type, CYTHON_UNUSED PyObject *args, CYTHON_UNUSED PyObject *kwargs) {
+    PyErr_SetString(PyExc_TypeError, "cannot instantiate type, use 'await coroutine' instead");
+    return NULL;
+}
+#endif
+static PyMethodDef __pyx_CoroutineAwait_methods[] = {
+    {"send", (PyCFunction) __Pyx_CoroutineAwait_Send, METH_O,
+     (char*) PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next yielded value or raise StopIteration.")},
+    {"throw", (PyCFunction) __Pyx_CoroutineAwait_Throw, METH_VARARGS,
+     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next yielded value or raise StopIteration.")},
+    {"close", (PyCFunction) __Pyx_CoroutineAwait_Close, METH_NOARGS,
+     (char*) PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")},
+    {0, 0, 0, 0}
+};
+static PyTypeObject __pyx_CoroutineAwaitType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "coroutine_wrapper",
+    sizeof(__pyx_CoroutineAwaitObject),
+    0,
+    (destructor) __Pyx_CoroutineAwait_dealloc,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    PyDoc_STR("A wrapper object implementing __await__ for coroutines."),
+    (traverseproc) __Pyx_CoroutineAwait_traverse,
+    (inquiry) __Pyx_CoroutineAwait_clear,
+    0,
+    0,
+    __Pyx_CoroutineAwait_self,
+    (iternextfunc) __Pyx_CoroutineAwait_Next,
+    __pyx_CoroutineAwait_methods,
+    0                         ,
+    0                      ,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if !CYTHON_COMPILING_IN_PYPY
+    __Pyx_CoroutineAwait_no_new,
+#else
+    0,
+#endif
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    0,
+#endif
+};
+#if PY_VERSION_HEX < 0x030500B1 || defined(__Pyx_IterableCoroutine_USED) || CYTHON_USE_ASYNC_SLOTS
+static CYTHON_INLINE PyObject *__Pyx__Coroutine_await(PyObject *coroutine) {
+    __pyx_CoroutineAwaitObject *await = PyObject_GC_New(__pyx_CoroutineAwaitObject, __pyx_CoroutineAwaitType);
+    if (unlikely(!await)) return NULL;
+    Py_INCREF(coroutine);
+    await->coroutine = coroutine;
+    PyObject_GC_Track(await);
+    return (PyObject*)await;
+}
+#endif
+#if PY_VERSION_HEX < 0x030500B1
+static PyObject *__Pyx_Coroutine_await_method(PyObject *coroutine, CYTHON_UNUSED PyObject *arg) {
+    return __Pyx__Coroutine_await(coroutine);
+}
+#endif
+#if defined(__Pyx_IterableCoroutine_USED) || CYTHON_USE_ASYNC_SLOTS
+static PyObject *__Pyx_Coroutine_await(PyObject *coroutine) {
+    if (unlikely(!coroutine || !__Pyx_Coroutine_Check(coroutine))) {
+        PyErr_SetString(PyExc_TypeError, "invalid input, expected coroutine");
+        return NULL;
+    }
+    return __Pyx__Coroutine_await(coroutine);
+}
+#endif
+static PyObject *
+__Pyx_Coroutine_get_frame(CYTHON_UNUSED __pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
+{
+    Py_RETURN_NONE;
+}
+#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
+static PyObject *__Pyx_Coroutine_compare(PyObject *obj, PyObject *other, int op) {
+    PyObject* result;
+    switch (op) {
+        case Py_EQ: result = (other == obj) ? Py_True : Py_False; break;
+        case Py_NE: result = (other != obj) ? Py_True : Py_False; break;
+        default:
+            result = Py_NotImplemented;
+    }
+    Py_INCREF(result);
+    return result;
+}
+#endif
+static PyMethodDef __pyx_Coroutine_methods[] = {
+    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
+     (char*) PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next iterated value or raise StopIteration.")},
+    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
+     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next iterated value or raise StopIteration.")},
+    {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS,
+     (char*) PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")},
+#if PY_VERSION_HEX < 0x030500B1
+    {"__await__", (PyCFunction) __Pyx_Coroutine_await_method, METH_NOARGS,
+     (char*) PyDoc_STR("__await__() -> return an iterator to be used in await expression.")},
+#endif
+    {0, 0, 0, 0}
+};
+static PyMemberDef __pyx_Coroutine_memberlist[] = {
+    {(char *) "cr_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
+    {(char*) "cr_await", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
+     (char*) PyDoc_STR("object being awaited, or None")},
+    {(char*) "cr_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL},
+    {(char *) "__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), PY_WRITE_RESTRICTED, 0},
+    {0, 0, 0, 0, 0}
+};
+static PyGetSetDef __pyx_Coroutine_getsets[] = {
+    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
+     (char*) PyDoc_STR("name of the coroutine"), 0},
+    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
+     (char*) PyDoc_STR("qualified name of the coroutine"), 0},
+    {(char *) "cr_frame", (getter)__Pyx_Coroutine_get_frame, NULL,
+     (char*) PyDoc_STR("Frame of the coroutine"), 0},
+    {0, 0, 0, 0, 0}
+};
+#if CYTHON_USE_ASYNC_SLOTS
+static __Pyx_PyAsyncMethodsStruct __pyx_Coroutine_as_async = {
+    __Pyx_Coroutine_await,
+    0,
+    0,
+};
+#endif
+static PyTypeObject __pyx_CoroutineType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "coroutine",
+    sizeof(__pyx_CoroutineObject),
+    0,
+    (destructor) __Pyx_Coroutine_dealloc,
+    0,
+    0,
+    0,
+#if CYTHON_USE_ASYNC_SLOTS
+    &__pyx_Coroutine_as_async,
+#else
+    0,
+#endif
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
+    0,
+    (traverseproc) __Pyx_Coroutine_traverse,
+    0,
+#if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
+    __Pyx_Coroutine_compare,
+#else
+    0,
+#endif
+    offsetof(__pyx_CoroutineObject, gi_weakreflist),
+    0,
+    0,
+    __pyx_Coroutine_methods,
+    __pyx_Coroutine_memberlist,
+    __pyx_Coroutine_getsets,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if CYTHON_USE_TP_FINALIZE
+    0,
+#else
+    __Pyx_Coroutine_del,
+#endif
+    0,
+#if CYTHON_USE_TP_FINALIZE
+    __Pyx_Coroutine_del,
+#elif PY_VERSION_HEX >= 0x030400a1
+    0,
+#endif
+};
+static int __pyx_Coroutine_init(void) {
+    __pyx_CoroutineType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+    __pyx_CoroutineType = __Pyx_FetchCommonType(&__pyx_CoroutineType_type);
+    if (unlikely(!__pyx_CoroutineType))
+        return -1;
+#ifdef __Pyx_IterableCoroutine_USED
+    if (unlikely(__pyx_IterableCoroutine_init() == -1))
+        return -1;
+#endif
+    __pyx_CoroutineAwaitType = __Pyx_FetchCommonType(&__pyx_CoroutineAwaitType_type);
+    if (unlikely(!__pyx_CoroutineAwaitType))
+        return -1;
+    return 0;
+}
+
+/* GetAwaitIter */
+static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) {
+#ifdef __Pyx_Coroutine_USED
+    if (__Pyx_Coroutine_Check(o)) {
+        return __Pyx_NewRef(o);
+    }
+#endif
+    return __Pyx__Coroutine_GetAwaitableIter(o);
+}
+static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) {
+#if PY_VERSION_HEX >= 0x030600B3 || defined(_PyErr_FormatFromCause)
+    _PyErr_FormatFromCause(
+        PyExc_TypeError,
+        "'async for' received an invalid object "
+        "from __anext__: %.100s",
+        Py_TYPE(source)->tp_name);
+#elif PY_MAJOR_VERSION >= 3
+    PyObject *exc, *val, *val2, *tb;
+    assert(PyErr_Occurred());
+    PyErr_Fetch(&exc, &val, &tb);
+    PyErr_NormalizeException(&exc, &val, &tb);
+    if (tb != NULL) {
+        PyException_SetTraceback(val, tb);
+        Py_DECREF(tb);
+    }
+    Py_DECREF(exc);
+    assert(!PyErr_Occurred());
+    PyErr_Format(
+        PyExc_TypeError,
+        "'async for' received an invalid object "
+        "from __anext__: %.100s",
+        Py_TYPE(source)->tp_name);
+    PyErr_Fetch(&exc, &val2, &tb);
+    PyErr_NormalizeException(&exc, &val2, &tb);
+    Py_INCREF(val);
+    PyException_SetCause(val2, val);
+    PyException_SetContext(val2, val);
+    PyErr_Restore(exc, val2, tb);
+#else
+    source++;
+#endif
+}
+static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
+    PyObject *res;
+#if CYTHON_USE_ASYNC_SLOTS
+    __Pyx_PyAsyncMethodsStruct* am = __Pyx_PyType_AsAsync(obj);
+    if (likely(am && am->am_await)) {
+        res = (*am->am_await)(obj);
+    } else
+#endif
+#if PY_VERSION_HEX >= 0x030500B2 || defined(PyCoro_CheckExact)
+    if (PyCoro_CheckExact(obj)) {
+        return __Pyx_NewRef(obj);
+    } else
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON && defined(CO_ITERABLE_COROUTINE)
+    if (PyGen_CheckExact(obj) && ((PyGenObject*)obj)->gi_code && ((PyCodeObject *)((PyGenObject*)obj)->gi_code)->co_flags & CO_ITERABLE_COROUTINE) {
+        return __Pyx_NewRef(obj);
+    } else
+#endif
+    {
+        PyObject *method = NULL;
+        int is_method = __Pyx_PyObject_GetMethod(obj, __pyx_n_s_await, &method);
+        if (likely(is_method)) {
+            res = __Pyx_PyObject_CallOneArg(method, obj);
+        } else if (likely(method)) {
+            res = __Pyx_PyObject_CallNoArg(method);
+        } else
+            goto slot_error;
+        Py_DECREF(method);
+    }
+    if (unlikely(!res)) {
+        __Pyx_Coroutine_AwaitableIterError(obj);
+        goto bad;
+    }
+    if (unlikely(!PyIter_Check(res))) {
+        PyErr_Format(PyExc_TypeError,
+                     "__await__() returned non-iterator of type '%.100s'",
+                     Py_TYPE(res)->tp_name);
+        Py_CLEAR(res);
+    } else {
+        int is_coroutine = 0;
+        #ifdef __Pyx_Coroutine_USED
+        is_coroutine |= __Pyx_Coroutine_Check(res);
+        #endif
+        #if PY_VERSION_HEX >= 0x030500B2 || defined(PyCoro_CheckExact)
+        is_coroutine |= PyCoro_CheckExact(res);
+        #endif
+        if (unlikely(is_coroutine)) {
+            /* __await__ must return an *iterator*, not
+               a coroutine or another awaitable (see PEP 492) */
+            PyErr_SetString(PyExc_TypeError,
+                            "__await__() returned a coroutine");
+            Py_CLEAR(res);
+        }
+    }
+    return res;
+slot_error:
+    PyErr_Format(PyExc_TypeError,
+                 "object %.100s can't be used in 'await' expression",
+                 Py_TYPE(obj)->tp_name);
+bad:
+    return NULL;
+}
+
+/* CoroutineYieldFrom */
+static PyObject* __Pyx__Coroutine_Yield_From_Generic(__pyx_CoroutineObject *gen, PyObject *source) {
+    PyObject *retval;
+    PyObject *source_gen = __Pyx__Coroutine_GetAwaitableIter(source);
+    if (unlikely(!source_gen)) {
+        return NULL;
+    }
+    if (__Pyx_Coroutine_Check(source_gen)) {
+        retval = __Pyx_Generator_Next(source_gen);
+    } else {
+#if CYTHON_USE_TYPE_SLOTS
+        retval = Py_TYPE(source_gen)->tp_iternext(source_gen);
+#else
+        retval = PyIter_Next(source_gen);
+#endif
+    }
+    if (retval) {
+        gen->yieldfrom = source_gen;
+        return retval;
+    }
+    Py_DECREF(source_gen);
+    return NULL;
+}
+static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject *gen, PyObject *source) {
+    PyObject *retval;
+    if (__Pyx_Coroutine_Check(source)) {
+        if (unlikely(((__pyx_CoroutineObject*)source)->yieldfrom)) {
+            PyErr_SetString(
+                PyExc_RuntimeError,
+                "coroutine is being awaited already");
+            return NULL;
+        }
+        retval = __Pyx_Generator_Next(source);
+#ifdef __Pyx_AsyncGen_USED
+    } else if (__pyx_PyAsyncGenASend_CheckExact(source)) {
+        retval = __Pyx_async_gen_asend_iternext(source);
+#endif
+    } else {
+        return __Pyx__Coroutine_Yield_From_Generic(gen, source);
+    }
+    if (retval) {
+        Py_INCREF(source);
+        gen->yieldfrom = source;
+    }
+    return retval;
+}
+
+/* ReturnWithStopIteration */
+static void __Pyx__ReturnWithStopIteration(PyObject* value) {
+    PyObject *exc, *args;
+#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_PYSTON
+    __Pyx_PyThreadState_declare
+    if ((PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x030500B1)
+            || unlikely(PyTuple_Check(value) || PyExceptionInstance_Check(value))) {
+        args = PyTuple_New(1);
+        if (unlikely(!args)) return;
+        Py_INCREF(value);
+        PyTuple_SET_ITEM(args, 0, value);
+        exc = PyType_Type.tp_call(PyExc_StopIteration, args, NULL);
+        Py_DECREF(args);
+        if (!exc) return;
+    } else {
+        Py_INCREF(value);
+        exc = value;
+    }
+    #if CYTHON_FAST_THREAD_STATE
+    __Pyx_PyThreadState_assign
+    #if CYTHON_USE_EXC_INFO_STACK
+    if (!__pyx_tstate->exc_info->exc_type)
+    #else
+    if (!__pyx_tstate->exc_type)
+    #endif
+    {
+        Py_INCREF(PyExc_StopIteration);
+        __Pyx_ErrRestore(PyExc_StopIteration, exc, NULL);
+        return;
+    }
+    #endif
+#else
+    args = PyTuple_Pack(1, value);
+    if (unlikely(!args)) return;
+    exc = PyObject_Call(PyExc_StopIteration, args, NULL);
+    Py_DECREF(args);
+    if (unlikely(!exc)) return;
+#endif
+    PyErr_SetObject(PyExc_StopIteration, exc);
+    Py_DECREF(exc);
+}
+
+/* None */
+static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
+    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
+}
+
+/* CythonFunction */
+#include <structmember.h>
+static PyObject *
+__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
+{
+    if (unlikely(op->func_doc == NULL)) {
+        if (op->func.m_ml->ml_doc) {
+#if PY_MAJOR_VERSION >= 3
+            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
+#else
+            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
+#endif
+            if (unlikely(op->func_doc == NULL))
+                return NULL;
+        } else {
+            Py_INCREF(Py_None);
+            return Py_None;
+        }
+    }
+    Py_INCREF(op->func_doc);
+    return op->func_doc;
+}
+static int
+__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
+{
+    PyObject *tmp = op->func_doc;
+    if (value == NULL) {
+        value = Py_None;
+    }
+    Py_INCREF(value);
+    op->func_doc = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
+{
+    if (unlikely(op->func_name == NULL)) {
+#if PY_MAJOR_VERSION >= 3
+        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
+#else
+        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
+#endif
+        if (unlikely(op->func_name == NULL))
+            return NULL;
+    }
+    Py_INCREF(op->func_name);
+    return op->func_name;
+}
+static int
+__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value)))
+#else
+    if (unlikely(value == NULL || !PyString_Check(value)))
+#endif
+    {
+        PyErr_SetString(PyExc_TypeError,
+                        "__name__ must be set to a string object");
+        return -1;
+    }
+    tmp = op->func_name;
+    Py_INCREF(value);
+    op->func_name = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
+{
+    Py_INCREF(op->func_qualname);
+    return op->func_qualname;
+}
+static int
+__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value)))
+#else
+    if (unlikely(value == NULL || !PyString_Check(value)))
+#endif
+    {
+        PyErr_SetString(PyExc_TypeError,
+                        "__qualname__ must be set to a string object");
+        return -1;
+    }
+    tmp = op->func_qualname;
+    Py_INCREF(value);
+    op->func_qualname = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
+{
+    PyObject *self;
+    self = m->func_closure;
+    if (self == NULL)
+        self = Py_None;
+    Py_INCREF(self);
+    return self;
+}
+static PyObject *
+__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
+{
+    if (unlikely(op->func_dict == NULL)) {
+        op->func_dict = PyDict_New();
+        if (unlikely(op->func_dict == NULL))
+            return NULL;
+    }
+    Py_INCREF(op->func_dict);
+    return op->func_dict;
+}
+static int
+__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
+{
+    PyObject *tmp;
+    if (unlikely(value == NULL)) {
+        PyErr_SetString(PyExc_TypeError,
+               "function's dictionary may not be deleted");
+        return -1;
+    }
+    if (unlikely(!PyDict_Check(value))) {
+        PyErr_SetString(PyExc_TypeError,
+               "setting function's dictionary to a non-dict");
+        return -1;
+    }
+    tmp = op->func_dict;
+    Py_INCREF(value);
+    op->func_dict = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
+{
+    Py_INCREF(op->func_globals);
+    return op->func_globals;
+}
+static PyObject *
+__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
+{
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+static PyObject *
+__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
+{
+    PyObject* result = (op->func_code) ? op->func_code : Py_None;
+    Py_INCREF(result);
+    return result;
+}
+static int
+__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
+    int result = 0;
+    PyObject *res = op->defaults_getter((PyObject *) op);
+    if (unlikely(!res))
+        return -1;
+    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
+    Py_INCREF(op->defaults_tuple);
+    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
+    Py_INCREF(op->defaults_kwdict);
+    #else
+    op->defaults_tuple = PySequence_ITEM(res, 0);
+    if (unlikely(!op->defaults_tuple)) result = -1;
+    else {
+        op->defaults_kwdict = PySequence_ITEM(res, 1);
+        if (unlikely(!op->defaults_kwdict)) result = -1;
+    }
+    #endif
+    Py_DECREF(res);
+    return result;
+}
+static int
+__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
+    PyObject* tmp;
+    if (!value) {
+        value = Py_None;
+    } else if (value != Py_None && !PyTuple_Check(value)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "__defaults__ must be set to a tuple object");
+        return -1;
+    }
+    Py_INCREF(value);
+    tmp = op->defaults_tuple;
+    op->defaults_tuple = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
+    PyObject* result = op->defaults_tuple;
+    if (unlikely(!result)) {
+        if (op->defaults_getter) {
+            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
+            result = op->defaults_tuple;
+        } else {
+            result = Py_None;
+        }
+    }
+    Py_INCREF(result);
+    return result;
+}
+static int
+__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
+    PyObject* tmp;
+    if (!value) {
+        value = Py_None;
+    } else if (value != Py_None && !PyDict_Check(value)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "__kwdefaults__ must be set to a dict object");
+        return -1;
+    }
+    Py_INCREF(value);
+    tmp = op->defaults_kwdict;
+    op->defaults_kwdict = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
+    PyObject* result = op->defaults_kwdict;
+    if (unlikely(!result)) {
+        if (op->defaults_getter) {
+            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
+            result = op->defaults_kwdict;
+        } else {
+            result = Py_None;
+        }
+    }
+    Py_INCREF(result);
+    return result;
+}
+static int
+__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
+    PyObject* tmp;
+    if (!value || value == Py_None) {
+        value = NULL;
+    } else if (!PyDict_Check(value)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "__annotations__ must be set to a dict object");
+        return -1;
+    }
+    Py_XINCREF(value);
+    tmp = op->func_annotations;
+    op->func_annotations = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
+    PyObject* result = op->func_annotations;
+    if (unlikely(!result)) {
+        result = PyDict_New();
+        if (unlikely(!result)) return NULL;
+        op->func_annotations = result;
+    }
+    Py_INCREF(result);
+    return result;
+}
+static PyGetSetDef __pyx_CyFunction_getsets[] = {
+    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
+    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
+    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
+    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
+    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
+    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
+    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
+    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
+    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
+    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
+    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
+    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
+    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
+    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
+    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
+    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
+    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
+    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
+    {0, 0, 0, 0, 0}
+};
+static PyMemberDef __pyx_CyFunction_members[] = {
+    {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), PY_WRITE_RESTRICTED, 0},
+    {0, 0, 0,  0, 0}
+};
+static PyObject *
+__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
+{
+#if PY_MAJOR_VERSION >= 3
+    return PyUnicode_FromString(m->func.m_ml->ml_name);
+#else
+    return PyString_FromString(m->func.m_ml->ml_name);
+#endif
+}
+static PyMethodDef __pyx_CyFunction_methods[] = {
+    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
+    {0, 0, 0, 0}
+};
+#if PY_VERSION_HEX < 0x030500A0
+#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
+#else
+#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
+#endif
+static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
+                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
+    __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
+    if (op == NULL)
+        return NULL;
+    op->flags = flags;
+    __Pyx_CyFunction_weakreflist(op) = NULL;
+    op->func.m_ml = ml;
+    op->func.m_self = (PyObject *) op;
+    Py_XINCREF(closure);
+    op->func_closure = closure;
+    Py_XINCREF(module);
+    op->func.m_module = module;
+    op->func_dict = NULL;
+    op->func_name = NULL;
+    Py_INCREF(qualname);
+    op->func_qualname = qualname;
+    op->func_doc = NULL;
+    op->func_classobj = NULL;
+    op->func_globals = globals;
+    Py_INCREF(op->func_globals);
+    Py_XINCREF(code);
+    op->func_code = code;
+    op->defaults_pyobjects = 0;
+    op->defaults = NULL;
+    op->defaults_tuple = NULL;
+    op->defaults_kwdict = NULL;
+    op->defaults_getter = NULL;
+    op->func_annotations = NULL;
+    PyObject_GC_Track(op);
+    return (PyObject *) op;
+}
+static int
+__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
+{
+    Py_CLEAR(m->func_closure);
+    Py_CLEAR(m->func.m_module);
+    Py_CLEAR(m->func_dict);
+    Py_CLEAR(m->func_name);
+    Py_CLEAR(m->func_qualname);
+    Py_CLEAR(m->func_doc);
+    Py_CLEAR(m->func_globals);
+    Py_CLEAR(m->func_code);
+    Py_CLEAR(m->func_classobj);
+    Py_CLEAR(m->defaults_tuple);
+    Py_CLEAR(m->defaults_kwdict);
+    Py_CLEAR(m->func_annotations);
+    if (m->defaults) {
+        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
+        int i;
+        for (i = 0; i < m->defaults_pyobjects; i++)
+            Py_XDECREF(pydefaults[i]);
+        PyObject_Free(m->defaults);
+        m->defaults = NULL;
+    }
+    return 0;
+}
+static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m)
+{
+    if (__Pyx_CyFunction_weakreflist(m) != NULL)
+        PyObject_ClearWeakRefs((PyObject *) m);
+    __Pyx_CyFunction_clear(m);
+    PyObject_GC_Del(m);
+}
+static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
+{
+    PyObject_GC_UnTrack(m);
+    __Pyx__CyFunction_dealloc(m);
+}
+static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
+{
+    Py_VISIT(m->func_closure);
+    Py_VISIT(m->func.m_module);
+    Py_VISIT(m->func_dict);
+    Py_VISIT(m->func_name);
+    Py_VISIT(m->func_qualname);
+    Py_VISIT(m->func_doc);
+    Py_VISIT(m->func_globals);
+    Py_VISIT(m->func_code);
+    Py_VISIT(m->func_classobj);
+    Py_VISIT(m->defaults_tuple);
+    Py_VISIT(m->defaults_kwdict);
+    if (m->defaults) {
+        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
+        int i;
+        for (i = 0; i < m->defaults_pyobjects; i++)
+            Py_VISIT(pydefaults[i]);
+    }
+    return 0;
+}
+static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
+{
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
+        Py_INCREF(func);
+        return func;
+    }
+    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
+        if (type == NULL)
+            type = (PyObject *)(Py_TYPE(obj));
+        return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
+    }
+    if (obj == Py_None)
+        obj = NULL;
+    return __Pyx_PyMethod_New(func, obj, type);
+}
+static PyObject*
+__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
+{
+#if PY_MAJOR_VERSION >= 3
+    return PyUnicode_FromFormat("<cyfunction %U at %p>",
+                                op->func_qualname, (void *)op);
+#else
+    return PyString_FromFormat("<cyfunction %s at %p>",
+                               PyString_AsString(op->func_qualname), (void *)op);
+#endif
+}
+static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
+    PyCFunctionObject* f = (PyCFunctionObject*)func;
+    PyCFunction meth = f->m_ml->ml_meth;
+    Py_ssize_t size;
+    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
+    case METH_VARARGS:
+        if (likely(kw == NULL || PyDict_Size(kw) == 0))
+            return (*meth)(self, arg);
+        break;
+    case METH_VARARGS | METH_KEYWORDS:
+        return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw);
+    case METH_NOARGS:
+        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
+            size = PyTuple_GET_SIZE(arg);
+            if (likely(size == 0))
+                return (*meth)(self, NULL);
+            PyErr_Format(PyExc_TypeError,
+                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
+                f->m_ml->ml_name, size);
+            return NULL;
+        }
+        break;
+    case METH_O:
+        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
+            size = PyTuple_GET_SIZE(arg);
+            if (likely(size == 1)) {
+                PyObject *result, *arg0;
+                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+                arg0 = PyTuple_GET_ITEM(arg, 0);
+                #else
+                arg0 = PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL;
+                #endif
+                result = (*meth)(self, arg0);
+                #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
+                Py_DECREF(arg0);
+                #endif
+                return result;
+            }
+            PyErr_Format(PyExc_TypeError,
+                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
+                f->m_ml->ml_name, size);
+            return NULL;
+        }
+        break;
+    default:
+        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
+                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
+                        "longer supported!");
+        return NULL;
+    }
+    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
+                 f->m_ml->ml_name);
+    return NULL;
+}
+static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
+    return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw);
+}
+static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
+    PyObject *result;
+    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
+    if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
+        Py_ssize_t argc;
+        PyObject *new_args;
+        PyObject *self;
+        argc = PyTuple_GET_SIZE(args);
+        new_args = PyTuple_GetSlice(args, 1, argc);
+        if (unlikely(!new_args))
+            return NULL;
+        self = PyTuple_GetItem(args, 0);
+        if (unlikely(!self)) {
+            Py_DECREF(new_args);
+            return NULL;
+        }
+        result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
+        Py_DECREF(new_args);
+    } else {
+        result = __Pyx_CyFunction_Call(func, args, kw);
+    }
+    return result;
+}
+static PyTypeObject __pyx_CyFunctionType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "cython_function_or_method",
+    sizeof(__pyx_CyFunctionObject),
+    0,
+    (destructor) __Pyx_CyFunction_dealloc,
+    0,
+    0,
+    0,
+#if PY_MAJOR_VERSION < 3
+    0,
+#else
+    0,
+#endif
+    (reprfunc) __Pyx_CyFunction_repr,
+    0,
+    0,
+    0,
+    0,
+    __Pyx_CyFunction_CallAsMethod,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    0,
+    (traverseproc) __Pyx_CyFunction_traverse,
+    (inquiry) __Pyx_CyFunction_clear,
+    0,
+#if PY_VERSION_HEX < 0x030500A0
+    offsetof(__pyx_CyFunctionObject, func_weakreflist),
+#else
+    offsetof(PyCFunctionObject, m_weakreflist),
+#endif
+    0,
+    0,
+    __pyx_CyFunction_methods,
+    __pyx_CyFunction_members,
+    __pyx_CyFunction_getsets,
+    0,
+    0,
+    __Pyx_CyFunction_descr_get,
+    0,
+    offsetof(__pyx_CyFunctionObject, func_dict),
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    0,
+#endif
+};
+static int __pyx_CyFunction_init(void) {
+    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
+    if (unlikely(__pyx_CyFunctionType == NULL)) {
+        return -1;
+    }
+    return 0;
+}
+static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->defaults = PyObject_Malloc(size);
+    if (unlikely(!m->defaults))
+        return PyErr_NoMemory();
+    memset(m->defaults, 0, size);
+    m->defaults_pyobjects = pyobjects;
+    return m->defaults;
+}
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->defaults_tuple = tuple;
+    Py_INCREF(tuple);
+}
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->defaults_kwdict = dict;
+    Py_INCREF(dict);
+}
+static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->func_annotations = dict;
+    Py_INCREF(dict);
+}
+
+/* HasAttr */
+static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
+    PyObject *r;
+    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
+        PyErr_SetString(PyExc_TypeError,
+                        "hasattr(): attribute name must be string");
+        return -1;
+    }
+    r = __Pyx_GetAttr(o, n);
+    if (unlikely(!r)) {
+        PyErr_Clear();
+        return 0;
+    } else {
+        Py_DECREF(r);
+        return 1;
+    }
+}
+
+/* Import */
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
+    PyObject *empty_list = 0;
+    PyObject *module = 0;
+    PyObject *global_dict = 0;
+    PyObject *empty_dict = 0;
+    PyObject *list;
+    #if PY_MAJOR_VERSION < 3
+    PyObject *py_import;
+    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
+    if (!py_import)
+        goto bad;
+    #endif
+    if (from_list)
+        list = from_list;
+    else {
+        empty_list = PyList_New(0);
+        if (!empty_list)
+            goto bad;
+        list = empty_list;
+    }
+    global_dict = PyModule_GetDict(__pyx_m);
+    if (!global_dict)
+        goto bad;
+    empty_dict = PyDict_New();
+    if (!empty_dict)
+        goto bad;
+    {
+        #if PY_MAJOR_VERSION >= 3
+        if (level == -1) {
+            if (strchr(__Pyx_MODULE_NAME, '.')) {
+                module = PyImport_ImportModuleLevelObject(
+                    name, global_dict, empty_dict, list, 1);
+                if (!module) {
+                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
+                        goto bad;
+                    PyErr_Clear();
+                }
+            }
+            level = 0;
+        }
+        #endif
+        if (!module) {
+            #if PY_MAJOR_VERSION < 3
+            PyObject *py_level = PyInt_FromLong(level);
+            if (!py_level)
+                goto bad;
+            module = PyObject_CallFunctionObjArgs(py_import,
+                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
+            Py_DECREF(py_level);
+            #else
+            module = PyImport_ImportModuleLevelObject(
+                name, global_dict, empty_dict, list, level);
+            #endif
+        }
+    }
+bad:
+    #if PY_MAJOR_VERSION < 3
+    Py_XDECREF(py_import);
+    #endif
+    Py_XDECREF(empty_list);
+    Py_XDECREF(empty_dict);
+    return module;
+}
+
+/* ImportFrom */
+static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
+    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
+    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+        PyErr_Format(PyExc_ImportError,
+        #if PY_MAJOR_VERSION < 3
+            "cannot import name %.230s", PyString_AS_STRING(name));
+        #else
+            "cannot import name %S", name);
+        #endif
+    }
+    return value;
+}
+
+/* CallNextTpDealloc */
+static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc) {
+    PyTypeObject* type = Py_TYPE(obj);
+    while (type && type->tp_dealloc != current_tp_dealloc)
+        type = type->tp_base;
+    while (type && type->tp_dealloc == current_tp_dealloc)
+        type = type->tp_base;
+    if (type)
+        type->tp_dealloc(obj);
+}
+
+/* CallNextTpTraverse */
+static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) {
+    PyTypeObject* type = Py_TYPE(obj);
+    while (type && type->tp_traverse != current_tp_traverse)
+        type = type->tp_base;
+    while (type && type->tp_traverse == current_tp_traverse)
+        type = type->tp_base;
+    if (type && type->tp_traverse)
+        return type->tp_traverse(obj, v, a);
+    return 0;
+}
+
+/* CallNextTpClear */
+static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
+    PyTypeObject* type = Py_TYPE(obj);
+    while (type && type->tp_clear != current_tp_clear)
+        type = type->tp_base;
+    while (type && type->tp_clear == current_tp_clear)
+        type = type->tp_base;
+    if (type && type->tp_clear)
+        type->tp_clear(obj);
+}
+
+/* SetVTable */
+static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
+#if PY_VERSION_HEX >= 0x02070000
+    PyObject *ob = PyCapsule_New(vtable, 0, 0);
+#else
+    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
+#endif
+    if (!ob)
+        goto bad;
+    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
+        goto bad;
+    Py_DECREF(ob);
+    return 0;
+bad:
+    Py_XDECREF(ob);
+    return -1;
+}
+
+/* SetupReduce */
+static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
+  int ret;
+  PyObject *name_attr;
+  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name_2);
+  if (likely(name_attr)) {
+      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
+  } else {
+      ret = -1;
+  }
+  if (unlikely(ret < 0)) {
+      PyErr_Clear();
+      ret = 0;
+  }
+  Py_XDECREF(name_attr);
+  return ret;
+}
+static int __Pyx_setup_reduce(PyObject* type_obj) {
+    int ret = 0;
+    PyObject *object_reduce = NULL;
+    PyObject *object_reduce_ex = NULL;
+    PyObject *reduce = NULL;
+    PyObject *reduce_ex = NULL;
+    PyObject *reduce_cython = NULL;
+    PyObject *setstate = NULL;
+    PyObject *setstate_cython = NULL;
+#if CYTHON_USE_PYTYPE_LOOKUP
+    if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD;
+#else
+    if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD;
+#endif
+#if CYTHON_USE_PYTYPE_LOOKUP
+    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD;
+#else
+    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD;
+#endif
+    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD;
+    if (reduce_ex == object_reduce_ex) {
+#if CYTHON_USE_PYTYPE_LOOKUP
+        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD;
+#else
+        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD;
+#endif
+        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD;
+        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
+            reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD;
+            ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD;
+            ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD;
+            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
+            if (!setstate) PyErr_Clear();
+            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
+                setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD;
+                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD;
+                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD;
+            }
+            PyType_Modified((PyTypeObject*)type_obj);
+        }
+    }
+    goto GOOD;
+BAD:
+    if (!PyErr_Occurred())
+        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
+    ret = -1;
+GOOD:
+#if !CYTHON_USE_PYTYPE_LOOKUP
+    Py_XDECREF(object_reduce);
+    Py_XDECREF(object_reduce_ex);
+#endif
+    Py_XDECREF(reduce);
+    Py_XDECREF(reduce_ex);
+    Py_XDECREF(reduce_cython);
+    Py_XDECREF(setstate);
+    Py_XDECREF(setstate_cython);
+    return ret;
+}
+
+/* PyObject_GenericGetAttr */
+#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
+static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
+    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
+        return PyObject_GenericGetAttr(obj, attr_name);
+    }
+    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
+}
+#endif
+
+/* TypeImport */
+#ifndef __PYX_HAVE_RT_ImportType
+#define __PYX_HAVE_RT_ImportType
+static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
+    size_t size, enum __Pyx_ImportType_CheckSize check_size)
+{
+    PyObject *result = 0;
+    char warning[200];
+    Py_ssize_t basicsize;
+#ifdef Py_LIMITED_API
+    PyObject *py_basicsize;
+#endif
+    result = PyObject_GetAttrString(module, class_name);
+    if (!result)
+        goto bad;
+    if (!PyType_Check(result)) {
+        PyErr_Format(PyExc_TypeError,
+            "%.200s.%.200s is not a type object",
+            module_name, class_name);
+        goto bad;
+    }
+#ifndef Py_LIMITED_API
+    basicsize = ((PyTypeObject *)result)->tp_basicsize;
+#else
+    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
+    if (!py_basicsize)
+        goto bad;
+    basicsize = PyLong_AsSsize_t(py_basicsize);
+    Py_DECREF(py_basicsize);
+    py_basicsize = 0;
+    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
+        goto bad;
+#endif
+    if ((size_t)basicsize < size) {
+        PyErr_Format(PyExc_ValueError,
+            "%.200s.%.200s size changed, may indicate binary incompatibility. "
+            "Expected %zd from C header, got %zd from PyObject",
+            module_name, class_name, size, basicsize);
+        goto bad;
+    }
+    if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
+        PyErr_Format(PyExc_ValueError,
+            "%.200s.%.200s size changed, may indicate binary incompatibility. "
+            "Expected %zd from C header, got %zd from PyObject",
+            module_name, class_name, size, basicsize);
+        goto bad;
+    }
+    else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
+        PyOS_snprintf(warning, sizeof(warning),
+            "%s.%s size changed, may indicate binary incompatibility. "
+            "Expected %zd from C header, got %zd from PyObject",
+            module_name, class_name, size, basicsize);
+        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
+    }
+    return (PyTypeObject *)result;
+bad:
+    Py_XDECREF(result);
+    return NULL;
+}
+#endif
+
+/* GetVTable */
+static void* __Pyx_GetVtable(PyObject *dict) {
+    void* ptr;
+    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
+    if (!ob)
+        goto bad;
+#if PY_VERSION_HEX >= 0x02070000
+    ptr = PyCapsule_GetPointer(ob, 0);
+#else
+    ptr = PyCObject_AsVoidPtr(ob);
+#endif
+    if (!ptr && !PyErr_Occurred())
+        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
+    Py_DECREF(ob);
+    return ptr;
+bad:
+    Py_XDECREF(ob);
+    return NULL;
+}
+
+/* PatchInspect */
+static PyObject* __Pyx_patch_inspect(PyObject* module) {
+#if defined(__Pyx_Generator_USED) && (!defined(CYTHON_PATCH_INSPECT) || CYTHON_PATCH_INSPECT)
+    static int inspect_patched = 0;
+    if (unlikely((!inspect_patched) && module)) {
+        module = __Pyx_Coroutine_patch_module(
+            module, ""
+"old_types = getattr(_module.isgenerator, '_cython_generator_types', None)\n"
+"if old_types is None or not isinstance(old_types, set):\n"
+"    old_types = set()\n"
+"    def cy_wrap(orig_func, type=type, cython_generator_types=old_types):\n"
+"        def cy_isgenerator(obj): return type(obj) in cython_generator_types or orig_func(obj)\n"
+"        cy_isgenerator._cython_generator_types = cython_generator_types\n"
+"        return cy_isgenerator\n"
+"    _module.isgenerator = cy_wrap(_module.isgenerator)\n"
+"old_types.add(_cython_generator_type)\n"
+        );
+        inspect_patched = 1;
+    }
+#else
+    if ((0)) return __Pyx_Coroutine_patch_module(module, NULL);
+#endif
+    return module;
+}
+
+/* PatchAsyncIO */
+static PyObject* __Pyx_patch_asyncio(PyObject* module) {
+#if PY_VERSION_HEX < 0x030500B2 &&\
+        (defined(__Pyx_Coroutine_USED) || defined(__Pyx_Generator_USED)) &&\
+        (!defined(CYTHON_PATCH_ASYNCIO) || CYTHON_PATCH_ASYNCIO)
+    PyObject *patch_module = NULL;
+    static int asyncio_patched = 0;
+    if (unlikely((!asyncio_patched) && module)) {
+        PyObject *package;
+        package = __Pyx_Import(__pyx_n_s_asyncio_coroutines, NULL, 0);
+        if (package) {
+            patch_module = __Pyx_Coroutine_patch_module(
+                PyObject_GetAttrString(package, "coroutines"), ""
+"try:\n"
+"    coro_types = _module._COROUTINE_TYPES\n"
+"except AttributeError: pass\n"
+"else:\n"
+"    if _cython_coroutine_type is not None and _cython_coroutine_type not in coro_types:\n"
+"        coro_types = tuple(coro_types) + (_cython_coroutine_type,)\n"
+"    if _cython_generator_type is not None and _cython_generator_type not in coro_types:\n"
+"        coro_types = tuple(coro_types) + (_cython_generator_type,)\n"
+"_module._COROUTINE_TYPES = coro_types\n"
+            );
+        } else {
+            PyErr_Clear();
+            package = __Pyx_Import(__pyx_n_s_asyncio_tasks, NULL, 0);
+            if (unlikely(!package)) goto asyncio_done;
+            patch_module = __Pyx_Coroutine_patch_module(
+                PyObject_GetAttrString(package, "tasks"), ""
+"if hasattr(_module, 'iscoroutine'):\n"
+"    old_types = getattr(_module.iscoroutine, '_cython_coroutine_types', None)\n"
+"    if old_types is None or not isinstance(old_types, set):\n"
+"        old_types = set()\n"
+"        def cy_wrap(orig_func, type=type, cython_coroutine_types=old_types):\n"
+"            def cy_iscoroutine(obj): return type(obj) in cython_coroutine_types or orig_func(obj)\n"
+"            cy_iscoroutine._cython_coroutine_types = cython_coroutine_types\n"
+"            return cy_iscoroutine\n"
+"        _module.iscoroutine = cy_wrap(_module.iscoroutine)\n"
+"    if _cython_coroutine_type is not None:\n"
+"        old_types.add(_cython_coroutine_type)\n"
+"    if _cython_generator_type is not None:\n"
+"        old_types.add(_cython_generator_type)\n"
+            );
+        }
+        Py_DECREF(package);
+        if (unlikely(!patch_module)) goto ignore;
+asyncio_done:
+        PyErr_Clear();
+        asyncio_patched = 1;
+#ifdef __Pyx_Generator_USED
+        {
+            PyObject *inspect_module;
+            if (patch_module) {
+                inspect_module = PyObject_GetAttr(patch_module, __pyx_n_s_inspect);
+                Py_DECREF(patch_module);
+            } else {
+                inspect_module = __Pyx_Import(__pyx_n_s_inspect, NULL, 0);
+            }
+            if (unlikely(!inspect_module)) goto ignore;
+            inspect_module = __Pyx_patch_inspect(inspect_module);
+            if (unlikely(!inspect_module)) {
+                Py_DECREF(module);
+                module = NULL;
+            }
+            Py_XDECREF(inspect_module);
+        }
+#else
+        if ((0)) return __Pyx_patch_inspect(module);
+#endif
+    }
+    return module;
+ignore:
+    PyErr_WriteUnraisable(module);
+    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch asyncio package with custom generator type", 1) < 0)) {
+        Py_DECREF(module);
+        module = NULL;
+    }
+#else
+    if ((0)) return __Pyx_patch_inspect(__Pyx_Coroutine_patch_module(module, NULL));
+#endif
+    return module;
+}
+
+/* CalculateMetaclass */
+static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
+    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
+    for (i=0; i < nbases; i++) {
+        PyTypeObject *tmptype;
+        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
+        tmptype = Py_TYPE(tmp);
+#if PY_MAJOR_VERSION < 3
+        if (tmptype == &PyClass_Type)
+            continue;
+#endif
+        if (!metaclass) {
+            metaclass = tmptype;
+            continue;
+        }
+        if (PyType_IsSubtype(metaclass, tmptype))
+            continue;
+        if (PyType_IsSubtype(tmptype, metaclass)) {
+            metaclass = tmptype;
+            continue;
+        }
+        PyErr_SetString(PyExc_TypeError,
+                        "metaclass conflict: "
+                        "the metaclass of a derived class "
+                        "must be a (non-strict) subclass "
+                        "of the metaclasses of all its bases");
+        return NULL;
+    }
+    if (!metaclass) {
+#if PY_MAJOR_VERSION < 3
+        metaclass = &PyClass_Type;
+#else
+        metaclass = &PyType_Type;
+#endif
+    }
+    Py_INCREF((PyObject*) metaclass);
+    return (PyObject*) metaclass;
+}
+
+/* Py3ClassCreate */
+static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
+                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
+    PyObject *ns;
+    if (metaclass) {
+        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare_2);
+        if (prep) {
+            PyObject *pargs = PyTuple_Pack(2, name, bases);
+            if (unlikely(!pargs)) {
+                Py_DECREF(prep);
+                return NULL;
+            }
+            ns = PyObject_Call(prep, pargs, mkw);
+            Py_DECREF(prep);
+            Py_DECREF(pargs);
+        } else {
+            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
+                return NULL;
+            PyErr_Clear();
+            ns = PyDict_New();
+        }
+    } else {
+        ns = PyDict_New();
+    }
+    if (unlikely(!ns))
+        return NULL;
+    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
+    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
+    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
+    return ns;
+bad:
+    Py_DECREF(ns);
+    return NULL;
+}
+static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
+                                      PyObject *dict, PyObject *mkw,
+                                      int calculate_metaclass, int allow_py2_metaclass) {
+    PyObject *result, *margs;
+    PyObject *owned_metaclass = NULL;
+    if (allow_py2_metaclass) {
+        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
+        if (owned_metaclass) {
+            metaclass = owned_metaclass;
+        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
+            PyErr_Clear();
+        } else {
+            return NULL;
+        }
+    }
+    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
+        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
+        Py_XDECREF(owned_metaclass);
+        if (unlikely(!metaclass))
+            return NULL;
+        owned_metaclass = metaclass;
+    }
+    margs = PyTuple_Pack(3, name, bases, dict);
+    if (unlikely(!margs)) {
+        result = NULL;
+    } else {
+        result = PyObject_Call(metaclass, margs, mkw);
+        Py_DECREF(margs);
+    }
+    Py_XDECREF(owned_metaclass);
+    return result;
+}
+
+/* CLineInTraceback */
+#ifndef CYTHON_CLINE_IN_TRACEBACK
+static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) {
+    PyObject *use_cline;
+    PyObject *ptype, *pvalue, *ptraceback;
+#if CYTHON_COMPILING_IN_CPYTHON
+    PyObject **cython_runtime_dict;
+#endif
+    if (unlikely(!__pyx_cython_runtime)) {
+        return c_line;
+    }
+    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
+#if CYTHON_COMPILING_IN_CPYTHON
+    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
+    if (likely(cython_runtime_dict)) {
+        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
+            use_cline, *cython_runtime_dict,
+            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
+    } else
+#endif
+    {
+      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
+      if (use_cline_obj) {
+        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
+        Py_DECREF(use_cline_obj);
+      } else {
+        PyErr_Clear();
+        use_cline = NULL;
+      }
+    }
+    if (!use_cline) {
+        c_line = 0;
+        PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
+    }
+    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
+        c_line = 0;
+    }
+    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
+    return c_line;
+}
+#endif
+
+/* CodeObjectCache */
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+    int start = 0, mid = 0, end = count - 1;
+    if (end >= 0 && code_line > entries[end].code_line) {
+        return count;
+    }
+    while (start < end) {
+        mid = start + (end - start) / 2;
+        if (code_line < entries[mid].code_line) {
+            end = mid;
+        } else if (code_line > entries[mid].code_line) {
+             start = mid + 1;
+        } else {
+            return mid;
+        }
+    }
+    if (code_line <= entries[mid].code_line) {
+        return mid;
+    } else {
+        return mid + 1;
+    }
+}
+static PyCodeObject *__pyx_find_code_object(int code_line) {
+    PyCodeObject* code_object;
+    int pos;
+    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
+        return NULL;
+    }
+    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
+        return NULL;
+    }
+    code_object = __pyx_code_cache.entries[pos].code_object;
+    Py_INCREF(code_object);
+    return code_object;
+}
+static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
+    int pos, i;
+    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
+    if (unlikely(!code_line)) {
+        return;
+    }
+    if (unlikely(!entries)) {
+        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
+        if (likely(entries)) {
+            __pyx_code_cache.entries = entries;
+            __pyx_code_cache.max_count = 64;
+            __pyx_code_cache.count = 1;
+            entries[0].code_line = code_line;
+            entries[0].code_object = code_object;
+            Py_INCREF(code_object);
+        }
+        return;
+    }
+    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
+    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
+        PyCodeObject* tmp = entries[pos].code_object;
+        entries[pos].code_object = code_object;
+        Py_DECREF(tmp);
+        return;
+    }
+    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
+        int new_max = __pyx_code_cache.max_count + 64;
+        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
+            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
+        if (unlikely(!entries)) {
+            return;
+        }
+        __pyx_code_cache.entries = entries;
+        __pyx_code_cache.max_count = new_max;
+    }
+    for (i=__pyx_code_cache.count; i>pos; i--) {
+        entries[i] = entries[i-1];
+    }
+    entries[pos].code_line = code_line;
+    entries[pos].code_object = code_object;
+    __pyx_code_cache.count++;
+    Py_INCREF(code_object);
+}
+
+/* AddTraceback */
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
+            const char *funcname, int c_line,
+            int py_line, const char *filename) {
+    PyCodeObject *py_code = 0;
+    PyObject *py_srcfile = 0;
+    PyObject *py_funcname = 0;
+    #if PY_MAJOR_VERSION < 3
+    py_srcfile = PyString_FromString(filename);
+    #else
+    py_srcfile = PyUnicode_FromString(filename);
+    #endif
+    if (!py_srcfile) goto bad;
+    if (c_line) {
+        #if PY_MAJOR_VERSION < 3
+        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+        #else
+        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
+        #endif
+    }
+    else {
+        #if PY_MAJOR_VERSION < 3
+        py_funcname = PyString_FromString(funcname);
+        #else
+        py_funcname = PyUnicode_FromString(funcname);
+        #endif
+    }
+    if (!py_funcname) goto bad;
+    py_code = __Pyx_PyCode_New(
+        0,
+        0,
+        0,
+        0,
+        0,
+        __pyx_empty_bytes, /*PyObject *code,*/
+        __pyx_empty_tuple, /*PyObject *consts,*/
+        __pyx_empty_tuple, /*PyObject *names,*/
+        __pyx_empty_tuple, /*PyObject *varnames,*/
+        __pyx_empty_tuple, /*PyObject *freevars,*/
+        __pyx_empty_tuple, /*PyObject *cellvars,*/
+        py_srcfile,   /*PyObject *filename,*/
+        py_funcname,  /*PyObject *name,*/
+        py_line,
+        __pyx_empty_bytes  /*PyObject *lnotab*/
+    );
+    Py_DECREF(py_srcfile);
+    Py_DECREF(py_funcname);
+    return py_code;
+bad:
+    Py_XDECREF(py_srcfile);
+    Py_XDECREF(py_funcname);
+    return NULL;
+}
+static void __Pyx_AddTraceback(const char *funcname, int c_line,
+                               int py_line, const char *filename) {
+    PyCodeObject *py_code = 0;
+    PyFrameObject *py_frame = 0;
+    PyThreadState *tstate = __Pyx_PyThreadState_Current;
+    if (c_line) {
+        c_line = __Pyx_CLineForTraceback(tstate, c_line);
+    }
+    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
+    if (!py_code) {
+        py_code = __Pyx_CreateCodeObjectForTraceback(
+            funcname, c_line, py_line, filename);
+        if (!py_code) goto bad;
+        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
+    }
+    py_frame = PyFrame_New(
+        tstate,            /*PyThreadState *tstate,*/
+        py_code,           /*PyCodeObject *code,*/
+        __pyx_d,    /*PyObject *globals,*/
+        0                  /*PyObject *locals*/
+    );
+    if (!py_frame) goto bad;
+    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
+    PyTraceBack_Here(py_frame);
+bad:
+    Py_XDECREF(py_code);
+    Py_XDECREF(py_frame);
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) ((enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_AuthenticationMessage),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
+    const int32_t neg_one = (int32_t) ((int32_t) 0 - (int32_t) 1), const_zero = (int32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int32_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int32_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int32_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntFromPyVerify */
+#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
+#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
+#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
+    {\
+        func_type value = func_value;\
+        if (sizeof(target_type) < sizeof(func_type)) {\
+            if (unlikely(value != (func_type) (target_type) value)) {\
+                func_type zero = 0;\
+                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
+                    return (target_type) -1;\
+                if (is_unsigned && unlikely(value < zero))\
+                    goto raise_neg_overflow;\
+                else\
+                    goto raise_overflow;\
+            }\
+        }\
+        return (target_type) value;\
+    }
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) ((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) {
+    const uint64_t neg_one = (uint64_t) ((uint64_t) 0 - (uint64_t) 1), const_zero = (uint64_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(uint64_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(uint64_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(uint64_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_7asyncpg_8protocol_8protocol_CodecType(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType value) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) ((enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_CodecType),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
+    const uint32_t neg_one = (uint32_t) ((uint32_t) 0 - (uint32_t) 1), const_zero = (uint32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(uint32_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(uint32_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(uint32_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
+    const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
+    const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(long) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(long) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(long) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(long),
+                                     little, !is_unsigned);
+    }
+}
+
+/* UnicodeAsUCS4 */
+static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
+   Py_ssize_t length;
+   #if CYTHON_PEP393_ENABLED
+   length = PyUnicode_GET_LENGTH(x);
+   if (likely(length == 1)) {
+       return PyUnicode_READ_CHAR(x, 0);
+   }
+   #else
+   length = PyUnicode_GET_SIZE(x);
+   if (likely(length == 1)) {
+       return PyUnicode_AS_UNICODE(x)[0];
+   }
+   #if Py_UNICODE_SIZE == 2
+   else if (PyUnicode_GET_SIZE(x) == 2) {
+       Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
+       if (high_val >= 0xD800 && high_val <= 0xDBFF) {
+           Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
+           if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
+               return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
+           }
+       }
+   }
+   #endif
+   #endif
+   PyErr_Format(PyExc_ValueError,
+                "only single character unicode strings can be converted to Py_UCS4, "
+                "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
+   return (Py_UCS4)-1;
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value) {
+    const int64_t neg_one = (int64_t) ((int64_t) 0 - (int64_t) 1), const_zero = (int64_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int64_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int64_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int64_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int64_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_ptrdiff_t(ptrdiff_t value) {
+    const ptrdiff_t neg_one = (ptrdiff_t) ((ptrdiff_t) 0 - (ptrdiff_t) 1), const_zero = (ptrdiff_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(ptrdiff_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(ptrdiff_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(ptrdiff_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(ptrdiff_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(ptrdiff_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(ptrdiff_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
+    const char neg_one = (char) ((char) 0 - (char) 1), const_zero = (char) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(char) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(char) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(char) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(char),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntToPy */
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value) {
+    const int16_t neg_one = (int16_t) ((int16_t) 0 - (int16_t) 1), const_zero = (int16_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int16_t) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int16_t) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int16_t) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+#endif
+        }
+    } else {
+        if (sizeof(int16_t) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+#ifdef HAVE_LONG_LONG
+        } else if (sizeof(int16_t) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+#endif
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int16_t),
+                                     little, !is_unsigned);
+    }
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
+    const int32_t neg_one = (int32_t) ((int32_t) 0 - (int32_t) 1), const_zero = (int32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int32_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int32_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int32_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int32_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) >= 2 * PyLong_SHIFT) {
+                            return (int32_t) (((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) >= 3 * PyLong_SHIFT) {
+                            return (int32_t) (((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) >= 4 * PyLong_SHIFT) {
+                            return (int32_t) (((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int32_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int32_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int32_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int32_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int32_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int32_t) (((int32_t)-1)*(((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int32_t) ((((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int32_t) (((int32_t)-1)*(((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int32_t) ((((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int32_t) (((int32_t)-1)*(((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int32_t) ((((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int32_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int32_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int32_t) -1;
+        }
+    } else {
+        int32_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int32_t) -1;
+        val = __Pyx_PyInt_As_int32_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int32_t");
+    return (int32_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int32_t");
+    return (int32_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(PyObject *x) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) >= 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) (((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) >= 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) (((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) >= 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) (((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)-1)*(((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) ((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)-1)*(((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) ((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)-1)*(((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) ((((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) -1;
+        }
+    } else {
+        enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) -1;
+        val = __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ConnectionStatus) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(PyObject *x) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) >= 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) (((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) >= 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) (((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) >= 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) (((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)-1)*(((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) ((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)-1)*(((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) ((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)-1)*(((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) ((((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) -1;
+        }
+    } else {
+        enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) -1;
+        val = __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ResultType(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ResultType) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(PyObject *x) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) >= 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) >= 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) >= 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)-1)*(((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) ((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)-1)*(((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) ((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)-1)*(((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) ((((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) -1;
+        }
+    } else {
+        enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) -1;
+        val = __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ProtocolState(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ProtocolState) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(PyObject *x) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) ((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) >= 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) (((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) >= 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) (((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) >= 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) (((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) (((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)-1)*(((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) ((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) (((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)-1)*(((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) ((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) (((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)-1)*(((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) ((((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) -1;
+        }
+    } else {
+        enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) -1;
+        val = __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_TransactionStatus) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) {
+    const uint64_t neg_one = (uint64_t) ((uint64_t) 0 - (uint64_t) 1), const_zero = (uint64_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(uint64_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(uint64_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (uint64_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (uint64_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(uint64_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(uint64_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) >= 2 * PyLong_SHIFT) {
+                            return (uint64_t) (((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(uint64_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) >= 3 * PyLong_SHIFT) {
+                            return (uint64_t) (((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(uint64_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) >= 4 * PyLong_SHIFT) {
+                            return (uint64_t) (((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (uint64_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(uint64_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (uint64_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(uint64_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(uint64_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(uint64_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (uint64_t) (((uint64_t)-1)*(((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(uint64_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (uint64_t) ((((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (uint64_t) (((uint64_t)-1)*(((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(uint64_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (uint64_t) ((((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (uint64_t) (((uint64_t)-1)*(((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(uint64_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (uint64_t) ((((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(uint64_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            uint64_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (uint64_t) -1;
+        }
+    } else {
+        uint64_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (uint64_t) -1;
+        val = __Pyx_PyInt_As_uint64_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to uint64_t");
+    return (uint64_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to uint64_t");
+    return (uint64_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
+    const uint32_t neg_one = (uint32_t) ((uint32_t) 0 - (uint32_t) 1), const_zero = (uint32_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(uint32_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(uint32_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (uint32_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (uint32_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(uint32_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(uint32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) >= 2 * PyLong_SHIFT) {
+                            return (uint32_t) (((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(uint32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) >= 3 * PyLong_SHIFT) {
+                            return (uint32_t) (((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(uint32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) >= 4 * PyLong_SHIFT) {
+                            return (uint32_t) (((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (uint32_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(uint32_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (uint32_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(uint32_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(uint32_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(uint32_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (uint32_t) (((uint32_t)-1)*(((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(uint32_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (uint32_t) ((((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (uint32_t) (((uint32_t)-1)*(((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(uint32_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (uint32_t) ((((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (uint32_t) (((uint32_t)-1)*(((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(uint32_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (uint32_t) ((((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(uint32_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            uint32_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (uint32_t) -1;
+        }
+    } else {
+        uint32_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (uint32_t) -1;
+        val = __Pyx_PyInt_As_uint32_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to uint32_t");
+    return (uint32_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to uint32_t");
+    return (uint32_t) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(PyObject *x) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) >= 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) (((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) >= 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) (((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) >= 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) (((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)-1)*(((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) ((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)-1)*(((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) ((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)-1)*(((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) ((((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) -1;
+        }
+    } else {
+        enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) -1;
+        val = __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ServerDataFormat) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
+    const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
+                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
+                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
+                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int) -1;
+        }
+    } else {
+        int val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int) -1;
+        val = __Pyx_PyInt_As_int(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int");
+    return (int) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int");
+    return (int) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
+    const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(long) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (long) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (long) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
+                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
+                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
+                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (long) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(long) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (long) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(long) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            long val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (long) -1;
+        }
+    } else {
+        long val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (long) -1;
+        val = __Pyx_PyInt_As_long(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to long");
+    return (long) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to long");
+    return (long) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(PyObject *x) {
+    const enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat neg_one = (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) ((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 0 - (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 1), const_zero = (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) >= 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) (((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) >= 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) (((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) >= 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) (((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)-1)*(((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 2 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) ((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)-1)*(((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 3 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) ((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) (((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)-1)*(((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) - 1 > 4 * PyLong_SHIFT) {
+                            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) ((((((((((enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) -1;
+        }
+    } else {
+        enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) -1;
+        val = __Pyx_PyInt_As_enum____pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat");
+    return (enum __pyx_t_7asyncpg_8protocol_8protocol_ClientExchangeFormat) -1;
+}
+
+/* CIntFromPy */
+static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) {
+    const int64_t neg_one = (int64_t) ((int64_t) 0 - (int64_t) 1), const_zero = (int64_t) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int64_t) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int64_t, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int64_t) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int64_t) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int64_t, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int64_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) >= 2 * PyLong_SHIFT) {
+                            return (int64_t) (((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int64_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) >= 3 * PyLong_SHIFT) {
+                            return (int64_t) (((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int64_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) >= 4 * PyLong_SHIFT) {
+                            return (int64_t) (((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int64_t) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int64_t) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned long, PyLong_AsUnsignedLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+#endif
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int64_t) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int64_t, sdigit, (sdigit) (-(sdigit)digits[0]))
+                case  1: __PYX_VERIFY_RETURN_INT(int64_t,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int64_t) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int64_t) (((int64_t)-1)*(((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int64_t) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
+                            return (int64_t) ((((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int64_t) (((int64_t)-1)*(((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int64_t) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
+                            return (int64_t) ((((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int64_t) (((int64_t)-1)*(((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int64_t) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT) {
+                            return (int64_t) ((((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int64_t) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, long, PyLong_AsLong(x))
+#ifdef HAVE_LONG_LONG
+            } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
+#endif
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int64_t val;
+            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int64_t) -1;
+        }
+    } else {
+        int64_t val;
+        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
+        if (!tmp) return (int64_t) -1;
+        val = __Pyx_PyInt_As_int64_t(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int64_t");
+    return (int64_t) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int64_t");
+    return (int64_t) -1;
+}
+
+/* ObjectAsUCS4 */
+static Py_UCS4 __Pyx__PyObject_AsPy_UCS4_raise_error(long ival) {
+   if (ival < 0) {
+       if (!PyErr_Occurred())
+           PyErr_SetString(PyExc_OverflowError,
+                           "cannot convert negative value to Py_UCS4");
+   } else {
+       PyErr_SetString(PyExc_OverflowError,
+                       "value too large to convert to Py_UCS4");
+   }
+   return (Py_UCS4)-1;
+}
+static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject* x) {
+   long ival;
+   ival = __Pyx_PyInt_As_long(x);
+   if (unlikely(!__Pyx_is_valid_index(ival, 1114111 + 1))) {
+       return __Pyx__PyObject_AsPy_UCS4_raise_error(ival);
+   }
+   return (Py_UCS4)ival;
+}
+
+/* IterableCoroutine */
+static PyTypeObject __pyx_IterableCoroutineType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "iterable_coroutine",
+    sizeof(__pyx_CoroutineObject),
+    0,
+    (destructor) __Pyx_Coroutine_dealloc,
+    0,
+    0,
+    0,
+#if CYTHON_USE_ASYNC_SLOTS
+    &__pyx_Coroutine_as_async,
+#else
+    0,
+#endif
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
+    0,
+    (traverseproc) __Pyx_Coroutine_traverse,
+    0,
+#if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
+    __Pyx_Coroutine_compare,
+#else
+    0,
+#endif
+    offsetof(__pyx_CoroutineObject, gi_weakreflist),
+    __Pyx_Coroutine_await,
+    (iternextfunc) __Pyx_Generator_Next,
+    __pyx_Coroutine_methods,
+    __pyx_Coroutine_memberlist,
+    __pyx_Coroutine_getsets,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    0,
+#else
+    __Pyx_Coroutine_del,
+#endif
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    __Pyx_Coroutine_del,
+#endif
+};
+static int __pyx_IterableCoroutine_init(void) {
+    __pyx_IterableCoroutineType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+    __pyx_IterableCoroutineType = __Pyx_FetchCommonType(&__pyx_IterableCoroutineType_type);
+    if (unlikely(!__pyx_IterableCoroutineType))
+        return -1;
+    return 0;
+}
+
+/* Generator */
+static PyMethodDef __pyx_Generator_methods[] = {
+    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
+     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
+    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
+     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
+    {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS,
+     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
+    {0, 0, 0, 0}
+};
+static PyMemberDef __pyx_Generator_memberlist[] = {
+    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
+    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
+     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
+    {(char*) "gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL},
+    {0, 0, 0, 0, 0}
+};
+static PyGetSetDef __pyx_Generator_getsets[] = {
+    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
+     (char*) PyDoc_STR("name of the generator"), 0},
+    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
+     (char*) PyDoc_STR("qualified name of the generator"), 0},
+    {0, 0, 0, 0, 0}
+};
+static PyTypeObject __pyx_GeneratorType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "generator",
+    sizeof(__pyx_CoroutineObject),
+    0,
+    (destructor) __Pyx_Coroutine_dealloc,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
+    0,
+    (traverseproc) __Pyx_Coroutine_traverse,
+    0,
+    0,
+    offsetof(__pyx_CoroutineObject, gi_weakreflist),
+    0,
+    (iternextfunc) __Pyx_Generator_Next,
+    __pyx_Generator_methods,
+    __pyx_Generator_memberlist,
+    __pyx_Generator_getsets,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if CYTHON_USE_TP_FINALIZE
+    0,
+#else
+    __Pyx_Coroutine_del,
+#endif
+    0,
+#if CYTHON_USE_TP_FINALIZE
+    __Pyx_Coroutine_del,
+#elif PY_VERSION_HEX >= 0x030400a1
+    0,
+#endif
+};
+static int __pyx_Generator_init(void) {
+    __pyx_GeneratorType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
+    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
+    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
+    if (unlikely(!__pyx_GeneratorType)) {
+        return -1;
+    }
+    return 0;
+}
+
+/* CheckBinaryVersion */
+static int __Pyx_check_binary_version(void) {
+    char ctversion[4], rtversion[4];
+    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+        char message[200];
+        PyOS_snprintf(message, sizeof(message),
+                      "compiletime version %s of module '%.100s' "
+                      "does not match runtime version %s",
+                      ctversion, __Pyx_MODULE_NAME, rtversion);
+        return PyErr_WarnEx(NULL, message, 1);
+    }
+    return 0;
+}
+
+/* VoidPtrExport */
+static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) {
+    PyObject *d;
+    PyObject *cobj = 0;
+    d = PyDict_GetItem(__pyx_d, __pyx_n_s_pyx_capi);
+    Py_XINCREF(d);
+    if (!d) {
+        d = PyDict_New();
+        if (!d)
+            goto bad;
+        if (__Pyx_PyObject_SetAttrStr(__pyx_m, __pyx_n_s_pyx_capi, d) < 0)
+            goto bad;
+    }
+#if PY_VERSION_HEX >= 0x02070000
+    cobj = PyCapsule_New(p, sig, 0);
+#else
+    cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
+#endif
+    if (!cobj)
+        goto bad;
+    if (PyDict_SetItem(d, name, cobj) < 0)
+        goto bad;
+    Py_DECREF(cobj);
+    Py_DECREF(d);
+    return 0;
+bad:
+    Py_XDECREF(cobj);
+    Py_XDECREF(d);
+    return -1;
+}
+
+/* FunctionImport */
+#ifndef __PYX_HAVE_RT_ImportFunction
+#define __PYX_HAVE_RT_ImportFunction
+static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
+    PyObject *d = 0;
+    PyObject *cobj = 0;
+    union {
+        void (*fp)(void);
+        void *p;
+    } tmp;
+    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
+    if (!d)
+        goto bad;
+    cobj = PyDict_GetItemString(d, funcname);
+    if (!cobj) {
+        PyErr_Format(PyExc_ImportError,
+            "%.200s does not export expected C function %.200s",
+                PyModule_GetName(module), funcname);
+        goto bad;
+    }
+#if PY_VERSION_HEX >= 0x02070000
+    if (!PyCapsule_IsValid(cobj, sig)) {
+        PyErr_Format(PyExc_TypeError,
+            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
+             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
+        goto bad;
+    }
+    tmp.p = PyCapsule_GetPointer(cobj, sig);
+#else
+    {const char *desc, *s1, *s2;
+    desc = (const char *)PyCObject_GetDesc(cobj);
+    if (!desc)
+        goto bad;
+    s1 = desc; s2 = sig;
+    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
+    if (*s1 != *s2) {
+        PyErr_Format(PyExc_TypeError,
+            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
+             PyModule_GetName(module), funcname, sig, desc);
+        goto bad;
+    }
+    tmp.p = PyCObject_AsVoidPtr(cobj);}
+#endif
+    *f = tmp.fp;
+    if (!(*f))
+        goto bad;
+    Py_DECREF(d);
+    return 0;
+bad:
+    Py_XDECREF(d);
+    return -1;
+}
+#endif
+
+/* InitStrings */
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+    while (t->p) {
+        #if PY_MAJOR_VERSION < 3
+        if (t->is_unicode) {
+            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+        } else if (t->intern) {
+            *t->p = PyString_InternFromString(t->s);
+        } else {
+            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+        }
+        #else
+        if (t->is_unicode | t->is_str) {
+            if (t->intern) {
+                *t->p = PyUnicode_InternFromString(t->s);
+            } else if (t->encoding) {
+                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+            } else {
+                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+            }
+        } else {
+            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+        }
+        #endif
+        if (!*t->p)
+            return -1;
+        if (PyObject_Hash(*t->p) == -1)
+            return -1;
+        ++t;
+    }
+    return 0;
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
+    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
+}
+static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
+    Py_ssize_t ignore;
+    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
+}
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+#if !CYTHON_PEP393_ENABLED
+static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
+    char* defenc_c;
+    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
+    if (!defenc) return NULL;
+    defenc_c = PyBytes_AS_STRING(defenc);
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+    {
+        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
+        char* c;
+        for (c = defenc_c; c < end; c++) {
+            if ((unsigned char) (*c) >= 128) {
+                PyUnicode_AsASCIIString(o);
+                return NULL;
+            }
+        }
+    }
+#endif
+    *length = PyBytes_GET_SIZE(defenc);
+    return defenc_c;
+}
+#else
+static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
+    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+    if (likely(PyUnicode_IS_ASCII(o))) {
+        *length = PyUnicode_GET_LENGTH(o);
+        return PyUnicode_AsUTF8(o);
+    } else {
+        PyUnicode_AsASCIIString(o);
+        return NULL;
+    }
+#else
+    return PyUnicode_AsUTF8AndSize(o, length);
+#endif
+}
+#endif
+#endif
+static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
+#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+    if (
+#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
+            __Pyx_sys_getdefaultencoding_not_ascii &&
+#endif
+            PyUnicode_Check(o)) {
+        return __Pyx_PyUnicode_AsStringAndSize(o, length);
+    } else
+#endif
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
+    if (PyByteArray_Check(o)) {
+        *length = PyByteArray_GET_SIZE(o);
+        return PyByteArray_AS_STRING(o);
+    } else
+#endif
+    {
+        char* result;
+        int r = PyBytes_AsStringAndSize(o, &result, length);
+        if (unlikely(r < 0)) {
+            return NULL;
+        } else {
+            return result;
+        }
+    }
+}
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+   int is_true = x == Py_True;
+   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+   else return PyObject_IsTrue(x);
+}
+static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
+    int retval;
+    if (unlikely(!x)) return -1;
+    retval = __Pyx_PyObject_IsTrue(x);
+    Py_DECREF(x);
+    return retval;
+}
+static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
+#if PY_MAJOR_VERSION >= 3
+    if (PyLong_Check(result)) {
+        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
+                "__int__ returned non-int (type %.200s).  "
+                "The ability to return an instance of a strict subclass of int "
+                "is deprecated, and may be removed in a future version of Python.",
+                Py_TYPE(result)->tp_name)) {
+            Py_DECREF(result);
+            return NULL;
+        }
+        return result;
+    }
+#endif
+    PyErr_Format(PyExc_TypeError,
+                 "__%.4s__ returned non-%.4s (type %.200s)",
+                 type_name, type_name, Py_TYPE(result)->tp_name);
+    Py_DECREF(result);
+    return NULL;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
+#if CYTHON_USE_TYPE_SLOTS
+  PyNumberMethods *m;
+#endif
+  const char *name = NULL;
+  PyObject *res = NULL;
+#if PY_MAJOR_VERSION < 3
+  if (likely(PyInt_Check(x) || PyLong_Check(x)))
+#else
+  if (likely(PyLong_Check(x)))
+#endif
+    return __Pyx_NewRef(x);
+#if CYTHON_USE_TYPE_SLOTS
+  m = Py_TYPE(x)->tp_as_number;
+  #if PY_MAJOR_VERSION < 3
+  if (m && m->nb_int) {
+    name = "int";
+    res = m->nb_int(x);
+  }
+  else if (m && m->nb_long) {
+    name = "long";
+    res = m->nb_long(x);
+  }
+  #else
+  if (likely(m && m->nb_int)) {
+    name = "int";
+    res = m->nb_int(x);
+  }
+  #endif
+#else
+  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
+    res = PyNumber_Int(x);
+  }
+#endif
+  if (likely(res)) {
+#if PY_MAJOR_VERSION < 3
+    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
+#else
+    if (unlikely(!PyLong_CheckExact(res))) {
+#endif
+        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
+    }
+  }
+  else if (!PyErr_Occurred()) {
+    PyErr_SetString(PyExc_TypeError,
+                    "an integer is required");
+  }
+  return res;
+}
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+  Py_ssize_t ival;
+  PyObject *x;
+#if PY_MAJOR_VERSION < 3
+  if (likely(PyInt_CheckExact(b))) {
+    if (sizeof(Py_ssize_t) >= sizeof(long))
+        return PyInt_AS_LONG(b);
+    else
+        return PyInt_AsSsize_t(b);
+  }
+#endif
+  if (likely(PyLong_CheckExact(b))) {
+    #if CYTHON_USE_PYLONG_INTERNALS
+    const digit* digits = ((PyLongObject*)b)->ob_digit;
+    const Py_ssize_t size = Py_SIZE(b);
+    if (likely(__Pyx_sst_abs(size) <= 1)) {
+        ival = likely(size) ? digits[0] : 0;
+        if (size == -1) ival = -ival;
+        return ival;
+    } else {
+      switch (size) {
+         case 2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+      }
+    }
+    #endif
+    return PyLong_AsSsize_t(b);
+  }
+  x = PyNumber_Index(b);
+  if (!x) return -1;
+  ival = PyInt_AsSsize_t(x);
+  Py_DECREF(x);
+  return ival;
+}
+static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
+  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
+}
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+    return PyInt_FromSize_t(ival);
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/asyncpg/protocol/protocol.pxd b/asyncpg/protocol/protocol.pxd
new file mode 100644 (file)
index 0000000..14a7ecc
--- /dev/null
@@ -0,0 +1,77 @@
+# 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
+
+
+from libc.stdint cimport int16_t, int32_t, uint16_t, \
+                         uint32_t, int64_t, uint64_t
+
+from asyncpg.pgproto.debug cimport PG_DEBUG
+
+from asyncpg.pgproto.pgproto cimport (
+    WriteBuffer,
+    ReadBuffer,
+    FRBuffer,
+)
+
+from asyncpg.pgproto cimport pgproto
+
+include "consts.pxi"
+include "pgtypes.pxi"
+
+include "codecs/base.pxd"
+include "settings.pxd"
+include "coreproto.pxd"
+include "prepared_stmt.pxd"
+
+
+cdef class BaseProtocol(CoreProtocol):
+
+    cdef:
+        object loop
+        object address
+        ConnectionSettings settings
+        object cancel_sent_waiter
+        object cancel_waiter
+        object waiter
+        bint return_extra
+        object create_future
+        object timeout_handle
+        object timeout_callback
+        object completed_callback
+        object conref
+        bint is_reading
+
+        str last_query
+
+        bint writing_paused
+        bint closing
+
+        readonly uint64_t queries_count
+
+        PreparedStatementState statement
+
+    cdef get_connection(self)
+
+    cdef _get_timeout_impl(self, timeout)
+    cdef _check_state(self)
+    cdef _new_waiter(self, timeout)
+    cdef _coreproto_error(self)
+
+    cdef _on_result__connect(self, object waiter)
+    cdef _on_result__prepare(self, object waiter)
+    cdef _on_result__bind_and_exec(self, object waiter)
+    cdef _on_result__close_stmt_or_portal(self, object waiter)
+    cdef _on_result__simple_query(self, object waiter)
+    cdef _on_result__bind(self, object waiter)
+    cdef _on_result__copy_out(self, object waiter)
+    cdef _on_result__copy_in(self, object waiter)
+
+    cdef _handle_waiter_on_connection_lost(self, cause)
+
+    cdef _dispatch_result(self)
+
+    cdef inline resume_reading(self)
+    cdef inline pause_reading(self)
diff --git a/asyncpg/protocol/protocol.pyx b/asyncpg/protocol/protocol.pyx
new file mode 100644 (file)
index 0000000..ac653bd
--- /dev/null
@@ -0,0 +1,961 @@
+# 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
+
+
+# cython: language_level=3
+
+cimport cython
+cimport cpython
+
+import asyncio
+import builtins
+import codecs
+import collections
+import socket
+import time
+import weakref
+
+from asyncpg.pgproto.pgproto cimport (
+    WriteBuffer,
+    ReadBuffer,
+
+    FRBuffer,
+    frb_init,
+    frb_read,
+    frb_read_all,
+    frb_slice_from,
+    frb_check,
+    frb_set_len,
+    frb_get_len,
+)
+
+from asyncpg.pgproto cimport pgproto
+from asyncpg.protocol cimport cpythonx
+from asyncpg.protocol cimport record
+
+from libc.stdint cimport int8_t, uint8_t, int16_t, uint16_t, \
+                         int32_t, uint32_t, int64_t, uint64_t, \
+                         UINT32_MAX
+
+from asyncpg.exceptions import _base as apg_exc_base
+from asyncpg import compat
+from asyncpg import types as apg_types
+from asyncpg import exceptions as apg_exc
+
+from asyncpg.pgproto cimport hton
+
+
+include "consts.pxi"
+include "pgtypes.pxi"
+
+include "encodings.pyx"
+include "settings.pyx"
+
+include "codecs/base.pyx"
+include "codecs/textutils.pyx"
+
+# register codecs provided by pgproto
+include "codecs/pgproto.pyx"
+
+# nonscalar
+include "codecs/array.pyx"
+include "codecs/range.pyx"
+include "codecs/record.pyx"
+
+include "coreproto.pyx"
+include "prepared_stmt.pyx"
+
+
+NO_TIMEOUT = object()
+
+
+cdef class BaseProtocol(CoreProtocol):
+    def __init__(self, addr, connected_fut, con_params, loop):
+        # type of `con_params` is `_ConnectionParameters`
+        CoreProtocol.__init__(self, con_params)
+
+        self.loop = loop
+        self.transport = None
+        self.waiter = connected_fut
+        self.cancel_waiter = None
+        self.cancel_sent_waiter = None
+
+        self.address = addr
+        self.settings = ConnectionSettings((self.address, con_params.database))
+
+        self.statement = None
+        self.return_extra = False
+
+        self.last_query = None
+
+        self.closing = False
+        self.is_reading = True
+        self.writing_allowed = asyncio.Event(loop=self.loop)
+        self.writing_allowed.set()
+
+        self.timeout_handle = None
+        self.timeout_callback = self._on_timeout
+        self.completed_callback = self._on_waiter_completed
+
+        self.queries_count = 0
+
+        try:
+            self.create_future = loop.create_future
+        except AttributeError:
+            self.create_future = self._create_future_fallback
+
+    def set_connection(self, connection):
+        self.conref = weakref.ref(connection)
+
+    cdef get_connection(self):
+        if self.conref is not None:
+            return self.conref()
+        else:
+            return None
+
+    def get_server_pid(self):
+        return self.backend_pid
+
+    def get_settings(self):
+        return self.settings
+
+    def is_in_transaction(self):
+        # PQTRANS_INTRANS = idle, within transaction block
+        # PQTRANS_INERROR = idle, within failed transaction
+        return self.xact_status in (PQTRANS_INTRANS, PQTRANS_INERROR)
+
+    cdef inline resume_reading(self):
+        if not self.is_reading:
+            self.is_reading = True
+            self.transport.resume_reading()
+
+    cdef inline pause_reading(self):
+        if self.is_reading:
+            self.is_reading = False
+            self.transport.pause_reading()
+
+    @cython.iterable_coroutine
+    async def prepare(self, stmt_name, query, timeout,
+                      PreparedStatementState state=None):
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+        timeout = self._get_timeout_impl(timeout)
+
+        waiter = self._new_waiter(timeout)
+        try:
+            self._prepare(stmt_name, query)  # network op
+            self.last_query = query
+            if state is None:
+                state = PreparedStatementState(stmt_name, query, self)
+            self.statement = state
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    @cython.iterable_coroutine
+    async def bind_execute(self, PreparedStatementState state, args,
+                           str portal_name, int limit, return_extra,
+                           timeout):
+
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+        timeout = self._get_timeout_impl(timeout)
+        args_buf = state._encode_bind_msg(args)
+
+        waiter = self._new_waiter(timeout)
+        try:
+            self._bind_execute(
+                portal_name,
+                state.name,
+                args_buf,
+                limit)  # network op
+
+            self.last_query = state.query
+            self.statement = state
+            self.return_extra = return_extra
+            self.queries_count += 1
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    @cython.iterable_coroutine
+    async def bind_execute_many(self, PreparedStatementState state, args,
+                                str portal_name, timeout):
+
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+        timeout = self._get_timeout_impl(timeout)
+
+        # Make sure the argument sequence is encoded lazily with
+        # this generator expression to keep the memory pressure under
+        # control.
+        data_gen = (state._encode_bind_msg(b) for b in args)
+        arg_bufs = iter(data_gen)
+
+        waiter = self._new_waiter(timeout)
+        try:
+            self._bind_execute_many(
+                portal_name,
+                state.name,
+                arg_bufs)  # network op
+
+            self.last_query = state.query
+            self.statement = state
+            self.return_extra = False
+            self.queries_count += 1
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    @cython.iterable_coroutine
+    async def bind(self, PreparedStatementState state, args,
+                   str portal_name, timeout):
+
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+        timeout = self._get_timeout_impl(timeout)
+        args_buf = state._encode_bind_msg(args)
+
+        waiter = self._new_waiter(timeout)
+        try:
+            self._bind(
+                portal_name,
+                state.name,
+                args_buf)  # network op
+
+            self.last_query = state.query
+            self.statement = state
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    @cython.iterable_coroutine
+    async def execute(self, PreparedStatementState state,
+                      str portal_name, int limit, return_extra,
+                      timeout):
+
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+        timeout = self._get_timeout_impl(timeout)
+
+        waiter = self._new_waiter(timeout)
+        try:
+            self._execute(
+                portal_name,
+                limit)  # network op
+
+            self.last_query = state.query
+            self.statement = state
+            self.return_extra = return_extra
+            self.queries_count += 1
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    @cython.iterable_coroutine
+    async def query(self, query, timeout):
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+        # query() needs to call _get_timeout instead of _get_timeout_impl
+        # for consistent validation, as it is called differently from
+        # prepare/bind/execute methods.
+        timeout = self._get_timeout(timeout)
+
+        waiter = self._new_waiter(timeout)
+        try:
+            self._simple_query(query)  # network op
+            self.last_query = query
+            self.queries_count += 1
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    @cython.iterable_coroutine
+    async def copy_out(self, copy_stmt, sink, timeout):
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+
+        timeout = self._get_timeout_impl(timeout)
+        timer = Timer(timeout)
+
+        # The copy operation is guarded by a single timeout
+        # on the top level.
+        waiter = self._new_waiter(timer.get_remaining_budget())
+
+        self._copy_out(copy_stmt)
+
+        try:
+            while True:
+                self.resume_reading()
+
+                with timer:
+                    buffer, done, status_msg = await waiter
+
+                # buffer will be empty if CopyDone was received apart from
+                # the last CopyData message.
+                if buffer:
+                    try:
+                        with timer:
+                            await asyncio.wait_for(
+                                sink(buffer),
+                                timeout=timer.get_remaining_budget(),
+                                loop=self.loop)
+                    except Exception as ex:
+                        # Abort the COPY operation on any error in
+                        # output sink.
+                        self._request_cancel()
+                        # Make asyncio shut up about unretrieved
+                        # QueryCanceledError
+                        waiter.add_done_callback(lambda f: f.exception())
+                        raise
+
+                # done will be True upon receipt of CopyDone.
+                if done:
+                    break
+
+                waiter = self._new_waiter(timer.get_remaining_budget())
+
+        finally:
+            self.resume_reading()
+
+        return status_msg
+
+    @cython.iterable_coroutine
+    async def copy_in(self, copy_stmt, reader, data,
+                      records, PreparedStatementState record_stmt, timeout):
+        cdef:
+            WriteBuffer wbuf
+            ssize_t num_cols
+            Codec codec
+
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+
+        timeout = self._get_timeout_impl(timeout)
+        timer = Timer(timeout)
+
+        waiter = self._new_waiter(timer.get_remaining_budget())
+
+        # Initiate COPY IN.
+        self._copy_in(copy_stmt)
+
+        try:
+            if record_stmt is not None:
+                # copy_in_records in binary mode
+                wbuf = WriteBuffer.new()
+                # Signature
+                wbuf.write_bytes(_COPY_SIGNATURE)
+                # Flags field
+                wbuf.write_int32(0)
+                # No header extension
+                wbuf.write_int32(0)
+
+                record_stmt._ensure_rows_decoder()
+                codecs = record_stmt.rows_codecs
+                num_cols = len(codecs)
+                settings = self.settings
+
+                for codec in codecs:
+                    if (not codec.has_encoder() or
+                            codec.format != PG_FORMAT_BINARY):
+                        raise apg_exc.InternalClientError(
+                            'no binary format encoder for '
+                            'type {} (OID {})'.format(codec.name, codec.oid))
+
+                for row in records:
+                    # Tuple header
+                    wbuf.write_int16(<int16_t>num_cols)
+                    # Tuple data
+                    for i in range(num_cols):
+                        item = row[i]
+                        if item is None:
+                            wbuf.write_int32(-1)
+                        else:
+                            codec = <Codec>cpython.PyTuple_GET_ITEM(codecs, i)
+                            codec.encode(settings, wbuf, item)
+
+                    if wbuf.len() >= _COPY_BUFFER_SIZE:
+                        with timer:
+                            await self.writing_allowed.wait()
+                        self._write_copy_data_msg(wbuf)
+                        wbuf = WriteBuffer.new()
+
+                # End of binary copy.
+                wbuf.write_int16(-1)
+                self._write_copy_data_msg(wbuf)
+
+            elif reader is not None:
+                try:
+                    aiter = reader.__aiter__
+                except AttributeError:
+                    raise TypeError('reader is not an asynchronous iterable')
+                else:
+                    iterator = aiter()
+
+                try:
+                    while True:
+                        # We rely on protocol flow control to moderate the
+                        # rate of data messages.
+                        with timer:
+                            await self.writing_allowed.wait()
+                        with timer:
+                            chunk = await asyncio.wait_for(
+                                iterator.__anext__(),
+                                timeout=timer.get_remaining_budget(),
+                                loop=self.loop)
+                        self._write_copy_data_msg(chunk)
+                except builtins.StopAsyncIteration:
+                    pass
+            else:
+                # Buffer passed in directly.
+                await self.writing_allowed.wait()
+                self._write_copy_data_msg(data)
+
+        except asyncio.TimeoutError:
+            self._write_copy_fail_msg('TimeoutError')
+            self._on_timeout(self.waiter)
+            try:
+                await waiter
+            except TimeoutError:
+                raise
+            else:
+                raise apg_exc.InternalClientError('TimoutError was not raised')
+
+        except Exception as e:
+            self._write_copy_fail_msg(str(e))
+            self._request_cancel()
+            # Make asyncio shut up about unretrieved QueryCanceledError
+            waiter.add_done_callback(lambda f: f.exception())
+            raise
+
+        self._write_copy_done_msg()
+
+        status_msg = await waiter
+
+        return status_msg
+
+    @cython.iterable_coroutine
+    async def close_statement(self, PreparedStatementState state, timeout):
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        self._check_state()
+
+        if state.refs != 0:
+            raise apg_exc.InternalClientError(
+                'cannot close prepared statement; refs == {} != 0'.format(
+                    state.refs))
+
+        timeout = self._get_timeout_impl(timeout)
+        waiter = self._new_waiter(timeout)
+        try:
+            self._close(state.name, False)  # network op
+            state.closed = True
+        except Exception as ex:
+            waiter.set_exception(ex)
+            self._coreproto_error()
+        finally:
+            return await waiter
+
+    def is_closed(self):
+        return self.closing
+
+    def is_connected(self):
+        return not self.closing and self.con_status == CONNECTION_OK
+
+    def abort(self):
+        if self.closing:
+            return
+        self.closing = True
+        self._handle_waiter_on_connection_lost(None)
+        self._terminate()
+        self.transport.abort()
+
+    @cython.iterable_coroutine
+    async def close(self, timeout):
+        if self.closing:
+            return
+
+        self.closing = True
+
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+
+        if self.waiter is not None:
+            # If there is a query running, cancel it
+            self._request_cancel()
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+            if self.cancel_waiter is not None:
+                await self.cancel_waiter
+
+        assert self.waiter is None
+
+        timeout = self._get_timeout_impl(timeout)
+
+        # Ask the server to terminate the connection and wait for it
+        # to drop.
+        self.waiter = self._new_waiter(timeout)
+        self._terminate()
+        try:
+            await self.waiter
+        except ConnectionResetError:
+            # There appears to be a difference in behaviour of asyncio
+            # in Windows, where, instead of calling protocol.connection_lost()
+            # a ConnectionResetError will be thrown into the task.
+            pass
+        finally:
+            self.waiter = None
+        self.transport.abort()
+
+    def _request_cancel(self):
+        self.cancel_waiter = self.create_future()
+        self.cancel_sent_waiter = self.create_future()
+
+        con = self.get_connection()
+        if con is not None:
+            # if 'con' is None it means that the connection object has been
+            # garbage collected and that the transport will soon be aborted.
+            con._cancel_current_command(self.cancel_sent_waiter)
+        else:
+            self.loop.call_exception_handler({
+                'message': 'asyncpg.Protocol has no reference to its '
+                           'Connection object and yet a cancellation '
+                           'was requested. Please report this at '
+                           'github.com/magicstack/asyncpg.'
+            })
+            self.abort()
+
+        self._set_state(PROTOCOL_CANCELLED)
+
+    def _on_timeout(self, fut):
+        if self.waiter is not fut or fut.done() or \
+                self.cancel_waiter is not None or \
+                self.timeout_handle is None:
+            return
+        self._request_cancel()
+        self.waiter.set_exception(asyncio.TimeoutError())
+
+    def _on_waiter_completed(self, fut):
+        if fut is not self.waiter or self.cancel_waiter is not None:
+            return
+        if fut.cancelled():
+            if self.timeout_handle:
+                self.timeout_handle.cancel()
+                self.timeout_handle = None
+            self._request_cancel()
+
+    def _create_future_fallback(self):
+        return asyncio.Future(loop=self.loop)
+
+    cdef _handle_waiter_on_connection_lost(self, cause):
+        if self.waiter is not None and not self.waiter.done():
+            exc = apg_exc.ConnectionDoesNotExistError(
+                'connection was closed in the middle of '
+                'operation')
+            if cause is not None:
+                exc.__cause__ = cause
+            self.waiter.set_exception(exc)
+        self.waiter = None
+
+    cdef _set_server_parameter(self, name, val):
+        self.settings.add_setting(name, val)
+
+    def _get_timeout(self, timeout):
+        if timeout is not None:
+            try:
+                if type(timeout) is bool:
+                    raise ValueError
+                timeout = float(timeout)
+            except ValueError:
+                raise ValueError(
+                    'invalid timeout value: expected non-negative float '
+                    '(got {!r})'.format(timeout)) from None
+
+        return self._get_timeout_impl(timeout)
+
+    cdef inline _get_timeout_impl(self, timeout):
+        if timeout is None:
+            timeout = self.get_connection()._config.command_timeout
+        elif timeout is NO_TIMEOUT:
+            timeout = None
+        else:
+            timeout = float(timeout)
+
+        if timeout is not None and timeout <= 0:
+            raise asyncio.TimeoutError()
+        return timeout
+
+    cdef _check_state(self):
+        if self.cancel_waiter is not None:
+            raise apg_exc.InterfaceError(
+                'cannot perform operation: another operation is cancelling')
+        if self.closing:
+            raise apg_exc.InterfaceError(
+                'cannot perform operation: connection is closed')
+        if self.waiter is not None or self.timeout_handle is not None:
+            raise apg_exc.InterfaceError(
+                'cannot perform operation: another operation is in progress')
+
+    def _is_cancelling(self):
+        return (
+            self.cancel_waiter is not None or
+            self.cancel_sent_waiter is not None
+        )
+
+    @cython.iterable_coroutine
+    async def _wait_for_cancellation(self):
+        if self.cancel_sent_waiter is not None:
+            await self.cancel_sent_waiter
+            self.cancel_sent_waiter = None
+        if self.cancel_waiter is not None:
+            await self.cancel_waiter
+
+    cdef _coreproto_error(self):
+        try:
+            if self.waiter is not None:
+                if not self.waiter.done():
+                    raise apg_exc.InternalClientError(
+                        'waiter is not done while handling critical '
+                        'protocol error')
+                self.waiter = None
+        finally:
+            self.abort()
+
+    cdef _new_waiter(self, timeout):
+        if self.waiter is not None:
+            raise apg_exc.InterfaceError(
+                'cannot perform operation: another operation is in progress')
+        self.waiter = self.create_future()
+        if timeout is not None:
+            self.timeout_handle = self.loop.call_later(
+                timeout, self.timeout_callback, self.waiter)
+        self.waiter.add_done_callback(self.completed_callback)
+        return self.waiter
+
+    cdef _on_result__connect(self, object waiter):
+        waiter.set_result(True)
+
+    cdef _on_result__prepare(self, object waiter):
+        if PG_DEBUG:
+            if self.statement is None:
+                raise apg_exc.InternalClientError(
+                    '_on_result__prepare: statement is None')
+
+        if self.result_param_desc is not None:
+            self.statement._set_args_desc(self.result_param_desc)
+        if self.result_row_desc is not None:
+            self.statement._set_row_desc(self.result_row_desc)
+        waiter.set_result(self.statement)
+
+    cdef _on_result__bind_and_exec(self, object waiter):
+        if self.return_extra:
+            waiter.set_result((
+                self.result,
+                self.result_status_msg,
+                self.result_execute_completed))
+        else:
+            waiter.set_result(self.result)
+
+    cdef _on_result__bind(self, object waiter):
+        waiter.set_result(self.result)
+
+    cdef _on_result__close_stmt_or_portal(self, object waiter):
+        waiter.set_result(self.result)
+
+    cdef _on_result__simple_query(self, object waiter):
+        waiter.set_result(self.result_status_msg.decode(self.encoding))
+
+    cdef _on_result__copy_out(self, object waiter):
+        cdef bint copy_done = self.state == PROTOCOL_COPY_OUT_DONE
+        if copy_done:
+            status_msg = self.result_status_msg.decode(self.encoding)
+        else:
+            status_msg = None
+
+        # We need to put some backpressure on Postgres
+        # here in case the sink is slow to process the output.
+        self.pause_reading()
+
+        waiter.set_result((self.result, copy_done, status_msg))
+
+    cdef _on_result__copy_in(self, object waiter):
+        status_msg = self.result_status_msg.decode(self.encoding)
+        waiter.set_result(status_msg)
+
+    cdef _decode_row(self, const char* buf, ssize_t buf_len):
+        if PG_DEBUG:
+            if self.statement is None:
+                raise apg_exc.InternalClientError(
+                    '_decode_row: statement is None')
+
+        return self.statement._decode_row(buf, buf_len)
+
+    cdef _dispatch_result(self):
+        waiter = self.waiter
+        self.waiter = None
+
+        if PG_DEBUG:
+            if waiter is None:
+                raise apg_exc.InternalClientError('_on_result: waiter is None')
+
+        if waiter.cancelled():
+            return
+
+        if waiter.done():
+            raise apg_exc.InternalClientError('_on_result: waiter is done')
+
+        if self.result_type == RESULT_FAILED:
+            if isinstance(self.result, dict):
+                exc = apg_exc_base.PostgresError.new(
+                    self.result, query=self.last_query)
+            else:
+                exc = self.result
+            waiter.set_exception(exc)
+            return
+
+        try:
+            if self.state == PROTOCOL_AUTH:
+                self._on_result__connect(waiter)
+
+            elif self.state == PROTOCOL_PREPARE:
+                self._on_result__prepare(waiter)
+
+            elif self.state == PROTOCOL_BIND_EXECUTE:
+                self._on_result__bind_and_exec(waiter)
+
+            elif self.state == PROTOCOL_BIND_EXECUTE_MANY:
+                self._on_result__bind_and_exec(waiter)
+
+            elif self.state == PROTOCOL_EXECUTE:
+                self._on_result__bind_and_exec(waiter)
+
+            elif self.state == PROTOCOL_BIND:
+                self._on_result__bind(waiter)
+
+            elif self.state == PROTOCOL_CLOSE_STMT_PORTAL:
+                self._on_result__close_stmt_or_portal(waiter)
+
+            elif self.state == PROTOCOL_SIMPLE_QUERY:
+                self._on_result__simple_query(waiter)
+
+            elif (self.state == PROTOCOL_COPY_OUT_DATA or
+                    self.state == PROTOCOL_COPY_OUT_DONE):
+                self._on_result__copy_out(waiter)
+
+            elif self.state == PROTOCOL_COPY_IN_DATA:
+                self._on_result__copy_in(waiter)
+
+            elif self.state == PROTOCOL_TERMINATING:
+                # We are waiting for the connection to drop, so
+                # ignore any stray results at this point.
+                pass
+
+            else:
+                raise apg_exc.InternalClientError(
+                    'got result for unknown protocol state {}'.
+                    format(self.state))
+
+        except Exception as exc:
+            waiter.set_exception(exc)
+
+    cdef _on_result(self):
+        if self.timeout_handle is not None:
+            self.timeout_handle.cancel()
+            self.timeout_handle = None
+
+        if self.cancel_waiter is not None:
+            # We have received the result of a cancelled command.
+            if not self.cancel_waiter.done():
+                # The cancellation future might have been cancelled
+                # by the cancellation of the entire task running the query.
+                self.cancel_waiter.set_result(None)
+            self.cancel_waiter = None
+            if self.waiter is not None and self.waiter.done():
+                self.waiter = None
+            if self.waiter is None:
+                return
+
+        try:
+            self._dispatch_result()
+        finally:
+            self.statement = None
+            self.last_query = None
+            self.return_extra = False
+
+    cdef _on_notice(self, parsed):
+        con = self.get_connection()
+        if con is not None:
+            con._process_log_message(parsed, self.last_query)
+
+    cdef _on_notification(self, pid, channel, payload):
+        con = self.get_connection()
+        if con is not None:
+            con._process_notification(pid, channel, payload)
+
+    cdef _on_connection_lost(self, exc):
+        if self.closing:
+            # The connection was lost because
+            # Protocol.close() was called
+            if self.waiter is not None and not self.waiter.done():
+                if exc is None:
+                    self.waiter.set_result(None)
+                else:
+                    self.waiter.set_exception(exc)
+            self.waiter = None
+        else:
+            # The connection was lost because it was
+            # terminated or due to another error;
+            # Throw an error in any awaiting waiter.
+            self.closing = True
+            # Cleanup the connection resources, including, possibly,
+            # releasing the pool holder.
+            con = self.get_connection()
+            if con is not None:
+                con._cleanup()
+            self._handle_waiter_on_connection_lost(exc)
+
+    cdef _write(self, buf):
+        self.transport.write(memoryview(buf))
+
+    # asyncio callbacks:
+
+    def data_received(self, data):
+        self.buffer.feed_data(data)
+        self._read_server_messages()
+
+    def connection_made(self, transport):
+        self.transport = transport
+
+        sock = transport.get_extra_info('socket')
+        if (sock is not None and
+              (not hasattr(socket, 'AF_UNIX')
+               or sock.family != socket.AF_UNIX)):
+            sock.setsockopt(socket.IPPROTO_TCP,
+                            socket.TCP_NODELAY, 1)
+
+        try:
+            self._connect()
+        except Exception as ex:
+            transport.abort()
+            self.con_status = CONNECTION_BAD
+            self._set_state(PROTOCOL_FAILED)
+            self._on_error(ex)
+
+    def connection_lost(self, exc):
+        self.con_status = CONNECTION_BAD
+        self._set_state(PROTOCOL_FAILED)
+        self._on_connection_lost(exc)
+
+    def pause_writing(self):
+        self.writing_allowed.clear()
+
+    def resume_writing(self):
+        self.writing_allowed.set()
+
+
+class Timer:
+    def __init__(self, budget):
+        self._budget = budget
+        self._started = 0
+
+    def __enter__(self):
+        if self._budget is not None:
+            self._started = time.monotonic()
+
+    def __exit__(self, et, e, tb):
+        if self._budget is not None:
+            self._budget -= time.monotonic() - self._started
+
+    def get_remaining_budget(self):
+        return self._budget
+
+
+class Protocol(BaseProtocol, asyncio.Protocol):
+    pass
+
+
+def _create_record(object mapping, tuple elems):
+    # Exposed only for testing purposes.
+
+    cdef:
+        object rec
+        int32_t i
+
+    if mapping is None:
+        desc = record.ApgRecordDesc_New({}, ())
+    else:
+        desc = record.ApgRecordDesc_New(
+            mapping, tuple(mapping) if mapping else ())
+
+    rec = record.ApgRecord_New(desc, len(elems))
+    for i in range(len(elems)):
+        elem = elems[i]
+        cpython.Py_INCREF(elem)
+        record.ApgRecord_SET_ITEM(rec, i, elem)
+    return rec
+
+
+Record = <object>record.ApgRecord_InitTypes()
diff --git a/asyncpg/protocol/record/__init__.pxd b/asyncpg/protocol/record/__init__.pxd
new file mode 100644 (file)
index 0000000..3d6b5fd
--- /dev/null
@@ -0,0 +1,19 @@
+# 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
+
+
+cimport cpython
+
+
+cdef extern from "record/recordobj.h":
+
+       cpython.PyTypeObject *ApgRecord_InitTypes() except NULL
+
+       int ApgRecord_CheckExact(object)
+       object ApgRecord_New(object, int)
+       void ApgRecord_SET_ITEM(object, int, object)
+
+       object ApgRecordDesc_New(object, object)
diff --git a/asyncpg/protocol/record/recordobj.c b/asyncpg/protocol/record/recordobj.c
new file mode 100644 (file)
index 0000000..e1de8b0
--- /dev/null
@@ -0,0 +1,918 @@
+/* Big parts of this file are copied (with modifications) from
+   CPython/Objects/tupleobject.c.
+
+   Portions Copyright (c) PSF (and other CPython copyright holders).
+   Portions Copyright (c) 2016-present MagicStack Inc.
+   License: PSFL v2; see CPython/LICENSE for details.
+*/
+
+#include "recordobj.h"
+
+
+static PyObject * record_iter(PyObject *);
+static PyObject * record_new_items_iter(PyObject *);
+
+static ApgRecordObject *free_list[ApgRecord_MAXSAVESIZE];
+static int numfree[ApgRecord_MAXSAVESIZE];
+
+
+PyObject *
+ApgRecord_New(PyObject *desc, Py_ssize_t size)
+{
+    ApgRecordObject *o;
+    Py_ssize_t i;
+
+    if (size < 0 || desc == NULL || !ApgRecordDesc_CheckExact(desc)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+
+    if (size < ApgRecord_MAXSAVESIZE && (o = free_list[size]) != NULL) {
+        free_list[size] = (ApgRecordObject *) o->ob_item[0];
+        numfree[size]--;
+        _Py_NewReference((PyObject *)o);
+    }
+    else {
+        /* Check for overflow */
+        if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - sizeof(ApgRecordObject) -
+                    sizeof(PyObject *)) / sizeof(PyObject *)) {
+            return PyErr_NoMemory();
+        }
+        o = PyObject_GC_NewVar(ApgRecordObject, &ApgRecord_Type, size);
+        if (o == NULL) {
+            return NULL;
+        }
+    }
+
+    for (i = 0; i < size; i++) {
+        o->ob_item[i] = NULL;
+    }
+
+    Py_INCREF(desc);
+    o->desc = (ApgRecordDescObject*)desc;
+    o->self_hash = -1;
+    PyObject_GC_Track(o);
+    return (PyObject *) o;
+}
+
+
+static void
+record_dealloc(ApgRecordObject *o)
+{
+    Py_ssize_t i;
+    Py_ssize_t len = Py_SIZE(o);
+
+    PyObject_GC_UnTrack(o);
+
+    o->self_hash = -1;
+
+    Py_CLEAR(o->desc);
+
+    Py_TRASHCAN_SAFE_BEGIN(o)
+    if (len > 0) {
+        i = len;
+        while (--i >= 0) {
+            Py_CLEAR(o->ob_item[i]);
+        }
+
+        if (len < ApgRecord_MAXSAVESIZE &&
+            numfree[len] < ApgRecord_MAXFREELIST &&
+            ApgRecord_CheckExact(o))
+        {
+            o->ob_item[0] = (PyObject *) free_list[len];
+            numfree[len]++;
+            free_list[len] = o;
+            goto done; /* return */
+        }
+    }
+    Py_TYPE(o)->tp_free((PyObject *)o);
+done:
+    Py_TRASHCAN_SAFE_END(o)
+}
+
+
+static int
+record_traverse(ApgRecordObject *o, visitproc visit, void *arg)
+{
+    Py_ssize_t i;
+
+    Py_VISIT(o->desc);
+
+    for (i = Py_SIZE(o); --i >= 0;) {
+        if (o->ob_item[i] != NULL) {
+            Py_VISIT(o->ob_item[i]);
+        }
+    }
+
+    return 0;
+}
+
+
+static Py_ssize_t
+record_length(ApgRecordObject *o)
+{
+    return Py_SIZE(o);
+}
+
+
+static Py_hash_t
+record_hash(ApgRecordObject *v)
+{
+    Py_uhash_t x;  /* Unsigned for defined overflow behavior. */
+    Py_hash_t y;
+    Py_ssize_t len;
+    PyObject **p;
+    Py_uhash_t mult;
+
+    if (v->self_hash != -1) {
+        return v->self_hash;
+    }
+
+    len = Py_SIZE(v);
+    mult = _PyHASH_MULTIPLIER;
+
+    x = 0x345678UL;
+    p = v->ob_item;
+    while (--len >= 0) {
+        y = PyObject_Hash(*p++);
+        if (y == -1) {
+            return -1;
+        }
+        x = (x ^ (Py_uhash_t)y) * mult;
+        /* the cast might truncate len; that doesn't change hash stability */
+        mult += (Py_uhash_t)(82520UL + (size_t)len + (size_t)len);
+    }
+    x += 97531UL;
+    if (x == (Py_uhash_t)-1) {
+        x = (Py_uhash_t)-2;
+    }
+    v->self_hash = (Py_hash_t)x;
+    return (Py_hash_t)x;
+}
+
+
+static PyObject *
+record_richcompare(PyObject *v, PyObject *w, int op)
+{
+    Py_ssize_t i;
+    Py_ssize_t vlen, wlen;
+    int v_is_tuple = 0;
+    int w_is_tuple = 0;
+    int comp;
+
+    if (!ApgRecord_CheckExact(v)) {
+        if (!PyTuple_Check(v)) {
+            Py_RETURN_NOTIMPLEMENTED;
+        }
+        v_is_tuple = 1;
+    }
+
+    if (!ApgRecord_CheckExact(w)) {
+        if (!PyTuple_Check(w)) {
+            Py_RETURN_NOTIMPLEMENTED;
+        }
+        w_is_tuple = 1;
+    }
+
+#define V_ITEM(i) \
+    (v_is_tuple ? (PyTuple_GET_ITEM(v, i)) : (ApgRecord_GET_ITEM(v, i)))
+#define W_ITEM(i) \
+    (w_is_tuple ? (PyTuple_GET_ITEM(w, i)) : (ApgRecord_GET_ITEM(w, i)))
+
+    vlen = Py_SIZE(v);
+    wlen = Py_SIZE(w);
+
+    if (op == Py_EQ && vlen != wlen) {
+        /* Checking if v == w, but len(v) != len(w): return False */
+        Py_RETURN_FALSE;
+    }
+
+    if (op == Py_NE && vlen != wlen) {
+        /* Checking if v != w, and len(v) != len(w): return True */
+        Py_RETURN_TRUE;
+    }
+
+    /* Search for the first index where items are different.
+     * Note that because tuples are immutable, it's safe to reuse
+     * vlen and wlen across the comparison calls.
+     */
+    for (i = 0; i < vlen && i < wlen; i++) {
+        comp = PyObject_RichCompareBool(V_ITEM(i), W_ITEM(i), Py_EQ);
+        if (comp < 0) {
+            return NULL;
+        }
+        if (!comp) {
+            break;
+        }
+    }
+
+    if (i >= vlen || i >= wlen) {
+        /* No more items to compare -- compare sizes */
+        int cmp;
+        switch (op) {
+            case Py_LT: cmp = vlen <  wlen; break;
+            case Py_LE: cmp = vlen <= wlen; break;
+            case Py_EQ: cmp = vlen == wlen; break;
+            case Py_NE: cmp = vlen != wlen; break;
+            case Py_GT: cmp = vlen >  wlen; break;
+            case Py_GE: cmp = vlen >= wlen; break;
+            default: return NULL; /* cannot happen */
+        }
+        if (cmp) {
+            Py_RETURN_TRUE;
+        }
+        else {
+            Py_RETURN_FALSE;
+        }
+    }
+
+    /* We have an item that differs -- shortcuts for EQ/NE */
+    if (op == Py_EQ) {
+        Py_RETURN_FALSE;
+    }
+    if (op == Py_NE) {
+        Py_RETURN_TRUE;
+    }
+
+    /* Compare the final item again using the proper operator */
+    return PyObject_RichCompare(V_ITEM(i), W_ITEM(i), op);
+
+#undef V_ITEM
+#undef W_ITEM
+}
+
+
+static PyObject *
+record_item(ApgRecordObject *o, Py_ssize_t i)
+{
+    if (i < 0 || i >= Py_SIZE(o)) {
+        PyErr_SetString(PyExc_IndexError, "record index out of range");
+        return NULL;
+    }
+    Py_INCREF(o->ob_item[i]);
+    return o->ob_item[i];
+}
+
+
+typedef enum item_by_name_result {
+    APG_ITEM_FOUND = 0,
+    APG_ERROR = -1,
+    APG_ITEM_NOT_FOUND = -2
+} item_by_name_result_t;
+
+
+/* Lookup a record value by its name.  Return 0 on success, -2 if the
+ * value was not found (with KeyError set), and -1 on all other errors.
+ */
+static item_by_name_result_t
+record_item_by_name(ApgRecordObject *o, PyObject *item, PyObject **result)
+{
+    PyObject *mapped;
+    PyObject *val;
+    Py_ssize_t i;
+
+    mapped = PyObject_GetItem(o->desc->mapping, item);
+    if (mapped == NULL) {
+        goto noitem;
+    }
+
+    if (!PyIndex_Check(mapped)) {
+        Py_DECREF(mapped);
+        goto error;
+    }
+
+    i = PyNumber_AsSsize_t(mapped, PyExc_IndexError);
+    Py_DECREF(mapped);
+
+    if (i < 0) {
+        if (PyErr_Occurred())
+            PyErr_Clear();
+        goto error;
+    }
+
+    val = record_item(o, i);
+    if (val == NULL) {
+        PyErr_Clear();
+        goto error;
+    }
+
+    *result = val;
+
+    return APG_ITEM_FOUND;
+
+noitem:
+    PyErr_SetObject(PyExc_KeyError, item);
+    return APG_ITEM_NOT_FOUND;
+
+error:
+    PyErr_SetString(PyExc_RuntimeError, "invalid record descriptor");
+    return APG_ERROR;
+}
+
+
+static PyObject *
+record_subscript(ApgRecordObject* o, PyObject* item)
+{
+    if (PyIndex_Check(item)) {
+        Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
+        if (i == -1 && PyErr_Occurred())
+            return NULL;
+        if (i < 0) {
+            i += Py_SIZE(o);
+        }
+        return record_item(o, i);
+    }
+    else if (PySlice_Check(item)) {
+        Py_ssize_t start, stop, step, slicelength, cur, i;
+        PyObject* result;
+        PyObject* it;
+        PyObject **src, **dest;
+
+        if (PySlice_GetIndicesEx(
+                item,
+                Py_SIZE(o),
+                &start, &stop, &step, &slicelength) < 0)
+        {
+            return NULL;
+        }
+
+        if (slicelength <= 0) {
+            return PyTuple_New(0);
+        }
+        else {
+            result = PyTuple_New(slicelength);
+            if (!result) return NULL;
+
+            src = o->ob_item;
+            dest = ((PyTupleObject *)result)->ob_item;
+            for (cur = start, i = 0; i < slicelength; cur += step, i++) {
+                it = src[cur];
+                Py_INCREF(it);
+                dest[i] = it;
+            }
+
+            return result;
+        }
+    }
+    else {
+        PyObject* result;
+
+        if (record_item_by_name(o, item, &result) < 0)
+            return NULL;
+        else
+            return result;
+    }
+}
+
+
+static PyObject *
+record_repr(ApgRecordObject *v)
+{
+    Py_ssize_t i, n;
+    PyObject *keys_iter;
+    _PyUnicodeWriter writer;
+
+    n = Py_SIZE(v);
+    if (n == 0) {
+        return PyUnicode_FromString("<Record>");
+    }
+
+    keys_iter = PyObject_GetIter(v->desc->keys);
+    if (keys_iter == NULL) {
+        return NULL;
+    }
+
+    i = Py_ReprEnter((PyObject *)v);
+    if (i != 0) {
+        Py_DECREF(keys_iter);
+        return i > 0 ? PyUnicode_FromString("<Record ...>") : NULL;
+    }
+
+    _PyUnicodeWriter_Init(&writer);
+    writer.overallocate = 1;
+    writer.min_length = 12; /* <Record a=1> */
+
+    if (_PyUnicodeWriter_WriteASCIIString(&writer, "<Record ", 8) < 0) {
+        goto error;
+    }
+
+    for (i = 0; i < n; ++i) {
+        PyObject *key;
+        PyObject *key_repr;
+        PyObject *val_repr;
+
+        if (i > 0) {
+            if (_PyUnicodeWriter_WriteChar(&writer, ' ') < 0) {
+                goto error;
+            }
+        }
+
+        if (Py_EnterRecursiveCall(" while getting the repr of a record")) {
+            goto error;
+        }
+        val_repr = PyObject_Repr(v->ob_item[i]);
+        Py_LeaveRecursiveCall();
+        if (val_repr == NULL) {
+            goto error;
+        }
+
+        key = PyIter_Next(keys_iter);
+        if (key == NULL) {
+            Py_DECREF(val_repr);
+            PyErr_SetString(PyExc_RuntimeError, "invalid record mapping");
+            goto error;
+        }
+
+        key_repr = PyObject_Str(key);
+        Py_DECREF(key);
+        if (key_repr == NULL) {
+            Py_DECREF(val_repr);
+            goto error;
+        }
+
+        if (_PyUnicodeWriter_WriteStr(&writer, key_repr) < 0) {
+            Py_DECREF(key_repr);
+            Py_DECREF(val_repr);
+            goto error;
+        }
+        Py_DECREF(key_repr);
+
+        if (_PyUnicodeWriter_WriteChar(&writer, '=') < 0) {
+            Py_DECREF(val_repr);
+            goto error;
+        }
+
+        if (_PyUnicodeWriter_WriteStr(&writer, val_repr) < 0) {
+            Py_DECREF(val_repr);
+            goto error;
+        }
+        Py_DECREF(val_repr);
+    }
+
+    writer.overallocate = 0;
+    if (_PyUnicodeWriter_WriteChar(&writer, '>') < 0) {
+        goto error;
+    }
+
+    Py_DECREF(keys_iter);
+    Py_ReprLeave((PyObject *)v);
+    return _PyUnicodeWriter_Finish(&writer);
+
+error:
+    Py_DECREF(keys_iter);
+    _PyUnicodeWriter_Dealloc(&writer);
+    Py_ReprLeave((PyObject *)v);
+    return NULL;
+}
+
+
+
+static PyObject *
+record_values(PyObject *o, PyObject *args)
+{
+    return record_iter(o);
+}
+
+
+static PyObject *
+record_keys(PyObject *o, PyObject *args)
+{
+    if (!ApgRecord_CheckExact(o)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+
+    return PyObject_GetIter(((ApgRecordObject*)o)->desc->keys);
+}
+
+
+static PyObject *
+record_items(PyObject *o, PyObject *args)
+{
+    if (!ApgRecord_CheckExact(o)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+
+    return record_new_items_iter(o);
+}
+
+
+static int
+record_contains(ApgRecordObject *o, PyObject *arg)
+{
+    if (!ApgRecord_CheckExact(o)) {
+        PyErr_BadInternalCall();
+        return -1;
+    }
+
+    return PySequence_Contains(o->desc->mapping, arg);
+}
+
+
+static PyObject *
+record_get(ApgRecordObject* o, PyObject* args)
+{
+    PyObject *key;
+    PyObject *defval = Py_None;
+    PyObject *val = NULL;
+    int res;
+
+    if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &defval))
+        return NULL;
+
+    res = record_item_by_name(o, key, &val);
+    if (res == APG_ITEM_NOT_FOUND) {
+        PyErr_Clear();
+        Py_INCREF(defval);
+        val = defval;
+    }
+
+    return val;
+}
+
+
+static PySequenceMethods record_as_sequence = {
+    (lenfunc)record_length,                          /* sq_length */
+    0,                                               /* sq_concat */
+    0,                                               /* sq_repeat */
+    (ssizeargfunc)record_item,                       /* sq_item */
+    0,                                               /* sq_slice */
+    0,                                               /* sq_ass_item */
+    0,                                               /* sq_ass_slice */
+    (objobjproc)record_contains,                     /* sq_contains */
+};
+
+
+static PyMappingMethods record_as_mapping = {
+    (lenfunc)record_length,                          /* mp_length */
+    (binaryfunc)record_subscript,                    /* mp_subscript */
+    0                                                /* mp_ass_subscript */
+};
+
+
+static PyMethodDef record_methods[] = {
+    {"values",          (PyCFunction)record_values, METH_NOARGS},
+    {"keys",            (PyCFunction)record_keys, METH_NOARGS},
+    {"items",           (PyCFunction)record_items, METH_NOARGS},
+    {"get",             (PyCFunction)record_get, METH_VARARGS},
+    {NULL,              NULL}           /* sentinel */
+};
+
+
+PyTypeObject ApgRecord_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    .tp_name = "asyncpg.Record",
+    .tp_basicsize = sizeof(ApgRecordObject) - sizeof(PyObject *),
+    .tp_itemsize = sizeof(PyObject *),
+    .tp_dealloc = (destructor)record_dealloc,
+    .tp_repr = (reprfunc)record_repr,
+    .tp_as_sequence = &record_as_sequence,
+    .tp_as_mapping = &record_as_mapping,
+    .tp_hash = (hashfunc)record_hash,
+    .tp_getattro = PyObject_GenericGetAttr,
+    .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
+    .tp_traverse = (traverseproc)record_traverse,
+    .tp_richcompare = record_richcompare,
+    .tp_iter = record_iter,
+    .tp_methods = record_methods,
+    .tp_free = PyObject_GC_Del,
+};
+
+
+/* Record Iterator */
+
+
+typedef struct {
+    PyObject_HEAD
+    Py_ssize_t it_index;
+    ApgRecordObject *it_seq; /* Set to NULL when iterator is exhausted */
+} ApgRecordIterObject;
+
+
+static void
+record_iter_dealloc(ApgRecordIterObject *it)
+{
+    PyObject_GC_UnTrack(it);
+    Py_CLEAR(it->it_seq);
+    PyObject_GC_Del(it);
+}
+
+
+static int
+record_iter_traverse(ApgRecordIterObject *it, visitproc visit, void *arg)
+{
+    Py_VISIT(it->it_seq);
+    return 0;
+}
+
+
+static PyObject *
+record_iter_next(ApgRecordIterObject *it)
+{
+    ApgRecordObject *seq;
+    PyObject *item;
+
+    assert(it != NULL);
+    seq = it->it_seq;
+    if (seq == NULL)
+        return NULL;
+    assert(ApgRecord_CheckExact(seq));
+
+    if (it->it_index < Py_SIZE(seq)) {
+        item = ApgRecord_GET_ITEM(seq, it->it_index);
+        ++it->it_index;
+        Py_INCREF(item);
+        return item;
+    }
+
+    it->it_seq = NULL;
+    Py_DECREF(seq);
+    return NULL;
+}
+
+
+static PyObject *
+record_iter_len(ApgRecordIterObject *it)
+{
+    Py_ssize_t len = 0;
+    if (it->it_seq) {
+        len = Py_SIZE(it->it_seq) - it->it_index;
+    }
+    return PyLong_FromSsize_t(len);
+}
+
+
+PyDoc_STRVAR(record_iter_len_doc,
+             "Private method returning an estimate of len(list(it)).");
+
+
+static PyMethodDef record_iter_methods[] = {
+    {"__length_hint__", (PyCFunction)record_iter_len, METH_NOARGS,
+        record_iter_len_doc},
+    {NULL,              NULL}           /* sentinel */
+};
+
+
+PyTypeObject ApgRecordIter_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    .tp_name = "RecordIterator",
+    .tp_basicsize = sizeof(ApgRecordIterObject),
+    .tp_dealloc = (destructor)record_iter_dealloc,
+    .tp_getattro = PyObject_GenericGetAttr,
+    .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    .tp_traverse = (traverseproc)record_iter_traverse,
+    .tp_iter = PyObject_SelfIter,
+    .tp_iternext = (iternextfunc)record_iter_next,
+    .tp_methods = record_iter_methods,
+};
+
+
+static PyObject *
+record_iter(PyObject *seq)
+{
+    ApgRecordIterObject *it;
+
+    if (!ApgRecord_CheckExact(seq)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+    it = PyObject_GC_New(ApgRecordIterObject, &ApgRecordIter_Type);
+    if (it == NULL)
+        return NULL;
+    it->it_index = 0;
+    Py_INCREF(seq);
+    it->it_seq = (ApgRecordObject *)seq;
+    PyObject_GC_Track(it);
+    return (PyObject *)it;
+}
+
+
+/* Record Items Iterator */
+
+
+typedef struct {
+    PyObject_HEAD
+    Py_ssize_t it_index;
+    PyObject *it_key_iter;
+    ApgRecordObject *it_seq; /* Set to NULL when iterator is exhausted */
+} ApgRecordItemsObject;
+
+
+static void
+record_items_dealloc(ApgRecordItemsObject *it)
+{
+    PyObject_GC_UnTrack(it);
+    Py_CLEAR(it->it_key_iter);
+    Py_CLEAR(it->it_seq);
+    PyObject_GC_Del(it);
+}
+
+
+static int
+record_items_traverse(ApgRecordItemsObject *it, visitproc visit, void *arg)
+{
+    Py_VISIT(it->it_key_iter);
+    Py_VISIT(it->it_seq);
+    return 0;
+}
+
+
+static PyObject *
+record_items_next(ApgRecordItemsObject *it)
+{
+    ApgRecordObject *seq;
+    PyObject *key;
+    PyObject *val;
+    PyObject *tup;
+
+    assert(it != NULL);
+    seq = it->it_seq;
+    if (seq == NULL) {
+        return NULL;
+    }
+    assert(ApgRecord_CheckExact(seq));
+    assert(it->it_key_iter != NULL);
+
+    key = PyIter_Next(it->it_key_iter);
+    if (key == NULL) {
+        /* likely it_key_iter had less items than seq has values */
+        goto exhausted;
+    }
+
+    if (it->it_index < Py_SIZE(seq)) {
+        val = ApgRecord_GET_ITEM(seq, it->it_index);
+        ++it->it_index;
+        Py_INCREF(val);
+    }
+    else {
+        /* it_key_iter had more items than seq has values */
+        Py_DECREF(key);
+        goto exhausted;
+    }
+
+    tup = PyTuple_New(2);
+    if (tup == NULL) {
+        Py_DECREF(val);
+        Py_DECREF(key);
+        goto exhausted;
+    }
+
+    PyTuple_SET_ITEM(tup, 0, key);
+    PyTuple_SET_ITEM(tup, 1, val);
+    return tup;
+
+exhausted:
+    Py_CLEAR(it->it_key_iter);
+    Py_CLEAR(it->it_seq);
+    return NULL;
+}
+
+
+static PyObject *
+record_items_len(ApgRecordItemsObject *it)
+{
+    Py_ssize_t len = 0;
+    if (it->it_seq) {
+        len = Py_SIZE(it->it_seq) - it->it_index;
+    }
+    return PyLong_FromSsize_t(len);
+}
+
+
+PyDoc_STRVAR(record_items_len_doc,
+             "Private method returning an estimate of len(list(it())).");
+
+
+static PyMethodDef record_items_methods[] = {
+    {"__length_hint__", (PyCFunction)record_items_len, METH_NOARGS,
+        record_items_len_doc},
+    {NULL,              NULL}           /* sentinel */
+};
+
+
+PyTypeObject ApgRecordItems_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    .tp_name = "RecordItemsIterator",
+    .tp_basicsize = sizeof(ApgRecordItemsObject),
+    .tp_dealloc = (destructor)record_items_dealloc,
+    .tp_getattro = PyObject_GenericGetAttr,
+    .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    .tp_traverse = (traverseproc)record_items_traverse,
+    .tp_iter = PyObject_SelfIter,
+    .tp_iternext = (iternextfunc)record_items_next,
+    .tp_methods = record_items_methods,
+};
+
+
+static PyObject *
+record_new_items_iter(PyObject *seq)
+{
+    ApgRecordItemsObject *it;
+    PyObject *key_iter;
+
+    if (!ApgRecord_CheckExact(seq)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+
+    key_iter = PyObject_GetIter(((ApgRecordObject*)seq)->desc->keys);
+    if (key_iter == NULL) {
+        return NULL;
+    }
+
+    it = PyObject_GC_New(ApgRecordItemsObject, &ApgRecordItems_Type);
+    if (it == NULL)
+        return NULL;
+
+    it->it_key_iter = key_iter;
+    it->it_index = 0;
+    Py_INCREF(seq);
+    it->it_seq = (ApgRecordObject *)seq;
+    PyObject_GC_Track(it);
+
+    return (PyObject *)it;
+}
+
+
+PyTypeObject *
+ApgRecord_InitTypes(void)
+{
+    if (PyType_Ready(&ApgRecord_Type) < 0) {
+        return NULL;
+    }
+
+    if (PyType_Ready(&ApgRecordDesc_Type) < 0) {
+        return NULL;
+    }
+
+    if (PyType_Ready(&ApgRecordIter_Type) < 0) {
+        return NULL;
+    }
+
+    if (PyType_Ready(&ApgRecordItems_Type) < 0) {
+        return NULL;
+    }
+
+    return &ApgRecord_Type;
+}
+
+
+/* ----------------- */
+
+
+static void
+record_desc_dealloc(ApgRecordDescObject *o)
+{
+    PyObject_GC_UnTrack(o);
+    Py_CLEAR(o->mapping);
+    Py_CLEAR(o->keys);
+    PyObject_GC_Del(o);
+}
+
+
+static int
+record_desc_traverse(ApgRecordDescObject *o, visitproc visit, void *arg)
+{
+    Py_VISIT(o->mapping);
+    Py_VISIT(o->keys);
+    return 0;
+}
+
+
+PyTypeObject ApgRecordDesc_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    .tp_name = "RecordDescriptor",
+    .tp_basicsize = sizeof(ApgRecordDescObject),
+    .tp_dealloc = (destructor)record_desc_dealloc,
+    .tp_getattro = PyObject_GenericGetAttr,
+    .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    .tp_traverse = (traverseproc)record_desc_traverse,
+    .tp_iter = PyObject_SelfIter,
+};
+
+
+PyObject *
+ApgRecordDesc_New(PyObject *mapping, PyObject *keys)
+{
+    ApgRecordDescObject *o;
+
+    if (!mapping || !keys || !PyTuple_CheckExact(keys)) {
+        PyErr_BadInternalCall();
+        return NULL;
+    }
+
+    o = PyObject_GC_New(ApgRecordDescObject, &ApgRecordDesc_Type);
+    if (o == NULL) {
+        return NULL;
+    }
+
+    Py_INCREF(mapping);
+    o->mapping = mapping;
+
+    Py_INCREF(keys);
+    o->keys = keys;
+
+    PyObject_GC_Track(o);
+    return (PyObject *) o;
+}
diff --git a/asyncpg/protocol/record/recordobj.h b/asyncpg/protocol/record/recordobj.h
new file mode 100644 (file)
index 0000000..d329f57
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef APG_RECORDOBJ_H
+#define APG_RECORDOBJ_H
+
+#include "Python.h"
+
+
+/* Largest record to save on free list */
+#define ApgRecord_MAXSAVESIZE 20
+
+/* Maximum number of records of each size to save */
+#define ApgRecord_MAXFREELIST 2000
+
+
+typedef struct {
+    PyObject_HEAD
+    PyObject *mapping;
+    PyObject *keys;
+} ApgRecordDescObject;
+
+
+typedef struct {
+    PyObject_VAR_HEAD
+    Py_hash_t self_hash;
+    ApgRecordDescObject *desc;
+    PyObject *ob_item[1];
+
+    /* ob_item contains space for 'ob_size' elements.
+     * Items must normally not be NULL, except during construction when
+     * the record is not yet visible outside the function that builds it.
+     */
+} ApgRecordObject;
+
+
+extern PyTypeObject ApgRecord_Type;
+extern PyTypeObject ApgRecordIter_Type;
+extern PyTypeObject ApgRecordItems_Type;
+
+extern PyTypeObject ApgRecordDesc_Type;
+
+#define ApgRecord_CheckExact(o) (Py_TYPE(o) == &ApgRecord_Type)
+#define ApgRecordDesc_CheckExact(o) (Py_TYPE(o) == &ApgRecordDesc_Type)
+
+#define ApgRecord_SET_ITEM(op, i, v) \
+                       (((ApgRecordObject *)(op))->ob_item[i] = v)
+#define ApgRecord_GET_ITEM(op, i) \
+                       (((ApgRecordObject *)(op))->ob_item[i])
+
+PyTypeObject *ApgRecord_InitTypes(void);
+PyObject *ApgRecord_New(PyObject *, Py_ssize_t);
+PyObject *ApgRecordDesc_New(PyObject *, PyObject *);
+
+#endif
diff --git a/asyncpg/protocol/settings.pxd b/asyncpg/protocol/settings.pxd
new file mode 100644 (file)
index 0000000..44b673c
--- /dev/null
@@ -0,0 +1,29 @@
+# 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 class ConnectionSettings(pgproto.CodecContext):
+    cdef:
+        str _encoding
+        object _codec
+        dict _settings
+        bint _is_utf8
+        DataCodecConfig _data_codecs
+
+    cdef add_setting(self, str name, str val)
+    cdef is_encoding_utf8(self)
+    cpdef get_text_codec(self)
+    cpdef inline register_data_types(self, types)
+    cpdef inline add_python_codec(
+        self, typeoid, typename, typeschema, typekind, encoder,
+        decoder, format)
+    cpdef inline remove_python_codec(
+        self, typeoid, typename, typeschema)
+    cpdef inline clear_type_cache(self)
+    cpdef inline set_builtin_type_codec(
+        self, typeoid, typename, typeschema, typekind, alias_to, format)
+    cpdef inline Codec get_data_codec(
+        self, uint32_t oid, ServerDataFormat format=*)
diff --git a/asyncpg/protocol/settings.pyx b/asyncpg/protocol/settings.pyx
new file mode 100644 (file)
index 0000000..2ea7216
--- /dev/null
@@ -0,0 +1,109 @@
+# 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
+
+
+from asyncpg import exceptions
+
+
+@cython.final
+cdef class ConnectionSettings(pgproto.CodecContext):
+
+    def __cinit__(self, conn_key):
+        self._encoding = 'utf-8'
+        self._is_utf8 = True
+        self._settings = {}
+        self._codec = codecs.lookup('utf-8')
+        self._data_codecs = DataCodecConfig(conn_key)
+
+    cdef add_setting(self, str name, str val):
+        self._settings[name] = val
+        if name == 'client_encoding':
+            py_enc = get_python_encoding(val)
+            self._codec = codecs.lookup(py_enc)
+            self._encoding = self._codec.name
+            self._is_utf8 = self._encoding == 'utf-8'
+
+    cdef is_encoding_utf8(self):
+        return self._is_utf8
+
+    cpdef get_text_codec(self):
+        return self._codec
+
+    cpdef inline register_data_types(self, types):
+        self._data_codecs.add_types(types)
+
+    cpdef inline add_python_codec(self, typeoid, typename, typeschema,
+                                  typekind, encoder, decoder, format):
+        cdef:
+            ServerDataFormat _format
+            ClientExchangeFormat xformat
+
+        if format == 'binary':
+            _format = PG_FORMAT_BINARY
+            xformat = PG_XFORMAT_OBJECT
+        elif format == 'text':
+            _format = PG_FORMAT_TEXT
+            xformat = PG_XFORMAT_OBJECT
+        elif format == 'tuple':
+            _format = PG_FORMAT_ANY
+            xformat = PG_XFORMAT_TUPLE
+        else:
+            raise exceptions.InterfaceError(
+                'invalid `format` argument, expected {}, got {!r}'.format(
+                    "'text', 'binary' or 'tuple'", format
+                ))
+
+        self._data_codecs.add_python_codec(typeoid, typename, typeschema,
+                                           typekind, encoder, decoder,
+                                           _format, xformat)
+
+    cpdef inline remove_python_codec(self, typeoid, typename, typeschema):
+        self._data_codecs.remove_python_codec(typeoid, typename, typeschema)
+
+    cpdef inline clear_type_cache(self):
+        self._data_codecs.clear_type_cache()
+
+    cpdef inline set_builtin_type_codec(self, typeoid, typename, typeschema,
+                                        typekind, alias_to, format):
+        cdef:
+            ServerDataFormat _format
+
+        if format is None:
+            _format = PG_FORMAT_ANY
+        elif format == 'binary':
+            _format = PG_FORMAT_BINARY
+        elif format == 'text':
+            _format = PG_FORMAT_TEXT
+        else:
+            raise exceptions.InterfaceError(
+                'invalid `format` argument, expected {}, got {!r}'.format(
+                    "'text' or 'binary'", format
+                ))
+
+        self._data_codecs.set_builtin_type_codec(typeoid, typename, typeschema,
+                                                 typekind, alias_to, _format)
+
+    cpdef inline Codec get_data_codec(self, uint32_t oid,
+                                      ServerDataFormat format=PG_FORMAT_ANY):
+        if format == PG_FORMAT_ANY:
+            codec = self._data_codecs.get_codec(oid, PG_FORMAT_BINARY)
+            if codec is None:
+                codec = self._data_codecs.get_codec(oid, PG_FORMAT_TEXT)
+            return codec
+        else:
+            return self._data_codecs.get_codec(oid, format)
+
+    def __getattr__(self, name):
+        if not name.startswith('_'):
+            try:
+                return self._settings[name]
+            except KeyError:
+                raise AttributeError(name) from None
+
+        return object.__getattr__(self, name)
+
+    def __repr__(self):
+        return '<ConnectionSettings {!r}>'.format(self._settings)
diff --git a/asyncpg/serverversion.py b/asyncpg/serverversion.py
new file mode 100644 (file)
index 0000000..6b2d28c
--- /dev/null
@@ -0,0 +1,57 @@
+# 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
+
+
+from . import types
+
+
+def split_server_version_string(version_string):
+    version_string = version_string.strip()
+    if version_string.startswith('PostgreSQL '):
+        version_string = version_string[len('PostgreSQL '):]
+    if version_string.startswith('Postgres-XL'):
+        version_string = version_string[len('Postgres-XL '):]
+
+    # Some distros (e.g Debian) like may inject their branding
+    # into the numeric version string, so make sure to only look
+    # at stuff before the first space.
+    version_string = version_string.split(' ')[0]
+    parts = version_string.strip().split('.')
+    if not parts[-1].isdigit():
+        # release level specified
+        lastitem = parts[-1]
+        levelpart = lastitem.rstrip('0123456789').lower()
+        if levelpart != lastitem:
+            serial = int(lastitem[len(levelpart):])
+        else:
+            serial = 0
+
+        level = levelpart.lstrip('0123456789')
+        if level != levelpart:
+            parts[-1] = levelpart[:-len(level)]
+        else:
+            parts[-1] = 0
+    else:
+        level = 'final'
+        serial = 0
+
+    if int(parts[0]) >= 10:
+        # Since PostgreSQL 10 the versioning scheme has changed.
+        # 10.x really means 10.0.x.  While parsing 10.1
+        # as (10, 1) may seem less confusing, in practice most
+        # version checks are written as version[:2], and we
+        # want to keep that behaviour consistent, i.e not fail
+        # a major version check due to a bugfix release.
+        parts.insert(1, 0)
+
+    versions = [int(p) for p in parts][:3]
+    if len(versions) < 3:
+        versions += [0] * (3 - len(versions))
+
+    versions.append(level)
+    versions.append(serial)
+
+    return types.ServerVersion(*versions)
diff --git a/asyncpg/transaction.py b/asyncpg/transaction.py
new file mode 100644 (file)
index 0000000..55768c4
--- /dev/null
@@ -0,0 +1,237 @@
+# 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
+
+
+import enum
+
+from . import connresource
+from . import exceptions as apg_errors
+
+
+class TransactionState(enum.Enum):
+    NEW = 0
+    STARTED = 1
+    COMMITTED = 2
+    ROLLEDBACK = 3
+    FAILED = 4
+
+
+ISOLATION_LEVELS = {'read_committed', 'serializable', 'repeatable_read'}
+
+
+class Transaction(connresource.ConnectionResource):
+    """Represents a transaction or savepoint block.
+
+    Transactions are created by calling the
+    :meth:`Connection.transaction() <connection.Connection.transaction>`
+    function.
+    """
+
+    __slots__ = ('_connection', '_isolation', '_readonly', '_deferrable',
+                 '_state', '_nested', '_id', '_managed')
+
+    def __init__(self, connection, isolation, readonly, deferrable):
+        super().__init__(connection)
+
+        if isolation not in ISOLATION_LEVELS:
+            raise ValueError(
+                'isolation is expected to be either of {}, '
+                'got {!r}'.format(ISOLATION_LEVELS, isolation))
+
+        if isolation != 'serializable':
+            if readonly:
+                raise ValueError(
+                    '"readonly" is only supported for '
+                    'serializable transactions')
+
+            if deferrable and not readonly:
+                raise ValueError(
+                    '"deferrable" is only supported for '
+                    'serializable readonly transactions')
+
+        self._isolation = isolation
+        self._readonly = readonly
+        self._deferrable = deferrable
+        self._state = TransactionState.NEW
+        self._nested = False
+        self._id = None
+        self._managed = False
+
+    async def __aenter__(self):
+        if self._managed:
+            raise apg_errors.InterfaceError(
+                'cannot enter context: already in an `async with` block')
+        self._managed = True
+        await self.start()
+
+    async def __aexit__(self, extype, ex, tb):
+        try:
+            self._check_conn_validity('__aexit__')
+        except apg_errors.InterfaceError:
+            if extype is GeneratorExit:
+                # When a PoolAcquireContext is being exited, and there
+                # is an open transaction in an async generator that has
+                # not been iterated fully, there is a possibility that
+                # Pool.release() would race with this __aexit__(), since
+                # both would be in concurrent tasks.  In such case we
+                # yield to Pool.release() to do the ROLLBACK for us.
+                # See https://github.com/MagicStack/asyncpg/issues/232
+                # for an example.
+                return
+            else:
+                raise
+
+        try:
+            if extype is not None:
+                await self.__rollback()
+            else:
+                await self.__commit()
+        finally:
+            self._managed = False
+
+    @connresource.guarded
+    async def start(self):
+        """Enter the transaction or savepoint block."""
+        self.__check_state_base('start')
+        if self._state is TransactionState.STARTED:
+            raise apg_errors.InterfaceError(
+                'cannot start; the transaction is already started')
+
+        con = self._connection
+
+        if con._top_xact is None:
+            if con._protocol.is_in_transaction():
+                raise apg_errors.InterfaceError(
+                    'cannot use Connection.transaction() in '
+                    'a manually started transaction')
+            con._top_xact = self
+        else:
+            # Nested transaction block
+            top_xact = con._top_xact
+            if self._isolation != top_xact._isolation:
+                raise apg_errors.InterfaceError(
+                    'nested transaction has a different isolation level: '
+                    'current {!r} != outer {!r}'.format(
+                        self._isolation, top_xact._isolation))
+            self._nested = True
+
+        if self._nested:
+            self._id = con._get_unique_id('savepoint')
+            query = 'SAVEPOINT {};'.format(self._id)
+        else:
+            if self._isolation == 'read_committed':
+                query = 'BEGIN;'
+            elif self._isolation == 'repeatable_read':
+                query = 'BEGIN ISOLATION LEVEL REPEATABLE READ;'
+            else:
+                query = 'BEGIN ISOLATION LEVEL SERIALIZABLE'
+                if self._readonly:
+                    query += ' READ ONLY'
+                if self._deferrable:
+                    query += ' DEFERRABLE'
+                query += ';'
+
+        try:
+            await self._connection.execute(query)
+        except BaseException:
+            self._state = TransactionState.FAILED
+            raise
+        else:
+            self._state = TransactionState.STARTED
+
+    def __check_state_base(self, opname):
+        if self._state is TransactionState.COMMITTED:
+            raise apg_errors.InterfaceError(
+                'cannot {}; the transaction is already committed'.format(
+                    opname))
+        if self._state is TransactionState.ROLLEDBACK:
+            raise apg_errors.InterfaceError(
+                'cannot {}; the transaction is already rolled back'.format(
+                    opname))
+        if self._state is TransactionState.FAILED:
+            raise apg_errors.InterfaceError(
+                'cannot {}; the transaction is in error state'.format(
+                    opname))
+
+    def __check_state(self, opname):
+        if self._state is not TransactionState.STARTED:
+            if self._state is TransactionState.NEW:
+                raise apg_errors.InterfaceError(
+                    'cannot {}; the transaction is not yet started'.format(
+                        opname))
+            self.__check_state_base(opname)
+
+    async def __commit(self):
+        self.__check_state('commit')
+
+        if self._connection._top_xact is self:
+            self._connection._top_xact = None
+
+        if self._nested:
+            query = 'RELEASE SAVEPOINT {};'.format(self._id)
+        else:
+            query = 'COMMIT;'
+
+        try:
+            await self._connection.execute(query)
+        except BaseException:
+            self._state = TransactionState.FAILED
+            raise
+        else:
+            self._state = TransactionState.COMMITTED
+
+    async def __rollback(self):
+        self.__check_state('rollback')
+
+        if self._connection._top_xact is self:
+            self._connection._top_xact = None
+
+        if self._nested:
+            query = 'ROLLBACK TO {};'.format(self._id)
+        else:
+            query = 'ROLLBACK;'
+
+        try:
+            await self._connection.execute(query)
+        except BaseException:
+            self._state = TransactionState.FAILED
+            raise
+        else:
+            self._state = TransactionState.ROLLEDBACK
+
+    @connresource.guarded
+    async def commit(self):
+        """Exit the transaction or savepoint block and commit changes."""
+        if self._managed:
+            raise apg_errors.InterfaceError(
+                'cannot manually commit from within an `async with` block')
+        await self.__commit()
+
+    @connresource.guarded
+    async def rollback(self):
+        """Exit the transaction or savepoint block and rollback changes."""
+        if self._managed:
+            raise apg_errors.InterfaceError(
+                'cannot manually rollback from within an `async with` block')
+        await self.__rollback()
+
+    def __repr__(self):
+        attrs = []
+        attrs.append('state:{}'.format(self._state.name.lower()))
+
+        attrs.append(self._isolation)
+        if self._readonly:
+            attrs.append('readonly')
+        if self._deferrable:
+            attrs.append('deferrable')
+
+        if self.__class__.__module__.startswith('asyncpg.'):
+            mod = 'asyncpg'
+        else:
+            mod = self.__class__.__module__
+
+        return '<{}.{} {} {:#x}>'.format(
+            mod, self.__class__.__name__, ' '.join(attrs), id(self))
diff --git a/asyncpg/types.py b/asyncpg/types.py
new file mode 100644 (file)
index 0000000..5124718
--- /dev/null
@@ -0,0 +1,144 @@
+# 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
+
+
+import collections
+
+from asyncpg.pgproto.types import (
+    BitString, Point, Path, Polygon,
+    Box, Line, LineSegment, Circle,
+)
+
+
+__all__ = (
+    'Type', 'Attribute', 'Range', 'BitString', 'Point', 'Path', 'Polygon',
+    'Box', 'Line', 'LineSegment', 'Circle', 'ServerVersion',
+)
+
+
+Type = collections.namedtuple('Type', ['oid', 'name', 'kind', 'schema'])
+Type.__doc__ = 'Database data type.'
+Type.oid.__doc__ = 'OID of the type.'
+Type.name.__doc__ = 'Type name.  For example "int2".'
+Type.kind.__doc__ = \
+    'Type kind.  Can be "scalar", "array", "composite" or "range".'
+Type.schema.__doc__ = 'Name of the database schema that defines the type.'
+
+
+Attribute = collections.namedtuple('Attribute', ['name', 'type'])
+Attribute.__doc__ = 'Database relation attribute.'
+Attribute.name.__doc__ = 'Attribute name.'
+Attribute.type.__doc__ = 'Attribute data type :class:`asyncpg.types.Type`.'
+
+
+ServerVersion = collections.namedtuple(
+    'ServerVersion', ['major', 'minor', 'micro', 'releaselevel', 'serial'])
+ServerVersion.__doc__ = 'PostgreSQL server version tuple.'
+
+
+class Range:
+    """Immutable representation of PostgreSQL `range` type."""
+
+    __slots__ = '_lower', '_upper', '_lower_inc', '_upper_inc', '_empty'
+
+    def __init__(self, lower=None, upper=None, *,
+                 lower_inc=True, upper_inc=False,
+                 empty=False):
+        self._empty = empty
+        if empty:
+            self._lower = self._upper = None
+            self._lower_inc = self._upper_inc = False
+        else:
+            self._lower = lower
+            self._upper = upper
+            self._lower_inc = lower is not None and lower_inc
+            self._upper_inc = upper is not None and upper_inc
+
+    @property
+    def lower(self):
+        return self._lower
+
+    @property
+    def lower_inc(self):
+        return self._lower_inc
+
+    @property
+    def lower_inf(self):
+        return self._lower is None and not self._empty
+
+    @property
+    def upper(self):
+        return self._upper
+
+    @property
+    def upper_inc(self):
+        return self._upper_inc
+
+    @property
+    def upper_inf(self):
+        return self._upper is None and not self._empty
+
+    @property
+    def isempty(self):
+        return self._empty
+
+    def __bool__(self):
+        return not self._empty
+
+    def __eq__(self, other):
+        if not isinstance(other, Range):
+            return NotImplemented
+
+        return (
+            self._lower,
+            self._upper,
+            self._lower_inc,
+            self._upper_inc,
+            self._empty
+        ) == (
+            other._lower,
+            other._upper,
+            other._lower_inc,
+            other._upper_inc,
+            other._empty
+        )
+
+    def __hash__(self):
+        return hash((
+            self._lower,
+            self._upper,
+            self._lower_inc,
+            self._upper_inc,
+            self._empty
+        ))
+
+    def __repr__(self):
+        if self._empty:
+            desc = 'empty'
+        else:
+            if self._lower is None or not self._lower_inc:
+                lb = '('
+            else:
+                lb = '['
+
+            if self._lower is not None:
+                lb += repr(self._lower)
+
+            if self._upper is not None:
+                ub = repr(self._upper)
+            else:
+                ub = ''
+
+            if self._upper is None or not self._upper_inc:
+                ub += ')'
+            else:
+                ub += ']'
+
+            desc = '{}, {}'.format(lb, ub)
+
+        return '<Range {}>'.format(desc)
+
+    __str__ = __repr__
diff --git a/asyncpg/utils.py b/asyncpg/utils.py
new file mode 100644 (file)
index 0000000..3940e04
--- /dev/null
@@ -0,0 +1,45 @@
+# Copyright (C) 2016-present the ayncpg 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
+
+
+import re
+
+
+def _quote_ident(ident):
+    return '"{}"'.format(ident.replace('"', '""'))
+
+
+def _quote_literal(string):
+    return "'{}'".format(string.replace("'", "''"))
+
+
+async def _mogrify(conn, query, args):
+    """Safely inline arguments to query text."""
+    # Introspect the target query for argument types and
+    # build a list of safely-quoted fully-qualified type names.
+    ps = await conn.prepare(query)
+    paramtypes = []
+    for t in ps.get_parameters():
+        if t.name.endswith('[]'):
+            pname = '_' + t.name[:-2]
+        else:
+            pname = t.name
+
+        paramtypes.append('{}.{}'.format(
+            _quote_ident(t.schema), _quote_ident(pname)))
+    del ps
+
+    # Use Postgres to convert arguments to text representation
+    # by casting each value to text.
+    cols = ['quote_literal(${}::{}::text)'.format(i, t)
+            for i, t in enumerate(paramtypes, start=1)]
+
+    textified = await conn.fetchrow(
+        'SELECT {cols}'.format(cols=', '.join(cols)), *args)
+
+    # Finally, replace $n references with text values.
+    return re.sub(
+        r'\$(\d+)\b', lambda m: textified[int(m.group(1)) - 1], query)
diff --git a/docs/api/index.rst b/docs/api/index.rst
new file mode 100644 (file)
index 0000000..d63ab8d
--- /dev/null
@@ -0,0 +1,346 @@
+.. _asyncpg-api-reference:
+
+=============
+API Reference
+=============
+
+.. module:: asyncpg
+    :synopsis: A fast PostgreSQL Database Client Library for Python/asyncio
+
+.. currentmodule:: asyncpg
+
+
+.. _asyncpg-api-connection:
+
+Connection
+==========
+
+.. autofunction:: asyncpg.connection.connect
+
+
+.. autoclass:: asyncpg.connection.Connection
+   :members:
+
+
+.. _asyncpg-api-prepared-stmt:
+
+Prepared Statements
+===================
+
+Prepared statements are a PostgreSQL feature that can be used to optimize the
+performance of queries that are executed more than once.  When a query
+is *prepared* by a call to :meth:`Connection.prepare`, the server parses,
+analyzes and compiles the query allowing to reuse that work once there is
+a need to run the same query again.
+
+.. code-block:: pycon
+
+   >>> import asyncpg, asyncio
+   >>> loop = asyncio.get_event_loop()
+   >>> async def run():
+   ...     conn = await asyncpg.connect()
+   ...     stmt = await conn.prepare('''SELECT 2 ^ $1''')
+   ...     print(await stmt.fetchval(10))
+   ...     print(await stmt.fetchval(20))
+   ...
+   >>> loop.run_until_complete(run())
+   1024.0
+   1048576.0
+
+.. note::
+
+   asyncpg automatically maintains a small LRU cache for queries executed
+   during calls to the :meth:`~Connection.fetch`, :meth:`~Connection.fetchrow`,
+   or :meth:`~Connection.fetchval` methods.
+
+.. warning::
+
+   If you are using pgbouncer with ``pool_mode`` set to ``transaction`` or
+   ``statement``, prepared statements will not work correctly.  See
+   :ref:`asyncpg-prepared-stmt-errors` for more information.
+
+
+.. autoclass:: asyncpg.prepared_stmt.PreparedStatement()
+   :members:
+
+
+.. _asyncpg-api-transaction:
+
+Transactions
+============
+
+The most common way to use transactions is through an ``async with`` statement:
+
+.. code-block:: python
+
+   async with connection.transaction():
+       await connection.execute("INSERT INTO mytable VALUES(1, 2, 3)")
+
+
+asyncpg supports nested transactions (a nested transaction context will create
+a `savepoint`_.):
+
+.. code-block:: python
+
+   async with connection.transaction():
+       await connection.execute('CREATE TABLE mytab (a int)')
+
+       try:
+           # Create a nested transaction:
+           async with connection.transaction():
+               await connection.execute('INSERT INTO mytab (a) VALUES (1), (2)')
+               # This nested transaction will be automatically rolled back:
+               raise Exception
+       except:
+           # Ignore exception
+           pass
+
+       # Because the nested transaction was rolled back, there
+       # will be nothing in `mytab`.
+       assert await connection.fetch('SELECT a FROM mytab') == []
+
+Alternatively, transactions can be used without an ``async with`` block:
+
+.. code-block:: python
+
+    tr = connection.transaction()
+    await tr.start()
+    try:
+        ...
+    except:
+        await tr.rollback()
+        raise
+    else:
+        await tr.commit()
+
+
+See also the
+:meth:`Connection.transaction() <asyncpg.connection.Connection.transaction>`
+function.
+
+.. _savepoint: https://www.postgresql.org/docs/current/static/sql-savepoint.html
+
+
+.. autoclass:: asyncpg.transaction.Transaction()
+   :members:
+
+   .. describe:: async with c:
+
+      start and commit/rollback the transaction or savepoint block
+      automatically when entering and exiting the code inside the
+      context manager block.
+
+
+.. _asyncpg-api-cursor:
+
+Cursors
+=======
+
+Cursors are useful when there is a need to iterate over the results of
+a large query without fetching all rows at once.  The cursor interface
+provided by asyncpg supports *asynchronous iteration* via the ``async for``
+statement, and also a way to read row chunks and skip forward over the
+result set.
+
+To iterate over a cursor using a connection object use
+:meth:`Connection.cursor() <asyncpg.connection.Connection.cursor>`.
+To make the iteration efficient, the cursor will prefetch records to
+reduce the number of queries sent to the server:
+
+.. code-block:: python
+
+    async def iterate(con: Connection):
+        async with con.transaction():
+            # Postgres requires non-scrollable cursors to be created
+            # and used in a transaction.
+            async for record in con.cursor('SELECT generate_series(0, 100)'):
+                print(record)
+
+Or, alternatively, you can iterate over the cursor manually (cursor
+won't be prefetching any rows):
+
+.. code-block:: python
+
+    async def iterate(con: Connection):
+        async with con.transaction():
+            # Postgres requires non-scrollable cursors to be created
+            # and used in a transaction.
+
+            async with con.transaction():
+                # Create a Cursor object
+                cur = await con.cursor('SELECT generate_series(0, 100)')
+
+                # Move the cursor 10 rows forward
+                await cur.forward(10)
+
+                # Fetch one row and print it
+                print(await cur.fetchrow())
+
+                # Fetch a list of 5 rows and print it
+                print(await cur.fetch(5))
+
+It's also possible to create cursors from prepared statements:
+
+.. code-block:: python
+
+    async def iterate(con: Connection):
+        # Create a prepared statement that will accept one argument
+        stmt = await con.prepare('SELECT generate_series(0, $1)')
+
+        async with con.transaction():
+            # Postgres requires non-scrollable cursors to be created
+            # and used in a transaction.
+
+            # Execute the prepared statement passing `10` as the
+            # argument -- that will generate a series or records
+            # from 0..10.  Iterate over all of them and print every
+            # record.
+            async for record in stmt.cursor(10):
+                print(record)
+
+
+.. note::
+
+   Cursors created by a call to
+   :meth:`Connection.cursor() <asyncpg.connection.Connection.cursor>` or
+   :meth:`PreparedStatement.cursor() <asyncpg.prepared_stmt.PreparedStatement.cursor>`
+   are *non-scrollable*: they can only be read forwards.  To create a scrollable
+   cursor, use the ``DECLARE ... SCROLL CURSOR`` SQL statement directly.
+
+.. warning::
+
+   Cursors created by a call to
+   :meth:`Connection.cursor() <asyncpg.connection.Connection.cursor>` or
+   :meth:`PreparedStatement.cursor() <asyncpg.prepared_stmt.PreparedStatement.cursor>`
+   cannot be used outside of a transaction.  Any such attempt will result in
+   :exc:`~asyncpg.exceptions.InterfaceError`.
+
+   To create a cursor usable outside of a transaction, use the
+   ``DECLARE ... CURSOR WITH HOLD`` SQL statement directly.
+
+
+.. autoclass:: asyncpg.cursor.CursorFactory()
+   :members:
+
+   .. describe:: async for row in c
+
+      Execute the statement and iterate over the results asynchronously.
+
+   .. describe:: await c
+
+      Execute the statement and return an instance of
+      :class:`~asyncpg.cursor.Cursor` which can be used to navigate over and
+      fetch subsets of the query results.
+
+
+.. autoclass:: asyncpg.cursor.Cursor()
+   :members:
+
+
+.. _asyncpg-api-pool:
+
+Connection Pools
+================
+
+.. autofunction:: asyncpg.pool.create_pool
+
+
+.. autoclass:: asyncpg.pool.Pool()
+   :members:
+
+
+.. _asyncpg-api-record:
+
+Record Objects
+==============
+
+Each row (or composite type value) returned by calls to ``fetch*`` methods
+is represented by an instance of the :class:`~asyncpg.Record` object.
+``Record`` objects are a tuple-/dict-like hybrid, and allow addressing of
+items either by a numeric index or by a field name:
+
+.. code-block:: pycon
+
+    >>> import asyncpg
+    >>> import asyncio
+    >>> loop = asyncio.get_event_loop()
+    >>> conn = loop.run_until_complete(asyncpg.connect())
+    >>> r = loop.run_until_complete(conn.fetchrow('''
+    ...     SELECT oid, rolname, rolsuper FROM pg_roles WHERE rolname = user'''))
+    >>> r
+    <Record oid=16388 rolname='elvis' rolsuper=True>
+    >>> r['oid']
+    16388
+    >>> r[0]
+    16388
+    >>> dict(r)
+    {'oid': 16388, 'rolname': 'elvis', 'rolsuper': True}
+    >>> tuple(r)
+    (16388, 'elvis', True)
+
+.. note::
+
+   ``Record`` objects currently cannot be created from Python code.
+
+.. class:: Record()
+
+   A read-only representation of PostgreSQL row.
+
+   .. describe:: len(r)
+
+      Return the number of fields in record *r*.
+
+   .. describe:: r[field]
+
+      Return the field of *r* with field name or index *field*.
+
+   .. describe:: name in r
+
+      Return ``True`` if record *r* has a field named *name*.
+
+   .. describe:: iter(r)
+
+      Return an iterator over the *values* of the record *r*.
+
+   .. describe:: get(name[, default])
+
+      Return the value for *name* if the record has a field named *name*,
+      else return *default*. If *default* is not given, return ``None``.
+
+      .. versionadded:: 0.18
+
+   .. method:: values()
+
+      Return an iterator over the record values.
+
+   .. method:: keys()
+
+      Return an iterator over the record field names.
+
+   .. method:: items()
+
+      Return an iterator over ``(field, value)`` pairs.
+
+
+.. class:: ConnectionSettings()
+
+    A read-only collection of Connection settings.
+
+    .. describe:: settings.setting_name
+
+       Return the value of the "setting_name" setting.  Raises an
+       ``AttributeError`` if the setting is not defined.
+
+       Example:
+
+       .. code-block:: pycon
+
+           >>> connection.get_settings().client_encoding
+           'UTF8'
+
+
+Data Types
+==========
+
+.. automodule:: asyncpg.types
+   :members:
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644 (file)
index 0000000..d638d31
--- /dev/null
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+
+import alabaster
+import os
+import sys
+
+sys.path.insert(0, os.path.abspath('..'))
+
+version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),
+                            'asyncpg', '__init__.py')
+
+with open(version_file, 'r') as f:
+    for line in f:
+        if line.startswith('__version__ ='):
+            _, _, version = line.partition('=')
+            version = version.strip(" \n'\"")
+            break
+    else:
+        raise RuntimeError(
+            'unable to read the version from asyncpg/__init__.py')
+
+# -- General configuration ------------------------------------------------
+
+extensions = [
+    'sphinx.ext.autodoc',
+    'sphinx.ext.doctest',
+    'sphinx.ext.viewcode',
+    'sphinx.ext.githubpages',
+    'sphinx.ext.intersphinx',
+    'sphinxcontrib.asyncio',
+]
+
+add_module_names = False
+
+templates_path = ['_templates']
+source_suffix = '.rst'
+master_doc = 'index'
+project = 'asyncpg'
+copyright = '2016-present, the asyncpg authors and contributors'
+author = '<See AUTHORS file>'
+release = version
+language = None
+exclude_patterns = ['_build']
+pygments_style = 'sphinx'
+todo_include_todos = False
+suppress_warnings = ['image.nonlocal_uri']
+
+# -- Options for HTML output ----------------------------------------------
+
+html_theme = 'sphinx_rtd_theme'
+# html_theme_options = {
+#     'description': 'asyncpg is a fast PostgreSQL client library for the '
+#                    'Python asyncio framework',
+#     'show_powered_by': False,
+# }
+html_theme_path = [alabaster.get_path()]
+html_title = 'asyncpg Documentation'
+html_short_title = 'asyncpg'
+html_static_path = ['_static']
+html_sidebars = {
+    '**': [
+        'about.html',
+        'navigation.html',
+    ]
+}
+html_show_sourcelink = False
+html_show_sphinx = False
+html_show_copyright = True
+html_context = {
+    'css_files': [
+        '_static/theme_overrides.css',
+    ],
+}
+htmlhelp_basename = 'asyncpgdoc'
+
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {}
+
+latex_documents = [
+    (master_doc, 'asyncpg.tex', 'asyncpg Documentation',
+     author, 'manual'),
+]
+
+
+# -- Options for manual page output ---------------------------------------
+
+man_pages = [
+    (master_doc, 'asyncpg', 'asyncpg Documentation',
+     [author], 1)
+]
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+texinfo_documents = [
+    (master_doc, 'asyncpg', 'asyncpg Documentation',
+     author, 'asyncpg',
+     'asyncpg is a fast PostgreSQL client library for the '
+     'Python asyncio framework',
+     'Miscellaneous'),
+]
+
+# -- Options for intersphinx ----------------------------------------------
+
+intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
diff --git a/docs/faq.rst b/docs/faq.rst
new file mode 100644 (file)
index 0000000..120b05a
--- /dev/null
@@ -0,0 +1,77 @@
+.. _asyncpg-faq:
+
+
+Frequently Asked Questions
+==========================
+
+Does asyncpg support DB-API?
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+No.  DB-API is a synchronous API, while asyncpg is based
+around an asynchronous I/O model.  Thus, full drop-in compatibility
+with DB-API is not possible and we decided to design asyncpg API
+in a way that is better aligned with PostgreSQL architecture and
+terminology.  We will release a synchronous DB-API-compatible version
+of asyncpg at some point in the future.
+
+
+Can I use asyncpg with SQLAlchemy ORM?
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Short answer: no.  asyncpg uses asynchronous execution model
+and API, which is fundamentally incompatible with SQLAlchemy.
+However, it is possible to use asyncpg and SQLAlchemy Core
+with the help of a third-party adapter, such as asyncpgsa_.
+
+
+Can I use dot-notation with :class:`asyncpg.Record`?  It looks cleaner.
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+We decided against making :class:`asyncpg.Record` a named tuple
+because we want to keep the ``Record`` method namespace separate
+from the column namespace.
+
+
+Why can't I use a :ref:`cursor <asyncpg-api-cursor>` outside of a transaction?
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Cursors created by a call to
+:meth:`Connection.cursor() <asyncpg.connection.Connection.cursor>` or
+:meth:`PreparedStatement.cursor() \
+<asyncpg.prepared_stmt.PreparedStatement.cursor>`
+cannot be used outside of a transaction.  Any such attempt will result in
+``InterfaceError``.
+To create a cursor usable outside of a transaction, use the
+``DECLARE ... CURSOR WITH HOLD`` SQL statement directly.
+
+
+.. _asyncpg-prepared-stmt-errors:
+
+Why am I getting prepared statement errors?
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you are getting intermittent ``prepared statement "__asyncpg_stmt_xx__"
+does not exist`` or ``prepared statement “__asyncpg_stmt_xx__”
+already exists`` errors, you are most likely not connecting to the
+PostgreSQL server directly, but via
+`pgbouncer <https://pgbouncer.github.io/>`_.  pgbouncer, when
+in the ``"transaction"`` or ``"statement"`` pooling mode, does not support
+prepared statements.  You have two options:
+
+* if you are using pgbouncer for connection pooling to a single server,
+  switch to the :ref:`connection pool <asyncpg-connection-pool>`
+  functionality provided by asyncpg, it is a much better option for this
+  purpose;
+
+* if you have no option of avoiding the use of pgbouncer, then you need to
+  switch pgbouncer's ``pool_mode`` to ``session``.
+
+
+Why do I get ``PostgresSyntaxError`` when using ``expression IN $1``?
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``expression IN $1`` is not a valid PostgreSQL syntax.  To check
+a value against a sequence use ``expression = any($1::mytype[])``,
+where ``mytype`` is the array element type.
+
+.. _asyncpgsa: https://github.com/CanopyTax/asyncpgsa
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644 (file)
index 0000000..7058508
--- /dev/null
@@ -0,0 +1,29 @@
+.. image:: https://travis-ci.org/MagicStack/asyncpg.svg?branch=master
+    :target: https://travis-ci.org/MagicStack/asyncpg
+
+.. image:: https://img.shields.io/pypi/status/asyncpg.svg?maxAge=2592000?style=plastic
+    :target: https://pypi.python.org/pypi/asyncpg
+
+
+=======
+asyncpg
+=======
+
+**asyncpg** is a database interface library designed specifically for
+PostgreSQL and Python/asyncio.  asyncpg is an efficient, clean implementation
+of PostgreSQL server binary protocol for use with Python's ``asyncio``
+framework.
+
+**asyncpg** requires Python 3.5 or later and is supported for PostgreSQL
+versions 9.2 to 11.
+
+Contents
+--------
+
+.. toctree::
+   :maxdepth: 2
+
+   installation
+   usage
+   api/index
+   faq
diff --git a/docs/installation.rst b/docs/installation.rst
new file mode 100644 (file)
index 0000000..6166866
--- /dev/null
@@ -0,0 +1,55 @@
+.. _asyncpg-installation:
+
+
+Installation
+============
+
+**asyncpg** has no external dependencies and the recommended way to
+install it is to use **pip**:
+
+.. code-block:: bash
+
+    $ pip install asyncpg
+
+
+.. note::
+
+   It is recommended to use **pip** version **8.1** or later to take
+   advantage of the precompiled wheel packages.  Older versions of pip
+   will ignore the wheel packages and install asyncpg from the source
+   package.  In that case a working C compiler is required.
+
+
+Building from source
+--------------------
+
+If you want to build **asyncpg** from a Git checkout you will need:
+
+  * A working C compiler.
+  * CPython header files.  These can usually be obtained by installing
+    the relevant Python development package: **python3-dev** on Debian/Ubuntu,
+    **python3-devel** on RHEL/Fedora.
+
+Once the above requirements are satisfied, run the following command
+in the root of the source checkout:
+
+.. code-block:: bash
+
+    $ pip install -e .
+
+A debug build containing more runtime checks can be created by setting
+the ``ASYNCPG_DEBUG`` environment variable when building:
+
+.. code-block:: bash
+
+    $ env ASYNCPG_DEBUG=1 pip install -e .
+
+
+Running tests
+-------------
+
+To execute the testsuite run:
+
+.. code-block:: bash
+
+    $ python setup.py test
diff --git a/docs/usage.rst b/docs/usage.rst
new file mode 100644 (file)
index 0000000..e7876c2
--- /dev/null
@@ -0,0 +1,408 @@
+.. _asyncpg-examples:
+
+
+asyncpg Usage
+=============
+
+The interaction with the database normally starts with a call to
+:func:`connect() <asyncpg.connection.connect>`, which establishes
+a new database session and returns a new
+:class:`Connection <asyncpg.connection.Connection>` instance,
+which provides methods to run queries and manage transactions.
+
+
+.. code-block:: python
+
+    import asyncio
+    import asyncpg
+    import datetime
+
+    async def main():
+        # Establish a connection to an existing database named "test"
+        # as a "postgres" user.
+        conn = await asyncpg.connect('postgresql://postgres@localhost/test')
+        # Execute a statement to create a new table.
+        await conn.execute('''
+            CREATE TABLE users(
+                id serial PRIMARY KEY,
+                name text,
+                dob date
+            )
+        ''')
+
+        # Insert a record into the created table.
+        await conn.execute('''
+            INSERT INTO users(name, dob) VALUES($1, $2)
+        ''', 'Bob', datetime.date(1984, 3, 1))
+
+        # Select a row from the table.
+        row = await conn.fetchrow(
+            'SELECT * FROM users WHERE name = $1', 'Bob')
+        # *row* now contains
+        # asyncpg.Record(id=1, name='Bob', dob=datetime.date(1984, 3, 1))
+
+        # Close the connection.
+        await conn.close()
+
+    asyncio.get_event_loop().run_until_complete(main())
+
+
+
+.. note::
+
+   asyncpg uses the native PostgreSQL syntax for query arguments: ``$n``.
+
+
+
+Type Conversion
+---------------
+
+asyncpg automatically converts PostgreSQL types to the corresponding Python
+types and vice versa.  All standard data types are supported out of the box,
+including arrays, composite types, range types, enumerations and any
+combination of them.  It is possible to supply codecs for non-standard
+types or override standard codecs.  See :ref:`asyncpg-custom-codecs` for
+more information.
+
+The table below shows the correspondence between PostgreSQL and Python types.
+
++----------------------+-----------------------------------------------------+
+| PostgreSQL Type      |  Python Type                                        |
++======================+=====================================================+
+| ``anyarray``         | :class:`list <python:list>`                         |
++----------------------+-----------------------------------------------------+
+| ``anyenum``          | :class:`str <python:str>`                           |
++----------------------+-----------------------------------------------------+
+| ``anyrange``         | :class:`asyncpg.Range <asyncpg.types.Range>`        |
++----------------------+-----------------------------------------------------+
+| ``record``           | :class:`asyncpg.Record`,                            |
+|                      | :class:`tuple <python:tuple>`,                      |
+|                      | :class:`Mapping <python:collections.abc.Mapping>`   |
++----------------------+-----------------------------------------------------+
+| ``bit``, ``varbit``  | :class:`asyncpg.BitString <asyncpg.types.BitString>`|
++----------------------+-----------------------------------------------------+
+| ``bool``             | :class:`bool <python:bool>`                         |
++----------------------+-----------------------------------------------------+
+| ``box``              | :class:`asyncpg.Box <asyncpg.types.Box>`            |
++----------------------+-----------------------------------------------------+
+| ``bytea``            | :class:`bytes <python:bytes>`                       |
++----------------------+-----------------------------------------------------+
+| ``char``, ``name``,  | :class:`str <python:str>`                           |
+| ``varchar``,         |                                                     |
+| ``text``,            |                                                     |
+| ``xml``              |                                                     |
++----------------------+-----------------------------------------------------+
+| ``cidr``             | :class:`ipaddress.IPv4Network\                      |
+|                      | <python:ipaddress.IPv4Network>`,                    |
+|                      | :class:`ipaddress.IPv6Network\                      |
+|                      | <python:ipaddress.IPv6Network>`                     |
++----------------------+-----------------------------------------------------+
+| ``inet``             | :class:`ipaddress.IPv4Network\                      |
+|                      | <python:ipaddress.IPv4Network>`,                    |
+|                      | :class:`ipaddress.IPv6Network\                      |
+|                      | <python:ipaddress.IPv6Network>`,                    |
+|                      | :class:`ipaddress.IPv4Address\                      |
+|                      | <python:ipaddress.IPv4Address>`,                    |
+|                      | :class:`ipaddress.IPv6Address\                      |
+|                      | <python:ipaddress.IPv6Address>`                     |
++----------------------+-----------------------------------------------------+
+| ``macaddr``          | :class:`str <python:str>`                           |
++----------------------+-----------------------------------------------------+
+| ``circle``           | :class:`asyncpg.Circle <asyncpg.types.Circle>`      |
++----------------------+-----------------------------------------------------+
+| ``date``             | :class:`datetime.date <python:datetime.date>`       |
++----------------------+-----------------------------------------------------+
+| ``time``             | offset-naïve :class:`datetime.time \                |
+|                      | <python:datetime.time>`                             |
++----------------------+-----------------------------------------------------+
+| ``time with          | offset-aware :class:`datetime.time \                |
+| timezone``           | <python:datetime.time>`                             |
++----------------------+-----------------------------------------------------+
+| ``timestamp``        | offset-naïve :class:`datetime.datetime \            |
+|                      | <python:datetime.datetime>`                         |
++----------------------+-----------------------------------------------------+
+| ``timestamp with     | offset-aware :class:`datetime.datetime \            |
+| timezone``           | <python:datetime.datetime>`                         |
++----------------------+-----------------------------------------------------+
+| ``interval``         | :class:`datetime.timedelta \                        |
+|                      | <python:datetime.timedelta>`                        |
++----------------------+-----------------------------------------------------+
+| ``float``,           | :class:`float <python:float>` [#f1]_                |
+| ``double precision`` |                                                     |
++----------------------+-----------------------------------------------------+
+| ``smallint``,        | :class:`int <python:int>`                           |
+| ``integer``,         |                                                     |
+| ``bigint``           |                                                     |
++----------------------+-----------------------------------------------------+
+| ``numeric``          | :class:`Decimal <python:decimal.Decimal>`           |
++----------------------+-----------------------------------------------------+
+| ``json``, ``jsonb``  | :class:`str <python:str>`                           |
++----------------------+-----------------------------------------------------+
+| ``line``             | :class:`asyncpg.Line <asyncpg.types.Line>`          |
++----------------------+-----------------------------------------------------+
+| ``lseg``             | :class:`asyncpg.LineSegment \                       |
+|                      | <asyncpg.types.LineSegment>`                        |
++----------------------+-----------------------------------------------------+
+| ``money``            | :class:`str <python:str>`                           |
++----------------------+-----------------------------------------------------+
+| ``path``             | :class:`asyncpg.Path <asyncpg.types.Path>`          |
++----------------------+-----------------------------------------------------+
+| ``point``            | :class:`asyncpg.Point <asyncpg.types.Point>`        |
++----------------------+-----------------------------------------------------+
+| ``polygon``          | :class:`asyncpg.Polygon <asyncpg.types.Polygon>`    |
++----------------------+-----------------------------------------------------+
+| ``uuid``             | :class:`uuid.UUID <python:uuid.UUID>`               |
++----------------------+-----------------------------------------------------+
+| ``tid``              | :class:`tuple <python:tuple>`                       |
++----------------------+-----------------------------------------------------+
+
+All other types are encoded and decoded as text by default.
+
+.. [#f1] Inexact single-precision ``float`` values may have a different
+         representation when decoded into a Python float.  This is inherent
+         to the implementation of limited-precision floating point types.
+         If you need the decimal representation to match, cast the expression
+         to ``double`` or ``numeric`` in your query.
+
+.. _asyncpg-custom-codecs:
+
+Custom Type Conversions
+-----------------------
+
+asyncpg allows defining custom type conversion functions both for standard
+and user-defined types using the :meth:`Connection.set_type_codec() \
+<asyncpg.connection.Connection.set_type_codec>` and
+:meth:`Connection.set_builtin_type_codec() \
+<asyncpg.connection.Connection.set_builtin_type_codec>` methods.
+
+
+Example: automatic JSON conversion
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The example below shows how to configure asyncpg to encode and decode
+JSON values using the :mod:`json <python:json>` module.
+
+.. code-block:: python
+
+    import asyncio
+    import asyncpg
+    import json
+
+
+    async def main():
+        conn = await asyncpg.connect()
+
+        try:
+            await conn.set_type_codec(
+                'json',
+                encoder=json.dumps,
+                decoder=json.loads,
+                schema='pg_catalog'
+            )
+
+            data = {'foo': 'bar', 'spam': 1}
+            res = await conn.fetchval('SELECT $1::json', data)
+
+        finally:
+            await conn.close()
+
+    asyncio.get_event_loop().run_until_complete(main())
+
+
+Example: automatic conversion of PostGIS types
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The example below shows how to configure asyncpg to encode and decode
+the PostGIS ``geometry`` type.  It works for any Python object that
+conforms to the `geo interface specification`_ and relies on Shapely_,
+although any library that supports reading and writing the WKB format
+will work.
+
+.. _Shapely: https://github.com/Toblerity/Shapely
+.. _geo interface specification: https://gist.github.com/sgillies/2217756
+
+.. code-block:: python
+
+    import asyncio
+    import asyncpg
+
+    import shapely.geometry
+    import shapely.wkb
+    from shapely.geometry.base import BaseGeometry
+
+
+    async def main():
+        conn = await asyncpg.connect()
+
+        try:
+            def encode_geometry(geometry):
+                if not hasattr(geometry, '__geo_interface__'):
+                    raise TypeError('{g} does not conform to '
+                                    'the geo interface'.format(g=geometry))
+                shape = shapely.geometry.asShape(geometry)
+                return shapely.wkb.dumps(shape)
+
+            def decode_geometry(wkb):
+                return shapely.wkb.loads(wkb)
+
+            await conn.set_type_codec(
+                'geometry',  # also works for 'geography'
+                encoder=encode_geometry,
+                decoder=decode_geometry,
+                format='binary',
+            )
+
+            data = shapely.geometry.Point(-73.985661, 40.748447)
+            res = await conn.fetchrow(
+                '''SELECT 'Empire State Building' AS name,
+                          $1::geometry            AS coordinates
+                ''',
+                data)
+
+            print(res)
+
+        finally:
+            await conn.close()
+
+    asyncio.get_event_loop().run_until_complete(main())
+
+
+Example: decoding numeric columns as floats
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+By default asyncpg decodes numeric columns as Python
+:class:`Decimal <python:decimal.Decimal>` instances.  The example below
+shows how to instruct asyncpg to use floats instead.
+
+.. code-block:: python
+
+    import asyncio
+    import asyncpg
+
+
+    async def main():
+        conn = await asyncpg.connect()
+
+        try:
+            await conn.set_type_codec(
+                'numeric', encoder=str, decoder=float,
+                schema='pg_catalog', format='text'
+            )
+
+            res = await conn.fetchval("SELECT $1::numeric", 11.123)
+            print(res, type(res))
+
+        finally:
+            await conn.close()
+
+    asyncio.get_event_loop().run_until_complete(main())
+
+
+Example: decoding hstore values
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+hstore_ is an extension data type used for storing key/value pairs.
+asyncpg includes a codec to decode and encode hstore values as ``dict``
+objects.  Because ``hstore`` is not a builtin type, the codec must
+be registered on a connection using :meth:`Connection.set_builtin_type_codec()
+<asyncpg.connection.Connection.set_builtin_type_codec>`:
+
+.. code-block:: python
+
+    import asyncpg
+    import asyncio
+
+    async def run():
+        conn = await asyncpg.connect()
+        # Assuming the hstore extension exists in the public schema.
+        await con.set_builtin_type_codec(
+            'hstore', codec_name='pg_contrib.hstore')
+        result = await con.fetchval("SELECT 'a=>1,b=>2'::hstore")
+        assert result == {'a': 1, 'b': 2}
+
+    asyncio.get_event_loop().run_until_complete(run())
+
+.. _hstore: https://www.postgresql.org/docs/current/static/hstore.html
+
+
+Transactions
+------------
+
+To create transactions, the
+:meth:`Connection.transaction() <asyncpg.connection.Connection>` method
+should be used.
+
+The most common way to use transactions is through an ``async with`` statement:
+
+.. code-block:: python
+
+   async with connection.transaction():
+       await connection.execute("INSERT INTO mytable VALUES(1, 2, 3)")
+
+.. note::
+
+   When not in an explicit transaction block, any changes to the database
+   will be applied immediately.  This is also known as *auto-commit*.
+
+See the :ref:`asyncpg-api-transaction` API documentation for more information.
+
+
+.. _asyncpg-connection-pool:
+
+Connection Pools
+----------------
+
+For server-type type applications, that handle frequent requests and need
+the database connection for a short period time while handling a request,
+the use of a connection pool is recommended.  asyncpg provides an advanced
+pool implementation, which eliminates the need to use an external connection
+pooler such as PgBouncer.
+
+To create a connection pool, use the
+:func:`asyncpg.create_pool() <asyncpg.pool.create_pool>` function.
+The resulting :class:`Pool <asyncpg.pool.Pool>` object can then be used
+to borrow connections from the pool.
+
+Below is an example of how **asyncpg** can be used to implement a simple
+Web service that computes the requested power of two.
+
+
+.. code-block:: python
+
+    import asyncio
+    import asyncpg
+    from aiohttp import web
+
+
+    async def handle(request):
+        """Handle incoming requests."""
+        pool = request.app['pool']
+        power = int(request.match_info.get('power', 10))
+
+        # Take a connection from the pool.
+        async with pool.acquire() as connection:
+            # Open a transaction.
+            async with connection.transaction():
+                # Run the query passing the request argument.
+                result = await connection.fetchval('select 2 ^ $1', power)
+                return web.Response(
+                    text="2 ^ {} is {}".format(power, result))
+
+
+    async def init_app():
+        """Initialize the application server."""
+        app = web.Application()
+        # Create a database connection pool
+        app['pool'] = await asyncpg.create_pool(database='postgres',
+                                                user='postgres')
+        # Configure service routes
+        app.router.add_route('GET', '/{power:\d+}', handle)
+        app.router.add_route('GET', '/', handle)
+        return app
+
+
+    loop = asyncio.get_event_loop()
+    app = loop.run_until_complete(init_app())
+    web.run_app(app)
+
+See :ref:`asyncpg-api-pool` API documentation for more information.
diff --git a/performance.png b/performance.png
new file mode 100644 (file)
index 0000000..14f4cd8
Binary files /dev/null and b/performance.png differ
diff --git a/setup.cfg b/setup.cfg
new file mode 100644 (file)
index 0000000..8bfd5a1
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,4 @@
+[egg_info]
+tag_build = 
+tag_date = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..216f026
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,295 @@
+# 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
+
+
+import sys
+
+if sys.version_info < (3, 5):
+    raise RuntimeError('asyncpg requires Python 3.5 or greater')
+
+import os
+import os.path
+import pathlib
+import platform
+import re
+import subprocess
+
+# We use vanilla build_ext, to avoid importing Cython via
+# the setuptools version.
+from distutils import extension as distutils_extension
+from distutils.command import build_ext as distutils_build_ext
+
+import setuptools
+from setuptools.command import build_py as setuptools_build_py
+from setuptools.command import sdist as setuptools_sdist
+
+
+CYTHON_DEPENDENCY = 'Cython==0.29'
+
+# Minimal dependencies required to test asyncpg.
+TEST_DEPENDENCIES = [
+    'flake8~=3.5.0',
+    'uvloop>=0.8.0;platform_system!="Windows"',
+]
+
+# Dependencies required to build documentation.
+DOC_DEPENDENCIES = [
+    'Sphinx~=1.7.3',
+    'sphinxcontrib-asyncio~=0.2.0',
+    'sphinx_rtd_theme~=0.2.4',
+]
+
+EXTRA_DEPENDENCIES = {
+    'docs': DOC_DEPENDENCIES,
+    'test': TEST_DEPENDENCIES,
+    # Dependencies required to develop asyncpg.
+    'dev': [
+        CYTHON_DEPENDENCY,
+        'pytest>=3.6.0',
+    ] + DOC_DEPENDENCIES + TEST_DEPENDENCIES
+}
+
+
+CFLAGS = ['-O2']
+LDFLAGS = []
+
+if platform.uname().system != 'Windows':
+    CFLAGS.extend(['-fsigned-char', '-Wall', '-Wsign-compare', '-Wconversion'])
+
+
+_ROOT = pathlib.Path(__file__).parent
+
+
+with open(str(_ROOT / 'README.rst')) as f:
+    readme = f.read()
+
+
+with open(str(_ROOT / 'asyncpg' / '__init__.py')) as f:
+    for line in f:
+        if line.startswith('__version__ ='):
+            _, _, version = line.partition('=')
+            VERSION = version.strip(" \n'\"")
+            break
+    else:
+        raise RuntimeError(
+            'unable to read the version from asyncpg/__init__.py')
+
+
+if (_ROOT / '.git').is_dir() and 'dev' in VERSION:
+    # This is a git checkout, use git to
+    # generate a precise version.
+    def git_commitish():
+        env = {}
+        v = os.environ.get('PATH')
+        if v is not None:
+            env['PATH'] = v
+
+        git = subprocess.run(['git', 'rev-parse', 'HEAD'], env=env,
+                             cwd=str(_ROOT), stdout=subprocess.PIPE)
+        if git.returncode == 0:
+            commitish = git.stdout.strip().decode('ascii')
+        else:
+            commitish = 'unknown'
+
+        return commitish
+
+    VERSION += '+' + git_commitish()[:7]
+
+
+class VersionMixin:
+
+    def _fix_version(self, filename):
+        # Replace asyncpg.__version__ with the actual version
+        # of the distribution (possibly inferred from git).
+
+        with open(str(filename)) as f:
+            content = f.read()
+
+        version_re = r"(.*__version__\s*=\s*)'[^']+'(.*)"
+        repl = r"\1'{}'\2".format(self.distribution.metadata.version)
+        content = re.sub(version_re, repl, content)
+
+        with open(str(filename), 'w') as f:
+            f.write(content)
+
+
+class sdist(setuptools_sdist.sdist, VersionMixin):
+
+    def make_release_tree(self, base_dir, files):
+        super().make_release_tree(base_dir, files)
+        self._fix_version(pathlib.Path(base_dir) / 'asyncpg' / '__init__.py')
+
+
+class build_py(setuptools_build_py.build_py, VersionMixin):
+
+    def build_module(self, module, module_file, package):
+        outfile, copied = super().build_module(module, module_file, package)
+
+        if module == '__init__' and package == 'asyncpg':
+            self._fix_version(outfile)
+
+        return outfile, copied
+
+
+class build_ext(distutils_build_ext.build_ext):
+
+    user_options = distutils_build_ext.build_ext.user_options + [
+        ('cython-always', None,
+            'run cythonize() even if .c files are present'),
+        ('cython-annotate', None,
+            'Produce a colorized HTML version of the Cython source.'),
+        ('cython-directives=', None,
+            'Cython compiler directives'),
+    ]
+
+    def initialize_options(self):
+        # initialize_options() may be called multiple times on the
+        # same command object, so make sure not to override previously
+        # set options.
+        if getattr(self, '_initialized', False):
+            return
+
+        super(build_ext, self).initialize_options()
+
+        if os.environ.get('ASYNCPG_DEBUG'):
+            self.cython_always = True
+            self.cython_annotate = True
+            self.cython_directives = "linetrace=True"
+            self.define = 'PG_DEBUG,CYTHON_TRACE,CYTHON_TRACE_NOGIL'
+            self.debug = True
+        else:
+            self.cython_always = False
+            self.cython_annotate = None
+            self.cython_directives = None
+
+    def finalize_options(self):
+        # finalize_options() may be called multiple times on the
+        # same command object, so make sure not to override previously
+        # set options.
+        if getattr(self, '_initialized', False):
+            return
+
+        need_cythonize = self.cython_always
+        cfiles = {}
+
+        for extension in self.distribution.ext_modules:
+            for i, sfile in enumerate(extension.sources):
+                if sfile.endswith('.pyx'):
+                    prefix, ext = os.path.splitext(sfile)
+                    cfile = prefix + '.c'
+
+                    if os.path.exists(cfile) and not self.cython_always:
+                        extension.sources[i] = cfile
+                    else:
+                        if os.path.exists(cfile):
+                            cfiles[cfile] = os.path.getmtime(cfile)
+                        else:
+                            cfiles[cfile] = 0
+                        need_cythonize = True
+
+        if need_cythonize:
+            import pkg_resources
+
+            # Double check Cython presence in case setup_requires
+            # didn't go into effect (most likely because someone
+            # imported Cython before setup_requires injected the
+            # correct egg into sys.path.
+            try:
+                import Cython
+            except ImportError:
+                raise RuntimeError(
+                    'please install {} to compile asyncpg from source'.format(
+                        CYTHON_DEPENDENCY))
+
+            cython_dep = pkg_resources.Requirement.parse(CYTHON_DEPENDENCY)
+            if Cython.__version__ not in cython_dep:
+                raise RuntimeError(
+                    'asyncpg requires {}, got Cython=={}'.format(
+                        CYTHON_DEPENDENCY, Cython.__version__
+                    ))
+
+            from Cython.Build import cythonize
+
+            directives = {
+                'language_level': '3',
+            }
+
+            if self.cython_directives:
+                for directive in self.cython_directives.split(','):
+                    k, _, v = directive.partition('=')
+                    if v.lower() == 'false':
+                        v = False
+                    if v.lower() == 'true':
+                        v = True
+
+                    directives[k] = v
+
+            self.distribution.ext_modules[:] = cythonize(
+                self.distribution.ext_modules,
+                compiler_directives=directives,
+                annotate=self.cython_annotate)
+
+        super(build_ext, self).finalize_options()
+
+
+setup_requires = []
+
+if (not (_ROOT / 'asyncpg' / 'protocol' / 'protocol.c').exists() or
+        '--cython-always' in sys.argv):
+    # No Cython output, require Cython to build.
+    setup_requires.append(CYTHON_DEPENDENCY)
+
+
+setuptools.setup(
+    name='asyncpg',
+    version=VERSION,
+    description='An asyncio PosgtreSQL driver',
+    long_description=readme,
+    classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Framework :: AsyncIO',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Apache Software License',
+        'Operating System :: POSIX',
+        'Operating System :: MacOS :: MacOS X',
+        'Operating System :: Microsoft :: Windows',
+        'Programming Language :: Python :: 3 :: Only',
+        'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
+        'Programming Language :: Python :: 3.7',
+        'Programming Language :: Python :: Implementation :: CPython',
+        'Topic :: Database :: Front-Ends',
+    ],
+    platforms=['macOS', 'POSIX', 'Windows'],
+    python_requires='>=3.5.0',
+    zip_safe=False,
+    author='MagicStack Inc',
+    author_email='hello@magic.io',
+    url='https://github.com/MagicStack/asyncpg',
+    license='Apache License, Version 2.0',
+    packages=['asyncpg'],
+    provides=['asyncpg'],
+    include_package_data=True,
+    ext_modules=[
+        distutils_extension.Extension(
+            "asyncpg.pgproto.pgproto",
+            ["asyncpg/pgproto/pgproto.pyx"],
+            extra_compile_args=CFLAGS,
+            extra_link_args=LDFLAGS),
+
+        distutils_extension.Extension(
+            "asyncpg.protocol.protocol",
+            ["asyncpg/protocol/record/recordobj.c",
+             "asyncpg/protocol/protocol.pyx"],
+            include_dirs=['asyncpg/pgproto/'],
+            extra_compile_args=CFLAGS,
+            extra_link_args=LDFLAGS),
+    ],
+    cmdclass={'build_ext': build_ext, 'build_py': build_py, 'sdist': sdist},
+    test_suite='tests.suite',
+    extras_require=EXTRA_DEPENDENCIES,
+    setup_requires=setup_requires,
+)
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644 (file)
index 0000000..6282ebe
--- /dev/null
@@ -0,0 +1,23 @@
+# 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
+
+
+import pathlib
+import sys
+import unittest
+
+
+def suite():
+    test_loader = unittest.TestLoader()
+    test_suite = test_loader.discover(str(pathlib.Path(__file__).parent),
+                                      pattern='test_*.py')
+    return test_suite
+
+
+if __name__ == '__main__':
+    runner = unittest.runner.TextTestRunner()
+    result = runner.run(suite())
+    sys.exit(not result.wasSuccessful())
diff --git a/tests/certs/ca.cert.pem b/tests/certs/ca.cert.pem
new file mode 100644 (file)
index 0000000..0329883
--- /dev/null
@@ -0,0 +1,35 @@
+-----BEGIN CERTIFICATE-----
+MIIGFzCCA/+gAwIBAgIJAPTCST3Z/WinMA0GCSqGSIb3DQEBCwUAMIGhMQswCQYD
+VQQGEwJDQTEQMA4GA1UECAwHT250YXJpbzEQMA4GA1UEBwwHVG9yb250bzEYMBYG
+A1UECgwPTWFnaWNTdGFjayBJbmMuMRYwFAYDVQQLDA1hc3luY3BnIHRlc3RzMR0w
+GwYDVQQDDBRhc3luY3BnIHRlc3Qgcm9vdCBjYTEdMBsGCSqGSIb3DQEJARYOaGVs
+bG9AbWFnaWMuaW8wHhcNMTcwNDAzMTYxMzMwWhcNMzcwMzI5MTYxMzMwWjCBoTEL
+MAkGA1UEBhMCQ0ExEDAOBgNVBAgMB09udGFyaW8xEDAOBgNVBAcMB1Rvcm9udG8x
+GDAWBgNVBAoMD01hZ2ljU3RhY2sgSW5jLjEWMBQGA1UECwwNYXN5bmNwZyB0ZXN0
+czEdMBsGA1UEAwwUYXN5bmNwZyB0ZXN0IHJvb3QgY2ExHTAbBgkqhkiG9w0BCQEW
+DmhlbGxvQG1hZ2ljLmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA
+zxreg1IEqX/g1IFwpNCc9hKa7YYMPk8mo4l+pE4CKXA9cQreaIiDg+l7+pJL3FMa
+a/7cuUsBlVOq/T+9gmjzdWDTHTdq55PQx6co4OlRyPGad2kMwYlAERB6s2jGfuwM
+sS0JJ3VPxUBXwB5ljq18L+HPsZXZhZOl6pBW74dfQE5SJZLTGIX6mbtwR+uQgaow
+1RsMwFAGvwDu8c8+3lmUinGhlHXRJAhbncnlOWmAqa3Yf8rny0JeX7wz5x3vbxnX
+9p9XMaXtV+hQWFHn21nAYjsCnDin6oyC2zUi9ahN5njKu+tUYA+K0ImliTAQNQ39
+m9SZvGNS2uIj/ryYVsI9FjgyJgV6JGcb0q1j2BPUmpPKwHN+sPkdKZy+Z4mVBiel
+mc7X6J9aEXxrvFIjhZOwhYn3RwpwguDFU5qY1Y9wzTg1HMLfQfzWdyInNEi4s96z
+biicisVMnR84syClg2RN56U+0hTJeYKTnYh/xV959EqoFfpUI2GZIxNmHr5p8S3M
+7uSeBxoovmUYadhF9SlKx+dABd/K1HBKfMC4z2iw9z6r4QGOnKoMy0eAn5wzL7wL
++h6znRPm28Qr9NEg8qJ9r1pfF3uhwgZw8hL8iytNfdUIneQVqoHApd33SxHFaO29
+2Nuc19ucySNsMFBIVSg1D5LGjcJYz3NZpleQsIwLhvMCAwEAAaNQME4wHQYDVR0O
+BBYEFOcVk1n/NisD3qXqtpSsWm+pXd0XMB8GA1UdIwQYMBaAFOcVk1n/NisD3qXq
+tpSsWm+pXd0XMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAEFyCFmn
+vc6EjKRld+G8Q1UBRCviNwAvTUyn6LfGFKeimCGlrXEIj08e15oSMVtbWYrs1vWk
+x9JJIJYSbaWJM6eaWmbPYgYzQaiDdWnZb/fXg20gDaFtTamDrqws44yPHgkF8B+k
+fBdkG6w59lGuwz2n8shag4ATDRambJBW1TV+6WAOH2FRQ6Mn/yz4qFGlI/r7yeCJ
+CcQ3KWcrmbqA+GeNCNFyP1CHh+1DXYydVJULZ8hO7TcAkHgKZuHA37N5WGr2Yb+1
+wVH8v2vXpka1wosENU5dMPgtJQ9raEVZEh6HQY81G5/rtUIEuLuHFGkMv9LiuV2/
+FhXGjwyfmDaRADIEH0j0e2NeKk3tLlHb+2cZgKRvwL0a/RkovgUtKN3/ZGHsuPFe
+YTk7RXn3DFpnhVltrg1vRPgR3euKKSVyw/DTPo1sQN205Lgcot+zshUIER/ELZBu
+77AeDK9wbjxG34vdPaNz+bpVpJxZWHyO0CSKpXYwUcdr5iU2VrWJrj4Mnvat9Elo
+BV6lkgdM47ngJ+bS4QpbvZG0YBzaN6mnXEQf3Zw1TkR+31m7vhRKilnObhG+Ylzq
+H6E/a1MVtTRu1FkhTHdHJmolMVSHAytZZnee5PC/1AlMcKdWEv8A5up9sTjGesFM
+ztcZLWC9GiyC/TFSJ1hDylkvvwcCX6PD7fLu
+-----END CERTIFICATE-----
diff --git a/tests/certs/server.cert.pem b/tests/certs/server.cert.pem
new file mode 100644 (file)
index 0000000..ce8bf0f
--- /dev/null
@@ -0,0 +1,40 @@
+-----BEGIN CERTIFICATE-----
+MIIHFjCCBP6gAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgaExCzAJBgNVBAYTAkNB
+MRAwDgYDVQQIDAdPbnRhcmlvMRAwDgYDVQQHDAdUb3JvbnRvMRgwFgYDVQQKDA9N
+YWdpY1N0YWNrIEluYy4xFjAUBgNVBAsMDWFzeW5jcGcgdGVzdHMxHTAbBgNVBAMM
+FGFzeW5jcGcgdGVzdCByb290IGNhMR0wGwYJKoZIhvcNAQkBFg5oZWxsb0BtYWdp
+Yy5pbzAeFw0xNzA0MDMxNjIxMjhaFw0zNzAzMjkxNjIxMjhaMIGEMQswCQYDVQQG
+EwJDQTEQMA4GA1UECAwHT250YXJpbzEYMBYGA1UECgwPTWFnaWNTdGFjayBJbmMu
+MRYwFAYDVQQLDA1hc3luY3BnIHRlc3RzMRIwEAYDVQQDDAlsb2NhbGhvc3QxHTAb
+BgkqhkiG9w0BCQEWDmhlbGxvQG1hZ2ljLmlvMIICIjANBgkqhkiG9w0BAQEFAAOC
+Ag8AMIICCgKCAgEA+0WH9PX4a6Tsnp7xtUbZ51c77aqVagdfj9xYJPqD3X7u2Odf
+yyYivZ91DiS23acfLOEQOfBNn2ZFcrLaXy33UAXo1VcvCsKNJY4FfS9A5OBZ4UTL
+peagrTnZuRS4KMadg0V9jb5au6+s7jExPty9c+nZ59Kd6IbkPn31l9K5rj4/2WvG
+pIj9k5YaXswJVBiTWGKxP9a3xMb9CG9bqNCD5kXo+1K2oDJyGE3mj6QSjlnFw6NN
+f+dCOGWSs7JHMNZVVtRG2qsEIssZgpHseu9he684ZqdqrMCG6wBDW58sUBp6Dt6z
+jyTLefs8ht0tT+ZcmPno2G3mgs1bLyQsQB8a7fqzzaW6wPwdZJBGO/qI7Zr/30VD
+I7InLmxbg62tdrTP4CibXWfe6Qoi6xSNZd7FvP2OoCA7Nk6HahdwDocInB9fWV2j
+jkqyeIdDSd9QUItCUSgyVm+XefO/T8B75PNCykyWAMMDGOBE706KZh4oXeMORoYp
+LxsbtL0/7n/JPwQDHeLQHHRjiw2ydxH2/940jngnL1YCqWiUq06FPvl3zn+Qgim+
+kIhfJeYuQ8zxdh8P7Ay4i5neuum+FQZspPiSzx6jMQIOu+e+iBP2AIdu/UQK+JPU
+epE2Pt5aEyuzgNEbg0cR6tQ3rJCbj0DdtU26ale5EeD8y1JYCXEYkED88bMCAwEA
+AaOCAXEwggFtMAkGA1UdEwQCMAAwEQYJYIZIAYb4QgEBBAQDAgZAMDMGCWCGSAGG
++EIBDQQmFiRPcGVuU1NMIEdlbmVyYXRlZCBTZXJ2ZXIgQ2VydGlmaWNhdGUwHQYD
+VR0OBBYEFHWtuEuKYLSw/iqmyBEyjcSxq0LHMIHWBgNVHSMEgc4wgcuAFOcVk1n/
+NisD3qXqtpSsWm+pXd0XoYGnpIGkMIGhMQswCQYDVQQGEwJDQTEQMA4GA1UECAwH
+T250YXJpbzEQMA4GA1UEBwwHVG9yb250bzEYMBYGA1UECgwPTWFnaWNTdGFjayBJ
+bmMuMRYwFAYDVQQLDA1hc3luY3BnIHRlc3RzMR0wGwYDVQQDDBRhc3luY3BnIHRl
+c3Qgcm9vdCBjYTEdMBsGCSqGSIb3DQEJARYOaGVsbG9AbWFnaWMuaW+CCQD0wkk9
+2f1opzATBgNVHSUEDDAKBggrBgEFBQcDATALBgNVHQ8EBAMCBaAwDQYJKoZIhvcN
+AQELBQADggIBAFUik2de0QH9gjHb0DeNRUpzHf67sVejqJoB0YCAlwhMTCwnMasR
+YQVeD6+L1KCoyynhwZE99B9LlWcL5V/uR++S88azc35mFVJ6j5b0zxT6nTOQE2Oe
+oOZrjhFDmdRQDyZl3oOQZD0CD2VoRZK2uGG1Isv8cC17ImC1bMNHbU+0Sc5twUtj
+jLvyoJNASQess35c+V/w6rdlXy2g19vSiR3nQPsh/HMv2Kx0sJaSIVKTdVBlH3FH
+o+v7tR2YRMxNw4olalxXJzvt1KgbNGczi4Yd/XnTQKCJx4xvJLhE/9R6Cj6vLeFZ
+YpSp1ftXBAQCQn6lv0fMe7az3fmXRJ692514F00zmJUI6EW1wqD4yx2Q8JgqmQ4k
+2oz4HBk/6Sh6Hf43KZAnLUMZ0VvkzhUTTp5/BwlhLjbWQdR6Lrf/8SRdEVzdco6F
+zmawidqeQCASHKbLfFfWbh+A0mzHhkcnvczM803oX1iOnaDQVIYWqZwJxmB+bsB9
+99/yBCxJw1YGIcHss97olsx2HReCVmcUZA3TBBG/WFATYV0DlVdApEPcR6a+NWE/
+W3EhPsZhUdSzjdlP1Yt9awq+V5eHHVA/ve0PufPW6nmxIXXpIuX2YGIRqEmWWSO8
++sKguObZvWZnj/D04GPjJTozy82vebiWGG1NODGO/4vCB0Zp/MbjYQb8
+-----END CERTIFICATE-----
diff --git a/tests/certs/server.key.pem b/tests/certs/server.key.pem
new file mode 100644 (file)
index 0000000..d802fb3
--- /dev/null
@@ -0,0 +1,51 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIJKgIBAAKCAgEA+0WH9PX4a6Tsnp7xtUbZ51c77aqVagdfj9xYJPqD3X7u2Odf
+yyYivZ91DiS23acfLOEQOfBNn2ZFcrLaXy33UAXo1VcvCsKNJY4FfS9A5OBZ4UTL
+peagrTnZuRS4KMadg0V9jb5au6+s7jExPty9c+nZ59Kd6IbkPn31l9K5rj4/2WvG
+pIj9k5YaXswJVBiTWGKxP9a3xMb9CG9bqNCD5kXo+1K2oDJyGE3mj6QSjlnFw6NN
+f+dCOGWSs7JHMNZVVtRG2qsEIssZgpHseu9he684ZqdqrMCG6wBDW58sUBp6Dt6z
+jyTLefs8ht0tT+ZcmPno2G3mgs1bLyQsQB8a7fqzzaW6wPwdZJBGO/qI7Zr/30VD
+I7InLmxbg62tdrTP4CibXWfe6Qoi6xSNZd7FvP2OoCA7Nk6HahdwDocInB9fWV2j
+jkqyeIdDSd9QUItCUSgyVm+XefO/T8B75PNCykyWAMMDGOBE706KZh4oXeMORoYp
+LxsbtL0/7n/JPwQDHeLQHHRjiw2ydxH2/940jngnL1YCqWiUq06FPvl3zn+Qgim+
+kIhfJeYuQ8zxdh8P7Ay4i5neuum+FQZspPiSzx6jMQIOu+e+iBP2AIdu/UQK+JPU
+epE2Pt5aEyuzgNEbg0cR6tQ3rJCbj0DdtU26ale5EeD8y1JYCXEYkED88bMCAwEA
+AQKCAgEAtof0E8b7B3dvTGs6Ou2VLbD5H9VjZPqmOONgRLyXPjgPWhH6TKEPa6CC
+cBvLm4jj5L46A1zFhp3MpV23tJy3o7InSZNj4PUjg7x/0EibY6h2omZPadz3q97y
+grjCbxyZH9tDMcyuLNmZTg7+LyQ7nBCs8vLVMy2KcLsfxYKW0DT4PQFF9BBv5N6N
+mX+u5yBTKUnIaQ+Zv6Ct/4qlkySmLIlsjeWwNP9wUqeEbaRKto4QU+Y1Tky4li9z
+OoavoJKSu9jI/+BryLqxdWB74XIz5p2K40eK/qN9Xwl55PzkO+x/7n1pAvs/tQUF
+GxNg70Hw0k/5DgAIC80SCFTGsG3oKLgPm1BS7Njoz8xcQvtZrYOKfEg/NOjUAWTE
+SvXoLRqTQ4bUS6F6VgSA+qEEXrKFGt+ViddXrfuyXow5ZXjstgwuuZSzjLTM9LPF
+tKEeB+hYbjpg0C7KuRGG5MfQ6eY8TjB3JCBGSBPw/4gv4DzkRoI2e2Qvgon6pNUT
+ZiQMmuQHX3d+5QQErzUgAYF401DBi+9kG6e78hZ5uG3lTUOW372jcAkdkD/DdC1B
+GMt7esIoyrO/57gFQXaFIQjSneWPiaxtYxUqpjbc0lCIfwYr3QFYzumZwUErJljl
+CxDJ2ejW6ONUXDPRbzprHFDi0y71G7WRT7ZmwoQY/q/Yxwg3mAECggEBAP8+cgZl
+001Np3M78KUYuUhDt+6J+ZujJnpCdsWqf0H0cxIA/FL6zpnyYP7nkum/QphE9CST
+jFew1/JnuCtHHzE9BryChjL+kjXswFAhGncsP+UjPI1AEliFhPHIfBF25N3LYBvU
+IO4syLLUsJsWlAaUbXBD29bSRUYwNPkspmblluZaKdS5fJQR9tiEUkNlPeUcjaMl
+Mhblo4r3lZYMkJqm11DGlNUnXb5/kCMq0D+kvhVvoHfRqk5G30m9Yu0QSR6dVlgi
+HiPXodNJSz0BZpfM/FXdnhAYnIANgPZS/St9JjpFeDTvo6vZgF9be+Tt29Zm7gxZ
+4hvoPCUwE5LhKjMCggEBAPwEEssXK3qkrIYRe1gJjxAkpTHWj5w18QNRRsDvNIT3
+Ode2MtloeOl2csIRtvVZWEHWuFiQyvDbVXQvmoeJT+K1acw0mOOkXLME2BLOHTkJ
+bYU5zd+dnF3W3CaOUagpesP7QZYiqdso88EugFDt5KtonFRtp/YNY4HxmEahE2I2
+KGVN6rFV5WIZsJyXhNCvacci1ZnJqwN/43Vx5ejsqjtypi1XAKlYzGj0ktDbOFGR
+vZQdR5Q8rYQ+V7Bypwzbchq9+Udh3Xd8VmosADE0OoATDU6m1SHvsZMxZ83vcs/8
+pkwtzMlzo3q/yPSG+jTU7kq0PE8z628ol5sFZrFMmoECggEATQpHFmFDnvCSWzi7
+UMmemw49hRVGLtDWu042VUE5+elTlhqQDme/Vj4PQsEY2c6txhIB8sxKLumktHjT
+4NQtuQnnb5yh7uBhtz8HaOgk+dV0T7AMBcJSBz/9uZC+yfKt77gEAUJM0jbYOQnz
+aEwvT7EbOyhwQW3kFORWCOOOMj6YBl0uhRObY4HslLuTrN3xCadNpPGEJd8YNsi1
+8L1IJDW5hZr6rz+bjvUnx0WT57HM4eF4eNHi6o9/s90i79TbjQ8GUcGygTUDlido
+OziiA62OeEhU/hy/l/L7et3fpnG2yR3Qw4GVUDhtA9s0EQwuL4+PyFCU68Fz7fGN
+5uZpewKCAQEAvBAmHhwaPBlrDVk6XEY11mwiQoDFBmNSiZE7ZXqcDKWZKpoyc/78
+S+wyUxR5HbognHEpfB4A86AZsuxbOs2DKcELRHHzrdzXuFfjDpV1RTz91699LGQn
+bfeKrdMCqKTbkiiLlwgjDQMQc5bJ9pqwTCFyl6aE8p6nJS8u3XYSSvXzSzXL764T
+0RMusox3dmuQWiRqlarizWfAS8JFOX5ywo4Z6DfGrJkxYRkx/l25N1W0zTTUV5C4
+Q7lqIqhMdNHF4qLlxRkI9cN5kR1ov08kYLLW+VySLBL8xsTVm94WJZN6XdrHuYVr
+94vq4F9hk89aS7EYWFp8VKVMDUkIi0KJAQKCAQEAmt1zJ9MP2xDIbNCY1Kuk3Zoy
+oYcCqijK6i/9Aeu+9w8U1hSrcU5SOF4VQbDwB00RzzDPL7K4e77GulEDnanKnEpX
+eu4lYuhCgG/G7uECU8jLOUQUVp8c4Fcyp29T0pTkow15TLifUOXAfQGfe8jK/SvI
+jpAAwxBDwQ4HNGA3y3HOzmIt5riRLGahASxDpyTDBmFiuRPwyXNxEoO6ZMtaSL9t
+ThhMc74EU8qFBBnzfaKkUZshB9jkcpQq800M99Wj5t31A4mNwz1tmAEM/Wvvbhea
+Yx2I+nS6CQhg0DMAxGqalTTLWxjY4NK+j6Mb5FVpXGJ5yUef2TWVRUymm5XlSA==
+-----END RSA PRIVATE KEY-----
diff --git a/tests/test__environment.py b/tests/test__environment.py
new file mode 100644 (file)
index 0000000..878fb2f
--- /dev/null
@@ -0,0 +1,39 @@
+# 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
+
+
+import os
+import unittest
+
+import asyncpg
+import asyncpg.serverversion
+
+from asyncpg import _testbase as tb
+
+
+class TestEnvironment(tb.ConnectedTestCase):
+    @unittest.skipIf(not os.environ.get('PGVERSION'),
+                     "environ[PGVERSION] is not set")
+    async def test_environment_server_version(self):
+        pgver = os.environ.get('PGVERSION')
+        env_ver = asyncpg.serverversion.split_server_version_string(pgver)
+        srv_ver = self.con.get_server_version()
+
+        self.assertEqual(
+            env_ver[:2], srv_ver[:2],
+            'Expecting PostgreSQL version {pgver}, got {maj}.{min}.'.format(
+                pgver=pgver, maj=srv_ver.major, min=srv_ver.minor)
+        )
+
+    @unittest.skipIf(not os.environ.get('ASYNCPG_VERSION'),
+                     "environ[ASYNCPG_VERSION] is not set")
+    async def test_environment_asyncpg_version(self):
+        apgver = os.environ.get('ASYNCPG_VERSION')
+        self.assertEqual(
+            asyncpg.__version__, apgver,
+            'Expecting asyncpg version {}, got {}.'.format(
+                apgver, asyncpg.__version__)
+        )
diff --git a/tests/test__sourcecode.py b/tests/test__sourcecode.py
new file mode 100644 (file)
index 0000000..e3dc08c
--- /dev/null
@@ -0,0 +1,40 @@
+# 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
+
+import os
+import subprocess
+import sys
+import unittest
+
+
+def find_root():
+    return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+class TestFlake8(unittest.TestCase):
+
+    def test_flake8(self):
+        root_path = find_root()
+        config_path = os.path.join(root_path, '.flake8')
+        if not os.path.exists(config_path):
+            raise RuntimeError('could not locate .flake8 file')
+
+        try:
+            import flake8  # NoQA
+        except ImportError:
+            raise unittest.SkipTest('flake8 module is missing')
+
+        try:
+            subprocess.run(
+                [sys.executable, '-m', 'flake8', '--config', config_path],
+                check=True,
+                stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT,
+                cwd=root_path)
+        except subprocess.CalledProcessError as ex:
+            output = ex.output.decode()
+            raise AssertionError(
+                'flake8 validation failed:\n{}'.format(output)) from None
diff --git a/tests/test_adversity.py b/tests/test_adversity.py
new file mode 100644 (file)
index 0000000..a0d153e
--- /dev/null
@@ -0,0 +1,67 @@
+# 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
+
+"""Tests how asyncpg behaves in non-ideal conditions."""
+
+import asyncio
+import os
+import unittest
+
+from asyncpg import _testbase as tb
+
+
+@unittest.skipIf(os.environ.get('PGHOST'), 'using remote cluster for testing')
+class TestConnectionLoss(tb.ProxiedClusterTestCase):
+    @tb.with_timeout(30.0)
+    async def test_connection_close_timeout(self):
+        con = await self.connect()
+        self.proxy.trigger_connectivity_loss()
+        with self.assertRaises(asyncio.TimeoutError):
+            await con.close(timeout=0.5)
+
+    @tb.with_timeout(30.0)
+    async def test_pool_release_timeout(self):
+        pool = await self.create_pool(
+            database='postgres', min_size=2, max_size=2)
+        try:
+            with self.assertRaises(asyncio.TimeoutError):
+                async with pool.acquire(timeout=0.5):
+                    self.proxy.trigger_connectivity_loss()
+        finally:
+            self.proxy.restore_connectivity()
+            pool.terminate()
+
+    @tb.with_timeout(30.0)
+    async def test_pool_handles_abrupt_connection_loss(self):
+        pool_size = 3
+        query_runtime = 0.5
+        pool_timeout = cmd_timeout = 1.0
+        concurrency = 9
+        pool_concurrency = (concurrency - 1) // pool_size + 1
+
+        # Worst expected runtime + 20% to account for other latencies.
+        worst_runtime = (pool_timeout + cmd_timeout) * pool_concurrency * 1.2
+
+        async def worker(pool):
+            async with pool.acquire(timeout=pool_timeout) as con:
+                await con.fetch('SELECT pg_sleep($1)', query_runtime)
+
+        def kill_connectivity():
+            self.proxy.trigger_connectivity_loss()
+
+        new_pool = self.create_pool(
+            database='postgres', min_size=pool_size, max_size=pool_size,
+            timeout=cmd_timeout, command_timeout=cmd_timeout)
+
+        with self.assertRunUnder(worst_runtime):
+            pool = await new_pool
+            try:
+                workers = [worker(pool) for _ in range(concurrency)]
+                self.loop.call_later(1, kill_connectivity)
+                await asyncio.gather(
+                    *workers, loop=self.loop, return_exceptions=True)
+            finally:
+                pool.terminate()
diff --git a/tests/test_cache_invalidation.py b/tests/test_cache_invalidation.py
new file mode 100644 (file)
index 0000000..96cfd58
--- /dev/null
@@ -0,0 +1,313 @@
+# 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
+
+
+import asyncpg
+from asyncpg import _testbase as tb
+
+ERRNUM = 'unexpected number of attributes of composite type'
+ERRTYP = 'unexpected data type of composite type'
+
+
+class TestCacheInvalidation(tb.ConnectedTestCase):
+    async def test_prepare_cache_invalidation_silent(self):
+        await self.con.execute('CREATE TABLE tab1(a int, b int)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, 2)')
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, 2))
+
+            await self.con.execute(
+                'ALTER TABLE tab1 ALTER COLUMN b SET DATA TYPE text')
+
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, '2'))
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+
+    async def test_prepare_cache_invalidation_in_transaction(self):
+        await self.con.execute('CREATE TABLE tab1(a int, b int)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, 2)')
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, 2))
+
+            await self.con.execute(
+                'ALTER TABLE tab1 ALTER COLUMN b SET DATA TYPE text')
+
+            with self.assertRaisesRegex(asyncpg.InvalidCachedStatementError,
+                                        'cached statement plan is invalid'):
+                async with self.con.transaction():
+                    result = await self.con.fetchrow('SELECT * FROM tab1')
+
+            # This is now OK,
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, '2'))
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+
+    async def test_prepare_cache_invalidation_in_pool(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=2, max_size=2)
+
+        await self.con.execute('CREATE TABLE tab1(a int, b int)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, 2)')
+
+            con1 = await pool.acquire()
+            con2 = await pool.acquire()
+
+            result = await con1.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, 2))
+
+            result = await con2.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, 2))
+
+            await self.con.execute(
+                'ALTER TABLE tab1 ALTER COLUMN b SET DATA TYPE text')
+
+            # con1 tries the same plan, will invalidate the cache
+            # for the entire pool.
+            result = await con1.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, '2'))
+
+            async with con2.transaction():
+                # This should work, as con1 should have invalidated
+                # the plan cache.
+                result = await con2.fetchrow('SELECT * FROM tab1')
+                self.assertEqual(result, (1, '2'))
+
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await pool.release(con2)
+            await pool.release(con1)
+            await pool.close()
+
+    async def test_type_cache_invalidation_in_transaction(self):
+        await self.con.execute('CREATE TYPE typ1 AS (x int, y int)')
+        await self.con.execute('CREATE TABLE tab1(a int, b typ1)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, (2, 3))')
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+
+            async with self.con.transaction():
+                await self.con.execute('ALTER TYPE typ1 ADD ATTRIBUTE c text')
+                with self.assertRaisesRegex(
+                        asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                    await self.con.fetchrow('SELECT * FROM tab1')
+                # The second request must be correct (cache was dropped):
+                result = await self.con.fetchrow('SELECT * FROM tab1')
+                self.assertEqual(result, (1, (2, 3, None)))
+
+            # This is now OK, the cache is actual after the transaction.
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3, None)))
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await self.con.execute('DROP TYPE typ1')
+
+    async def test_type_cache_invalidation_in_cancelled_transaction(self):
+        await self.con.execute('CREATE TYPE typ1 AS (x int, y int)')
+        await self.con.execute('CREATE TABLE tab1(a int, b typ1)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, (2, 3))')
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+
+            try:
+                async with self.con.transaction():
+                    await self.con.execute(
+                        'ALTER TYPE typ1 ADD ATTRIBUTE c text')
+                    with self.assertRaisesRegex(
+                            asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                        await self.con.fetchrow('SELECT * FROM tab1')
+                    # The second request must be correct (cache was dropped):
+                    result = await self.con.fetchrow('SELECT * FROM tab1')
+                    self.assertEqual(result, (1, (2, 3, None)))
+                    raise UserWarning  # Just to generate ROLLBACK
+            except UserWarning:
+                pass
+
+            with self.assertRaisesRegex(
+                    asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                await self.con.fetchrow('SELECT * FROM tab1')
+            # This is now OK, the cache is filled after being dropped.
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await self.con.execute('DROP TYPE typ1')
+
+    async def test_prepared_type_cache_invalidation(self):
+        await self.con.execute('CREATE TYPE typ1 AS (x int, y int)')
+        await self.con.execute('CREATE TABLE tab1(a int, b typ1)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, (2, 3))')
+            prep = await self.con._prepare('SELECT * FROM tab1',
+                                           use_cache=True)
+            result = await prep.fetchrow()
+            self.assertEqual(result, (1, (2, 3)))
+
+            try:
+                async with self.con.transaction():
+                    await self.con.execute(
+                        'ALTER TYPE typ1 ADD ATTRIBUTE c text')
+                    with self.assertRaisesRegex(
+                            asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                        await prep.fetchrow()
+                    # PS has its local cache for types codecs, even after the
+                    # cache cleanup it is not possible to use it.
+                    # That's why it is marked as closed.
+                    with self.assertRaisesRegex(
+                            asyncpg.InterfaceError,
+                            'the prepared statement is closed'):
+                        await prep.fetchrow()
+
+                    prep = await self.con._prepare('SELECT * FROM tab1',
+                                                   use_cache=True)
+                    # The second PS must be correct (cache was dropped):
+                    result = await prep.fetchrow()
+                    self.assertEqual(result, (1, (2, 3, None)))
+                    raise UserWarning  # Just to generate ROLLBACK
+            except UserWarning:
+                pass
+
+            with self.assertRaisesRegex(
+                    asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                await prep.fetchrow()
+
+            # Reprepare it again after dropping cache.
+            prep = await self.con._prepare('SELECT * FROM tab1',
+                                           use_cache=True)
+            # This is now OK, the cache is filled after being dropped.
+            result = await prep.fetchrow()
+            self.assertEqual(result, (1, (2, 3)))
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await self.con.execute('DROP TYPE typ1')
+
+    async def test_type_cache_invalidation_on_drop_type_attr(self):
+        await self.con.execute('CREATE TYPE typ1 AS (x int, y int, c text)')
+        await self.con.execute('CREATE TABLE tab1(a int, b typ1)')
+
+        try:
+            await self.con.execute(
+                'INSERT INTO tab1 VALUES (1, (2, 3, $1))', 'x')
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3, 'x')))
+
+            await self.con.execute('ALTER TYPE typ1 DROP ATTRIBUTE x')
+            with self.assertRaisesRegex(
+                    asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                await self.con.fetchrow('SELECT * FROM tab1')
+
+            # This is now OK, the cache is filled after being dropped.
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (3, 'x')))
+
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await self.con.execute('DROP TYPE typ1')
+
+    async def test_type_cache_invalidation_on_change_attr(self):
+        await self.con.execute('CREATE TYPE typ1 AS (x int, y int)')
+        await self.con.execute('CREATE TABLE tab1(a int, b typ1)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, (2, 3))')
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+
+            # It is slightly artificial, but can take place in transactional
+            # schema changing. Nevertheless, if the code checks and raises it
+            # the most probable reason is a difference with the cache type.
+            await self.con.execute('ALTER TYPE typ1 DROP ATTRIBUTE y')
+            await self.con.execute('ALTER TYPE typ1 ADD ATTRIBUTE y bigint')
+            with self.assertRaisesRegex(
+                    asyncpg.OutdatedSchemaCacheError, ERRTYP):
+                await self.con.fetchrow('SELECT * FROM tab1')
+
+            # This is now OK, the cache is filled after being dropped.
+            result = await self.con.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, None)))
+
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await self.con.execute('DROP TYPE typ1')
+
+    async def test_type_cache_invalidation_in_pool(self):
+        await self.con.execute('CREATE DATABASE testdb')
+        pool = await self.create_pool(database='postgres',
+                                      min_size=2, max_size=2)
+
+        pool_chk = await self.create_pool(database='testdb',
+                                          min_size=2, max_size=2)
+
+        await self.con.execute('CREATE TYPE typ1 AS (x int, y int)')
+        await self.con.execute('CREATE TABLE tab1(a int, b typ1)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, (2, 3))')
+
+            con1 = await pool.acquire()
+            con2 = await pool.acquire()
+
+            result = await con1.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+
+            result = await con2.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+
+            # Create the same schema in the "testdb", fetch data which caches
+            # type info.
+            con_chk = await pool_chk.acquire()
+            await con_chk.execute('CREATE TYPE typ1 AS (x int, y int)')
+            await con_chk.execute('CREATE TABLE tab1(a int, b typ1)')
+            await con_chk.execute('INSERT INTO tab1 VALUES (1, (2, 3))')
+            result = await con_chk.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3)))
+
+            # Change schema in the databases.
+            await self.con.execute('ALTER TYPE typ1 ADD ATTRIBUTE c text')
+            await con_chk.execute('ALTER TYPE typ1 ADD ATTRIBUTE c text')
+
+            # con1 tries to get cached type info, fails, but invalidates the
+            # cache for the entire pool.
+            with self.assertRaisesRegex(
+                    asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                await con1.fetchrow('SELECT * FROM tab1')
+
+            async with con2.transaction():
+                # This should work, as con1 should have invalidated all caches.
+                result = await con2.fetchrow('SELECT * FROM tab1')
+                self.assertEqual(result, (1, (2, 3, None)))
+
+            # After all the con1 uses actual info from renewed cache entry.
+            result = await con1.fetchrow('SELECT * FROM tab1')
+            self.assertEqual(result, (1, (2, 3, None)))
+
+            # Check the invalidation is database-specific, i.e. cache entries
+            # for pool_chk/con_chk was not dropped via pool/con1.
+            with self.assertRaisesRegex(
+                    asyncpg.OutdatedSchemaCacheError, ERRNUM):
+                await con_chk.fetchrow('SELECT * FROM tab1')
+
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+            await self.con.execute('DROP TYPE typ1')
+            await pool.release(con2)
+            await pool.release(con1)
+            await pool.close()
+            await pool_chk.release(con_chk)
+            await pool_chk.close()
+            await self.con.execute('DROP DATABASE testdb')
diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py
new file mode 100644 (file)
index 0000000..bc21309
--- /dev/null
@@ -0,0 +1,96 @@
+# 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
+
+
+import asyncio
+import asyncpg
+
+from asyncpg import _testbase as tb
+
+
+class TestCancellation(tb.ConnectedTestCase):
+
+    async def test_cancellation_01(self):
+        st1000 = await self.con.prepare('SELECT 1000')
+
+        async def test0():
+            val = await self.con.execute('SELECT 42')
+            self.assertEqual(val, 'SELECT 1')
+
+        async def test1():
+            val = await self.con.fetchval('SELECT 42')
+            self.assertEqual(val, 42)
+
+        async def test2():
+            val = await self.con.fetchrow('SELECT 42')
+            self.assertEqual(val, (42,))
+
+        async def test3():
+            val = await self.con.fetch('SELECT 42')
+            self.assertEqual(val, [(42,)])
+
+        async def test4():
+            val = await self.con.prepare('SELECT 42')
+            self.assertEqual(await val.fetchval(), 42)
+
+        async def test5():
+            self.assertEqual(await st1000.fetchval(), 1000)
+
+        async def test6():
+            self.assertEqual(await st1000.fetchrow(), (1000,))
+
+        async def test7():
+            self.assertEqual(await st1000.fetch(), [(1000,)])
+
+        async def test8():
+            cur = await st1000.cursor()
+            self.assertEqual(await cur.fetchrow(), (1000,))
+
+        for test in {test0, test1, test2, test3, test4, test5,
+                     test6, test7, test8}:
+
+            with self.subTest(testfunc=test), self.assertRunUnder(1):
+                st = await self.con.prepare('SELECT pg_sleep(20)')
+                task = self.loop.create_task(st.fetch())
+                await asyncio.sleep(0.05, loop=self.loop)
+                task.cancel()
+
+                with self.assertRaises(asyncio.CancelledError):
+                    await task
+
+                async with self.con.transaction():
+                    await test()
+
+    async def test_cancellation_02(self):
+        st = await self.con.prepare('SELECT 1')
+        task = self.loop.create_task(st.fetch())
+        await asyncio.sleep(0.05, loop=self.loop)
+        task.cancel()
+        self.assertEqual(await task, [(1,)])
+
+    async def test_cancellation_03(self):
+        with self.assertRaises(asyncpg.InFailedSQLTransactionError):
+            async with self.con.transaction():
+                task = self.loop.create_task(
+                    self.con.fetch('SELECT pg_sleep(20)'))
+                await asyncio.sleep(0.05, loop=self.loop)
+                task.cancel()
+
+                with self.assertRaises(asyncio.CancelledError):
+                    await task
+
+                await self.con.fetch('SELECT generate_series(0, 100)')
+
+        self.assertEqual(
+            await self.con.fetchval('SELECT 42'),
+            42)
+
+    async def test_cancellation_04(self):
+        await self.con.fetchval('SELECT pg_sleep(0)')
+        waiter = asyncio.Future(loop=self.loop)
+        self.con._cancel_current_command(waiter)
+        await waiter
+        self.assertEqual(await self.con.fetchval('SELECT 42'), 42)
diff --git a/tests/test_codecs.py b/tests/test_codecs.py
new file mode 100644 (file)
index 0000000..5498b40
--- /dev/null
@@ -0,0 +1,1768 @@
+# 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
+
+
+import datetime
+import decimal
+import ipaddress
+import math
+import os
+import random
+import struct
+import unittest
+import uuid
+
+import asyncpg
+from asyncpg import _testbase as tb
+from asyncpg import cluster as pg_cluster
+
+
+def _timezone(offset):
+    minutes = offset // 60
+    return datetime.timezone(datetime.timedelta(minutes=minutes))
+
+
+def _system_timezone():
+    d = datetime.datetime.now(datetime.timezone.utc).astimezone()
+    return datetime.timezone(d.utcoffset())
+
+
+infinity_datetime = datetime.datetime(
+    datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
+negative_infinity_datetime = datetime.datetime(
+    datetime.MINYEAR, 1, 1, 0, 0, 0, 0)
+
+infinity_date = datetime.date(datetime.MAXYEAR, 12, 31)
+negative_infinity_date = datetime.date(datetime.MINYEAR, 1, 1)
+current_timezone = _system_timezone()
+current_date = datetime.date.today()
+current_datetime = datetime.datetime.now()
+
+
+type_samples = [
+    ('bool', 'bool', (
+        True, False,
+    )),
+    ('smallint', 'int2', (
+        -2 ** 15, 2 ** 15 - 1,
+        -1, 0, 1,
+    )),
+    ('int', 'int4', (
+        -2 ** 31, 2 ** 31 - 1,
+        -1, 0, 1,
+    )),
+    ('bigint', 'int8', (
+        -2 ** 63, 2 ** 63 - 1,
+        -1, 0, 1,
+    )),
+    ('numeric', 'numeric', (
+        -(2 ** 64),
+        2 ** 64,
+        -(2 ** 128),
+        2 ** 128,
+        -1, 0, 1,
+        decimal.Decimal("0.00000000000000"),
+        decimal.Decimal("1.00000000000000"),
+        decimal.Decimal("-1.00000000000000"),
+        decimal.Decimal("-2.00000000000000"),
+        decimal.Decimal("1000000000000000.00000000000000"),
+        decimal.Decimal("-0.00000000000000"),
+        decimal.Decimal(1234),
+        decimal.Decimal(-1234),
+        decimal.Decimal("1234000000.00088883231"),
+        decimal.Decimal(str(1234.00088883231)),
+        decimal.Decimal("3123.23111"),
+        decimal.Decimal("-3123000000.23111"),
+        decimal.Decimal("3123.2311100000"),
+        decimal.Decimal("-03123.0023111"),
+        decimal.Decimal("3123.23111"),
+        decimal.Decimal("3123.23111"),
+        decimal.Decimal("10000.23111"),
+        decimal.Decimal("100000.23111"),
+        decimal.Decimal("1000000.23111"),
+        decimal.Decimal("10000000.23111"),
+        decimal.Decimal("100000000.23111"),
+        decimal.Decimal("1000000000.23111"),
+        decimal.Decimal("1000000000.3111"),
+        decimal.Decimal("1000000000.111"),
+        decimal.Decimal("1000000000.11"),
+        decimal.Decimal("100000000.0"),
+        decimal.Decimal("10000000.0"),
+        decimal.Decimal("1000000.0"),
+        decimal.Decimal("100000.0"),
+        decimal.Decimal("10000.0"),
+        decimal.Decimal("1000.0"),
+        decimal.Decimal("100.0"),
+        decimal.Decimal("100"),
+        decimal.Decimal("100.1"),
+        decimal.Decimal("100.12"),
+        decimal.Decimal("100.123"),
+        decimal.Decimal("100.1234"),
+        decimal.Decimal("100.12345"),
+        decimal.Decimal("100.123456"),
+        decimal.Decimal("100.1234567"),
+        decimal.Decimal("100.12345679"),
+        decimal.Decimal("100.123456790"),
+        decimal.Decimal("100.123456790000000000000000"),
+        decimal.Decimal("1.0"),
+        decimal.Decimal("0.0"),
+        decimal.Decimal("-1.0"),
+        decimal.Decimal("1.0E-1000"),
+        decimal.Decimal("1.0E1000"),
+        decimal.Decimal("0.000000000000000000000000001"),
+        decimal.Decimal("0.000000000000010000000000001"),
+        decimal.Decimal("0.00000000000000000000000001"),
+        decimal.Decimal("0.00000000100000000000000001"),
+        decimal.Decimal("0.0000000000000000000000001"),
+        decimal.Decimal("0.000000000000000000000001"),
+        decimal.Decimal("0.00000000000000000000001"),
+        decimal.Decimal("0.0000000000000000000001"),
+        decimal.Decimal("0.000000000000000000001"),
+        decimal.Decimal("0.00000000000000000001"),
+        decimal.Decimal("0.0000000000000000001"),
+        decimal.Decimal("0.000000000000000001"),
+        decimal.Decimal("0.00000000000000001"),
+        decimal.Decimal("0.0000000000000001"),
+        decimal.Decimal("0.000000000000001"),
+        decimal.Decimal("0.00000000000001"),
+        decimal.Decimal("0.0000000000001"),
+        decimal.Decimal("0.000000000001"),
+        decimal.Decimal("0.00000000001"),
+        decimal.Decimal("0.0000000001"),
+        decimal.Decimal("0.000000001"),
+        decimal.Decimal("0.00000001"),
+        decimal.Decimal("0.0000001"),
+        decimal.Decimal("0.000001"),
+        decimal.Decimal("0.00001"),
+        decimal.Decimal("0.0001"),
+        decimal.Decimal("0.001"),
+        decimal.Decimal("0.01"),
+        decimal.Decimal("0.1"),
+    )),
+    ('bytea', 'bytea', (
+        bytes(range(256)),
+        bytes(range(255, -1, -1)),
+        b'\x00\x00',
+        b'foo',
+        b'f' * 1024 * 1024,
+        dict(input=bytearray(b'\x02\x01'), output=b'\x02\x01'),
+    )),
+    ('text', 'text', (
+        '',
+        'A' * (1024 * 1024 + 11)
+    )),
+    ('"char"', 'char', (
+        b'a',
+        b'b',
+        b'\x00'
+    )),
+    ('timestamp', 'timestamp', [
+        datetime.datetime(3000, 5, 20, 5, 30, 10),
+        datetime.datetime(2000, 1, 1, 5, 25, 10),
+        datetime.datetime(500, 1, 1, 5, 25, 10),
+        datetime.datetime(250, 1, 1, 5, 25, 10),
+        infinity_datetime,
+        negative_infinity_datetime,
+        {'textinput': 'infinity', 'output': infinity_datetime},
+        {'textinput': '-infinity', 'output': negative_infinity_datetime},
+        {'input': datetime.date(2000, 1, 1),
+         'output': datetime.datetime(2000, 1, 1)},
+        {'textinput': '1970-01-01 20:31:23.648',
+         'output': datetime.datetime(1970, 1, 1, 20, 31, 23, 648000)},
+        {'input': datetime.datetime(1970, 1, 1, 20, 31, 23, 648000),
+         'textoutput': '1970-01-01 20:31:23.648'},
+    ]),
+    ('date', 'date', [
+        datetime.date(3000, 5, 20),
+        datetime.date(2000, 1, 1),
+        datetime.date(500, 1, 1),
+        infinity_date,
+        negative_infinity_date,
+        {'textinput': 'infinity', 'output': infinity_date},
+        {'textinput': '-infinity', 'output': negative_infinity_date},
+    ]),
+    ('time', 'time', [
+        datetime.time(12, 15, 20),
+        datetime.time(0, 1, 1),
+        datetime.time(23, 59, 59),
+    ]),
+    ('timestamptz', 'timestamptz', [
+        # It's converted to UTC. When it comes back out, it will be in UTC
+        # again. The datetime comparison will take the tzinfo into account.
+        datetime.datetime(1990, 5, 12, 10, 10, 0, tzinfo=_timezone(4000)),
+        datetime.datetime(1982, 5, 18, 10, 10, 0, tzinfo=_timezone(6000)),
+        datetime.datetime(1950, 1, 1, 10, 10, 0, tzinfo=_timezone(7000)),
+        datetime.datetime(1800, 1, 1, 10, 10, 0, tzinfo=_timezone(2000)),
+        datetime.datetime(2400, 1, 1, 10, 10, 0, tzinfo=_timezone(2000)),
+        infinity_datetime,
+        negative_infinity_datetime,
+        {
+            'input': current_date,
+            'output': datetime.datetime(
+                year=current_date.year, month=current_date.month,
+                day=current_date.day, tzinfo=current_timezone),
+        },
+        {
+            'input': current_datetime,
+            'output': current_datetime.replace(tzinfo=current_timezone),
+        }
+    ]),
+    ('timetz', 'timetz', [
+        # timetz retains the offset
+        datetime.time(10, 10, 0, tzinfo=_timezone(4000)),
+        datetime.time(10, 10, 0, tzinfo=_timezone(6000)),
+        datetime.time(10, 10, 0, tzinfo=_timezone(7000)),
+        datetime.time(10, 10, 0, tzinfo=_timezone(2000)),
+        datetime.time(22, 30, 0, tzinfo=_timezone(0)),
+    ]),
+    ('interval', 'interval', [
+        datetime.timedelta(40, 10, 1234),
+        datetime.timedelta(0, 0, 4321),
+        datetime.timedelta(0, 0),
+        datetime.timedelta(-100, 0),
+        datetime.timedelta(-100, -400),
+        {
+            'textinput': '-2 years -11 months -10 days '
+                         '-2 hours -800 milliseconds',
+            'output': datetime.timedelta(
+                days=(-2 * 365) + (-11 * 30) - 10,
+                seconds=(-2 * 3600),
+                milliseconds=-800
+            ),
+        },
+        {
+            'query': 'SELECT justify_hours($1::interval)::text',
+            'input': datetime.timedelta(
+                days=(-2 * 365) + (-11 * 30) - 10,
+                seconds=(-2 * 3600),
+                milliseconds=-800
+            ),
+            'textoutput': '-1070 days -02:00:00.8',
+        },
+    ]),
+    ('uuid', 'uuid', [
+        uuid.UUID('38a4ff5a-3a56-11e6-a6c2-c8f73323c6d4'),
+        uuid.UUID('00000000-0000-0000-0000-000000000000'),
+        {'input': '00000000-0000-0000-0000-000000000000',
+         'output': uuid.UUID('00000000-0000-0000-0000-000000000000')}
+    ]),
+    ('uuid[]', 'uuid[]', [
+        [uuid.UUID('38a4ff5a-3a56-11e6-a6c2-c8f73323c6d4'),
+         uuid.UUID('00000000-0000-0000-0000-000000000000')],
+        []
+    ]),
+    ('json', 'json', [
+        '[1, 2, 3, 4]',
+        '{"a": [1, 2], "b": 0}'
+    ]),
+    ('jsonb', 'jsonb', [
+        '[1, 2, 3, 4]',
+        '{"a": [1, 2], "b": 0}'
+    ], (9, 4)),
+    ('oid[]', 'oid[]', [
+        [1, 2, 3, 4],
+        []
+    ]),
+    ('smallint[]', 'int2[]', [
+        [1, 2, 3, 4],
+        [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
+        []
+    ]),
+    ('bigint[]', 'int8[]', [
+        [2 ** 42, -2 ** 54, 0],
+        []
+    ]),
+    ('int[]', 'int4[]', [
+        [2 ** 22, -2 ** 24, 0],
+        []
+    ]),
+    ('time[]', 'time[]', [
+        [datetime.time(12, 15, 20), datetime.time(0, 1, 1)],
+        []
+    ]),
+    ('text[]', 'text[]', [
+        ['ABCDE', 'EDCBA'],
+        [],
+        ['A' * 1024 * 1024] * 10
+    ]),
+    ('float8', 'float8', [
+        1.1,
+        -1.1,
+        0,
+        2,
+        1e-4,
+        -1e-20,
+        122.2e-100,
+        2e5,
+        math.pi,
+        math.e,
+        math.inf,
+        -math.inf,
+        math.nan,
+        {'textinput': 'infinity', 'output': math.inf},
+        {'textinput': '-infinity', 'output': -math.inf},
+        {'textinput': 'NaN', 'output': math.nan},
+    ]),
+    ('float4', 'float4', [
+        1.1,
+        -1.1,
+        0,
+        2,
+        1e-4,
+        -1e-20,
+        2e5,
+        math.pi,
+        math.e,
+        math.inf,
+        -math.inf,
+        math.nan,
+        {'textinput': 'infinity', 'output': math.inf},
+        {'textinput': '-infinity', 'output': -math.inf},
+        {'textinput': 'NaN', 'output': math.nan},
+    ]),
+    ('cidr', 'cidr', [
+        ipaddress.IPv4Network('255.255.255.255/32'),
+        ipaddress.IPv4Network('127.0.0.0/8'),
+        ipaddress.IPv4Network('127.1.0.0/16'),
+        ipaddress.IPv4Network('127.1.0.0/18'),
+        ipaddress.IPv4Network('10.0.0.0/32'),
+        ipaddress.IPv4Network('0.0.0.0/0'),
+        ipaddress.IPv6Network('ffff' + ':ffff' * 7 + '/128'),
+        ipaddress.IPv6Network('::1/128'),
+        ipaddress.IPv6Network('::/0'),
+    ]),
+    ('inet', 'inet', [
+        ipaddress.IPv4Address('255.255.255.255'),
+        ipaddress.IPv4Address('127.0.0.1'),
+        ipaddress.IPv4Address('0.0.0.0'),
+        ipaddress.IPv6Address('ffff' + ':ffff' * 7),
+        ipaddress.IPv6Address('::1'),
+        ipaddress.IPv6Address('::'),
+        dict(
+            input='127.0.0.0/8',
+            output=ipaddress.IPv4Network('127.0.0.0/8')),
+        dict(
+            input='127.0.0.1/32',
+            output=ipaddress.IPv4Address('127.0.0.1')),
+        # Postgres appends /32 when casting to text explicitly, but
+        # *not* in inet_out.
+        dict(
+            input='10.11.12.13',
+            textoutput='10.11.12.13/32'
+        ),
+        dict(
+            input=ipaddress.IPv4Address('10.11.12.13'),
+            textoutput='10.11.12.13/32'
+        ),
+        dict(
+            input=ipaddress.IPv4Network('10.11.12.13'),
+            textoutput='10.11.12.13/32'
+        ),
+        dict(
+            textinput='10.11.12.13',
+            output=ipaddress.IPv4Address('10.11.12.13'),
+        ),
+        dict(
+            # Non-zero address bits after the network prefix are permitted
+            # by postgres, but are invalid in Python
+            # (and zeroed out by supernet()).
+            textinput='10.11.12.13/0',
+            output=ipaddress.IPv4Network('0.0.0.0/0'),
+        ),
+    ]),
+    ('macaddr', 'macaddr', [
+        '00:00:00:00:00:00',
+        'ff:ff:ff:ff:ff:ff'
+    ]),
+    ('txid_snapshot', 'txid_snapshot', [
+        (100, 1000, (100, 200, 300, 400))
+    ]),
+    ('varbit', 'varbit', [
+        asyncpg.BitString('0000 0001'),
+        asyncpg.BitString('00010001'),
+        asyncpg.BitString(''),
+        asyncpg.BitString(),
+        asyncpg.BitString.frombytes(b'\x00', bitlength=3),
+        asyncpg.BitString('0000 0000 1'),
+        dict(input=b'\x01', output=asyncpg.BitString('0000 0001')),
+        dict(input=bytearray(b'\x02'), output=asyncpg.BitString('0000 0010')),
+    ]),
+    ('path', 'path', [
+        asyncpg.Path(asyncpg.Point(0.0, 0.0), asyncpg.Point(1.0, 1.0)),
+        asyncpg.Path(asyncpg.Point(0.0, 0.0), asyncpg.Point(1.0, 1.0),
+                     is_closed=True),
+        dict(input=((0.0, 0.0), (1.0, 1.0)),
+             output=asyncpg.Path(asyncpg.Point(0.0, 0.0),
+                                 asyncpg.Point(1.0, 1.0),
+                                 is_closed=True)),
+        dict(input=[(0.0, 0.0), (1.0, 1.0)],
+             output=asyncpg.Path(asyncpg.Point(0.0, 0.0),
+                                 asyncpg.Point(1.0, 1.0),
+                                 is_closed=False)),
+    ]),
+    ('point', 'point', [
+        asyncpg.Point(0.0, 0.0),
+        asyncpg.Point(1.0, 2.0),
+    ]),
+    ('box', 'box', [
+        asyncpg.Box((1.0, 2.0), (0.0, 0.0)),
+    ]),
+    ('line', 'line', [
+        asyncpg.Line(1, 2, 3),
+    ], (9, 4)),
+    ('lseg', 'lseg', [
+        asyncpg.LineSegment((1, 2), (2, 2)),
+    ]),
+    ('polygon', 'polygon', [
+        asyncpg.Polygon(asyncpg.Point(0.0, 0.0), asyncpg.Point(1.0, 0.0),
+                        asyncpg.Point(1.0, 1.0), asyncpg.Point(0.0, 1.0)),
+    ]),
+    ('circle', 'circle', [
+        asyncpg.Circle((0.0, 0.0), 100),
+    ]),
+    ('tid', 'tid', [
+        (100, 200),
+        (0, 0),
+        (2147483647, 0),
+        (4294967295, 0),
+        (0, 32767),
+        (0, 65535),
+        (4294967295, 65535),
+    ]),
+    ('oid', 'oid', [
+        0,
+        10,
+        4294967295
+    ])
+]
+
+
+class TestCodecs(tb.ConnectedTestCase):
+
+    async def test_standard_codecs(self):
+        """Test encoding/decoding of standard data types and arrays thereof."""
+        for (typname, intname, sample_data, *metadata) in type_samples:
+            if metadata and self.server_version < metadata[0]:
+                continue
+
+            st = await self.con.prepare(
+                "SELECT $1::" + typname
+            )
+
+            text_in = await self.con.prepare(
+                "SELECT $1::text::" + typname
+            )
+
+            text_out = await self.con.prepare(
+                "SELECT $1::" + typname + "::text"
+            )
+
+            for sample in sample_data:
+                with self.subTest(sample=sample, typname=typname):
+                    stmt = st
+                    if isinstance(sample, dict):
+                        if 'textinput' in sample:
+                            inputval = sample['textinput']
+                            stmt = text_in
+                        else:
+                            inputval = sample['input']
+
+                        if 'textoutput' in sample:
+                            outputval = sample['textoutput']
+                            if stmt is text_in:
+                                raise ValueError(
+                                    'cannot test "textin" and'
+                                    ' "textout" simultaneously')
+                            stmt = text_out
+                        else:
+                            outputval = sample['output']
+
+                        if sample.get('query'):
+                            stmt = await self.con.prepare(sample['query'])
+                    else:
+                        inputval = outputval = sample
+
+                    result = await stmt.fetchval(inputval)
+                    err_msg = (
+                        "unexpected result for {} when passing {!r}: "
+                        "received {!r}, expected {!r}".format(
+                            typname, inputval, result, outputval))
+
+                    if typname.startswith('float'):
+                        if math.isnan(outputval):
+                            if not math.isnan(result):
+                                self.fail(err_msg)
+                        else:
+                            self.assertTrue(
+                                math.isclose(result, outputval, rel_tol=1e-6),
+                                err_msg)
+                    else:
+                        self.assertEqual(result, outputval, err_msg)
+
+            with self.subTest(sample=None, typname=typname):
+                # Test that None is handled for all types.
+                rsample = await st.fetchval(None)
+                self.assertIsNone(rsample)
+
+            at = st.get_attributes()
+            self.assertEqual(at[0].type.name, intname)
+
+    async def test_all_builtin_types_handled(self):
+        from asyncpg.protocol.protocol import BUILTIN_TYPE_OID_MAP
+
+        for oid, typename in BUILTIN_TYPE_OID_MAP.items():
+            codec = self.con.get_settings().get_data_codec(oid)
+            self.assertIsNotNone(
+                codec,
+                'core type {} ({}) is unhandled'.format(typename, oid))
+
+    async def test_void(self):
+        res = await self.con.fetchval('select pg_sleep(0)')
+        self.assertIsNone(res)
+        await self.con.fetchval('select now($1::void)', '')
+
+    def test_bitstring(self):
+        bitlen = random.randint(0, 1000)
+        bs = ''.join(random.choice(('1', '0', ' ')) for _ in range(bitlen))
+        bits = asyncpg.BitString(bs)
+        sanitized_bs = bs.replace(' ', '')
+        self.assertEqual(sanitized_bs,
+                         bits.as_string().replace(' ', ''))
+
+        expected_bytelen = \
+            len(sanitized_bs) // 8 + (1 if len(sanitized_bs) % 8 else 0)
+
+        self.assertEqual(len(bits.bytes), expected_bytelen)
+
+        little, big = bits.to_int('little'), bits.to_int('big')
+        self.assertEqual(bits.from_int(little, len(bits), 'little'), bits)
+        self.assertEqual(bits.from_int(big, len(bits), 'big'), bits)
+
+        naive_little = 0
+        for i, c in enumerate(sanitized_bs):
+            naive_little |= int(c) << i
+        naive_big = 0
+        for c in sanitized_bs:
+            naive_big = (naive_big << 1) | int(c)
+
+        self.assertEqual(little, naive_little)
+        self.assertEqual(big, naive_big)
+
+    async def test_interval(self):
+        res = await self.con.fetchval("SELECT '5 years'::interval")
+        self.assertEqual(res, datetime.timedelta(days=1825))
+
+        res = await self.con.fetchval("SELECT '5 years 1 month'::interval")
+        self.assertEqual(res, datetime.timedelta(days=1855))
+
+        res = await self.con.fetchval("SELECT '-5 years'::interval")
+        self.assertEqual(res, datetime.timedelta(days=-1825))
+
+        res = await self.con.fetchval("SELECT '-5 years -1 month'::interval")
+        self.assertEqual(res, datetime.timedelta(days=-1855))
+
+    async def test_numeric(self):
+        # Test that we handle dscale correctly.
+        cases = [
+            '0.001',
+            '0.001000',
+            '1',
+            '1.00000'
+        ]
+
+        for case in cases:
+            res = await self.con.fetchval(
+                "SELECT $1::numeric", case)
+
+            self.assertEqual(str(res), case)
+
+        try:
+            await self.con.execute(
+                '''
+                    CREATE TABLE tab (v numeric(3, 2));
+                    INSERT INTO tab VALUES (0), (1);
+                ''')
+            res = await self.con.fetchval("SELECT v FROM tab WHERE v = $1", 0)
+            self.assertEqual(str(res), '0.00')
+            res = await self.con.fetchval("SELECT v FROM tab WHERE v = $1", 1)
+            self.assertEqual(str(res), '1.00')
+        finally:
+            await self.con.execute('DROP TABLE tab')
+
+        res = await self.con.fetchval(
+            "SELECT $1::numeric", decimal.Decimal('NaN'))
+        self.assertTrue(res.is_nan())
+
+        res = await self.con.fetchval(
+            "SELECT $1::numeric", decimal.Decimal('sNaN'))
+        self.assertTrue(res.is_nan())
+
+        with self.assertRaisesRegex(asyncpg.DataError,
+                                    'numeric type does not '
+                                    'support infinite values'):
+            await self.con.fetchval(
+                "SELECT $1::numeric", decimal.Decimal('-Inf'))
+
+        with self.assertRaisesRegex(asyncpg.DataError,
+                                    'numeric type does not '
+                                    'support infinite values'):
+            await self.con.fetchval(
+                "SELECT $1::numeric", decimal.Decimal('+Inf'))
+
+        with self.assertRaisesRegex(asyncpg.DataError, 'invalid'):
+            await self.con.fetchval(
+                "SELECT $1::numeric", 'invalid')
+
+    async def test_unhandled_type_fallback(self):
+        await self.con.execute('''
+            CREATE EXTENSION IF NOT EXISTS isn
+        ''')
+
+        try:
+            input_val = '1436-4522'
+
+            res = await self.con.fetchrow('''
+                SELECT $1::issn AS issn, 42 AS int
+            ''', input_val)
+
+            self.assertEqual(res['issn'], input_val)
+            self.assertEqual(res['int'], 42)
+
+        finally:
+            await self.con.execute('''
+                DROP EXTENSION isn
+            ''')
+
+    async def test_invalid_input(self):
+        cases = [
+            ('bytea', 'a bytes-like object is required', [
+                1,
+                'aaa'
+            ]),
+            ('bool', 'a boolean is required', [
+                1,
+            ]),
+            ('int2', 'an integer is required', [
+                '2',
+                'aa',
+            ]),
+            ('smallint', 'value out of int16 range', [
+                2**256,  # check for the same exception for any big numbers
+                decimal.Decimal("2000000000000000000000000000000"),
+                0xffff,
+                0xffffffff,
+                32768,
+                -32769
+            ]),
+            ('float4', 'value out of float32 range', [
+                4.1 * 10 ** 40,
+                -4.1 * 10 ** 40,
+            ]),
+            ('int4', 'an integer is required', [
+                '2',
+                'aa',
+            ]),
+            ('int', 'value out of int32 range', [
+                2**256,  # check for the same exception for any big numbers
+                decimal.Decimal("2000000000000000000000000000000"),
+                0xffffffff,
+                2**31,
+                -2**31 - 1,
+            ]),
+            ('int8', 'an integer is required', [
+                '2',
+                'aa',
+            ]),
+            ('bigint', 'value out of int64 range', [
+                2**256,  # check for the same exception for any big numbers
+                decimal.Decimal("2000000000000000000000000000000"),
+                0xffffffffffffffff,
+                2**63,
+                -2**63 - 1,
+            ]),
+            ('text', 'expected str, got bytes', [
+                b'foo'
+            ]),
+            ('text', 'expected str, got list', [
+                [1]
+            ]),
+            ('tid', 'list or tuple expected', [
+                b'foo'
+            ]),
+            ('tid', 'invalid number of elements in tid tuple', [
+                [],
+                (),
+                [1, 2, 3],
+                (4,),
+            ]),
+            ('tid', 'tuple id block value out of uint32 range', [
+                (-1, 0),
+                (2**256, 0),
+                (0xffffffff + 1, 0),
+                (2**32, 0),
+            ]),
+            ('tid', 'tuple id offset value out of uint16 range', [
+                (0, -1),
+                (0, 2**256),
+                (0, 0xffff + 1),
+                (0, 0xffffffff),
+                (0, 65536),
+            ]),
+            ('oid', 'value out of uint32 range', [
+                2 ** 32,
+                -1,
+            ]),
+            ('timestamp', r"expected a datetime\.date.*got 'str'", [
+                'foo'
+            ]),
+            ('timestamptz', r"expected a datetime\.date.*got 'str'", [
+                'foo'
+            ]),
+        ]
+
+        for typname, errmsg, data in cases:
+            stmt = await self.con.prepare("SELECT $1::" + typname)
+
+            for sample in data:
+                with self.subTest(sample=sample, typname=typname):
+                    full_errmsg = (
+                        r'invalid input for query argument \$1:.*' + errmsg)
+
+                    with self.assertRaisesRegex(
+                            asyncpg.DataError, full_errmsg):
+                        await stmt.fetchval(sample)
+
+    async def test_arrays(self):
+        """Test encoding/decoding of arrays (particularly multidimensional)."""
+        cases = [
+            (
+                r"SELECT '[1:3][-1:0]={{1,2},{4,5},{6,7}}'::int[]",
+                [[1, 2], [4, 5], [6, 7]]
+            ),
+            (
+                r"SELECT '{{{{{{1}}}}}}'::int[]",
+                [[[[[[1]]]]]]
+            ),
+            (
+                r"SELECT '{1, 2, NULL}'::int[]::anyarray",
+                [1, 2, None]
+            ),
+            (
+                r"SELECT '{}'::int[]",
+                []
+            ),
+        ]
+
+        for sql, expected in cases:
+            with self.subTest(sql=sql):
+                res = await self.con.fetchval(sql)
+                self.assertEqual(res, expected)
+
+        with self.assertRaises(asyncpg.ProgramLimitExceededError):
+            await self.con.fetchval("SELECT '{{{{{{{1}}}}}}}'::int[]")
+
+        cases = [
+            [None],
+            [1, 2, 3, 4, 5, 6],
+            [[1, 2], [4, 5], [6, 7]],
+            [[[1], [2]], [[4], [5]], [[None], [7]]],
+            [[[[[[1]]]]]],
+            [[[[[[None]]]]]]
+        ]
+
+        st = await self.con.prepare(
+            "SELECT $1::int[]"
+        )
+
+        for case in cases:
+            with self.subTest(case=case):
+                result = await st.fetchval(case)
+                err_msg = (
+                    "failed to return array data as-is; "
+                    "gave {!r}, received {!r}".format(
+                        case, result))
+
+                self.assertEqual(result, case, err_msg)
+
+        # A sized iterable is fine as array input.
+        class Iterable:
+            def __iter__(self):
+                return iter([1, 2, 3])
+
+            def __len__(self):
+                return 3
+
+        result = await self.con.fetchval("SELECT $1::int[]", Iterable())
+        self.assertEqual(result, [1, 2, 3])
+
+        # A pure container is _not_ OK for array input.
+        class SomeContainer:
+            def __contains__(self, item):
+                return False
+
+        with self.assertRaisesRegex(asyncpg.DataError,
+                                    'sized iterable container expected'):
+            result = await self.con.fetchval("SELECT $1::int[]",
+                                             SomeContainer())
+
+        with self.assertRaisesRegex(asyncpg.DataError, 'dimensions'):
+            await self.con.fetchval(
+                "SELECT $1::int[]",
+                [[[[[[[1]]]]]]])
+
+        with self.assertRaisesRegex(asyncpg.DataError, 'non-homogeneous'):
+            await self.con.fetchval(
+                "SELECT $1::int[]",
+                [1, [1]])
+
+        with self.assertRaisesRegex(asyncpg.DataError, 'non-homogeneous'):
+            await self.con.fetchval(
+                "SELECT $1::int[]",
+                [[1], 1, [2]])
+
+        with self.assertRaisesRegex(asyncpg.DataError,
+                                    'invalid array element'):
+            await self.con.fetchval(
+                "SELECT $1::int[]",
+                [1, 't', 2])
+
+        with self.assertRaisesRegex(asyncpg.DataError,
+                                    'invalid array element'):
+            await self.con.fetchval(
+                "SELECT $1::int[]",
+                [[1], ['t'], [2]])
+
+        with self.assertRaisesRegex(asyncpg.DataError,
+                                    'sized iterable container expected'):
+            await self.con.fetchval(
+                "SELECT $1::int[]",
+                1)
+
+    async def test_composites(self):
+        """Test encoding/decoding of composite types."""
+        await self.con.execute('''
+            CREATE TYPE test_composite AS (
+                a int,
+                b text,
+                c int[]
+            )
+        ''')
+
+        st = await self.con.prepare('''
+            SELECT ROW(NULL, 1234, '5678', ROW(42, '42'))
+        ''')
+
+        res = await st.fetchval()
+
+        self.assertEqual(res, (None, 1234, '5678', (42, '42')))
+
+        try:
+            st = await self.con.prepare('''
+                SELECT ROW(
+                    NULL,
+                    '5678',
+                    ARRAY[9, NULL, 11]::int[]
+                )::test_composite AS test
+            ''')
+
+            res = await st.fetch()
+            res = res[0]['test']
+
+            self.assertIsNone(res['a'])
+            self.assertEqual(res['b'], '5678')
+            self.assertEqual(res['c'], [9, None, 11])
+
+            self.assertIsNone(res[0])
+            self.assertEqual(res[1], '5678')
+            self.assertEqual(res[2], [9, None, 11])
+
+            at = st.get_attributes()
+            self.assertEqual(len(at), 1)
+            self.assertEqual(at[0].name, 'test')
+            self.assertEqual(at[0].type.name, 'test_composite')
+            self.assertEqual(at[0].type.kind, 'composite')
+
+            res = await self.con.fetchval('''
+                SELECT $1::test_composite
+            ''', res)
+
+            # composite input as a mapping
+            res = await self.con.fetchval('''
+                SELECT $1::test_composite
+            ''', {'b': 'foo', 'a': 1, 'c': [1, 2, 3]})
+
+            self.assertEqual(res, (1, 'foo', [1, 2, 3]))
+
+            # Test None padding
+            res = await self.con.fetchval('''
+                SELECT $1::test_composite
+            ''', {'a': 1})
+
+            self.assertEqual(res, (1, None, None))
+
+            with self.assertRaisesRegex(
+                    asyncpg.DataError,
+                    "'bad' is not a valid element"):
+                await self.con.fetchval(
+                    "SELECT $1::test_composite",
+                    {'bad': 'foo'})
+
+        finally:
+            await self.con.execute('DROP TYPE test_composite')
+
+    async def test_domains(self):
+        """Test encoding/decoding of composite types."""
+        await self.con.execute('''
+            CREATE DOMAIN my_dom AS int
+        ''')
+
+        await self.con.execute('''
+            CREATE DOMAIN my_dom2 AS my_dom
+        ''')
+
+        try:
+            st = await self.con.prepare('''
+                SELECT 3::my_dom2
+            ''')
+            res = await st.fetchval()
+
+            self.assertEqual(res, 3)
+
+            st = await self.con.prepare('''
+                SELECT NULL::my_dom2
+            ''')
+            res = await st.fetchval()
+
+            self.assertIsNone(res)
+
+            at = st.get_attributes()
+            self.assertEqual(len(at), 1)
+            self.assertEqual(at[0].name, 'my_dom2')
+            self.assertEqual(at[0].type.name, 'int4')
+            self.assertEqual(at[0].type.kind, 'scalar')
+
+        finally:
+            await self.con.execute('DROP DOMAIN my_dom2')
+            await self.con.execute('DROP DOMAIN my_dom')
+
+    async def test_range_types(self):
+        """Test encoding/decoding of range types."""
+
+        cases = [
+            ('int4range', [
+                [(1, 9), asyncpg.Range(1, 10)],
+                [asyncpg.Range(0, 9, lower_inc=False, upper_inc=True),
+                 asyncpg.Range(1, 10)],
+                [(), asyncpg.Range(empty=True)],
+                [asyncpg.Range(empty=True), asyncpg.Range(empty=True)],
+                [(None, 2), asyncpg.Range(None, 3)],
+                [asyncpg.Range(None, 2, upper_inc=True),
+                 asyncpg.Range(None, 3)],
+                [(2,), asyncpg.Range(2, None)],
+                [(2, None), asyncpg.Range(2, None)],
+                [asyncpg.Range(2, None), asyncpg.Range(2, None)],
+                [(None, None), asyncpg.Range(None, None)],
+                [asyncpg.Range(None, None), asyncpg.Range(None, None)]
+            ])
+        ]
+
+        for (typname, sample_data) in cases:
+            st = await self.con.prepare(
+                "SELECT $1::" + typname
+            )
+
+            for sample, expected in sample_data:
+                with self.subTest(sample=sample, typname=typname):
+                    result = await st.fetchval(sample)
+                    self.assertEqual(result, expected)
+
+        with self.assertRaisesRegex(
+                asyncpg.DataError, 'list, tuple or Range object expected'):
+            await self.con.fetch("SELECT $1::int4range", 'aa')
+
+        with self.assertRaisesRegex(
+                asyncpg.DataError, 'expected 0, 1 or 2 elements'):
+            await self.con.fetch("SELECT $1::int4range", (0, 2, 3))
+
+        cases = [(asyncpg.Range(0, 1), asyncpg.Range(0, 1), 1),
+                 (asyncpg.Range(0, 1), asyncpg.Range(0, 2), 2),
+                 (asyncpg.Range(empty=True), asyncpg.Range(0, 2), 2),
+                 (asyncpg.Range(empty=True), asyncpg.Range(empty=True), 1),
+                 (asyncpg.Range(0, 1, upper_inc=True), asyncpg.Range(0, 1), 2),
+                 ]
+        for obj_a, obj_b, count in cases:
+            dic = {obj_a: 1, obj_b: 2}
+            self.assertEqual(len(dic), count)
+
+    async def test_extra_codec_alias(self):
+        """Test encoding/decoding of a builtin non-pg_catalog codec."""
+        await self.con.execute('''
+            CREATE DOMAIN my_dec_t AS decimal;
+            CREATE EXTENSION IF NOT EXISTS hstore;
+            CREATE TYPE rec_t AS ( i my_dec_t, h hstore );
+        ''')
+
+        try:
+            await self.con.set_builtin_type_codec(
+                'hstore', codec_name='pg_contrib.hstore')
+
+            cases = [
+                {'ham': 'spam', 'nada': None},
+                {}
+            ]
+
+            st = await self.con.prepare('''
+                SELECT $1::hstore AS result
+            ''')
+
+            for case in cases:
+                res = await st.fetchval(case)
+                self.assertEqual(res, case)
+
+            res = await self.con.fetchval('''
+                SELECT $1::hstore AS result
+            ''', (('foo', '2'), ('bar', '3')))
+
+            self.assertEqual(res, {'foo': '2', 'bar': '3'})
+
+            with self.assertRaisesRegex(asyncpg.DataError,
+                                        'null value not allowed'):
+                await self.con.fetchval('''
+                    SELECT $1::hstore AS result
+                ''', {None: '1'})
+
+            await self.con.set_builtin_type_codec(
+                'my_dec_t', codec_name='decimal')
+
+            res = await self.con.fetchval('''
+                SELECT $1::my_dec_t AS result
+            ''', 44)
+
+            self.assertEqual(res, 44)
+
+            # Both my_dec_t and hstore are decoded in binary
+            res = await self.con.fetchval('''
+                SELECT ($1::my_dec_t, 'a=>1'::hstore)::rec_t AS result
+            ''', 44)
+
+            self.assertEqual(res, (44, {'a': '1'}))
+
+            # Now, declare only the text format for my_dec_t
+            await self.con.reset_type_codec('my_dec_t')
+            await self.con.set_builtin_type_codec(
+                'my_dec_t', codec_name='decimal', format='text')
+
+            # This should fail, as there is no binary codec for
+            # my_dec_t and text decoding of composites is not
+            # implemented.
+            with self.assertRaises(NotImplementedError):
+                res = await self.con.fetchval('''
+                    SELECT ($1::my_dec_t, 'a=>1'::hstore)::rec_t AS result
+                ''', 44)
+
+        finally:
+            await self.con.execute('''
+                DROP TYPE rec_t;
+                DROP EXTENSION hstore;
+                DROP DOMAIN my_dec_t;
+            ''')
+
+    async def test_custom_codec_text(self):
+        """Test encoding/decoding using a custom codec in text mode."""
+        await self.con.execute('''
+            CREATE EXTENSION IF NOT EXISTS hstore
+        ''')
+
+        def hstore_decoder(data):
+            result = {}
+            items = data.split(',')
+            for item in items:
+                k, _, v = item.partition('=>')
+                result[k.strip('"')] = v.strip('"')
+
+            return result
+
+        def hstore_encoder(obj):
+            return ','.join('{}=>{}'.format(k, v) for k, v in obj.items())
+
+        try:
+            await self.con.set_type_codec('hstore', encoder=hstore_encoder,
+                                          decoder=hstore_decoder)
+
+            st = await self.con.prepare('''
+                SELECT $1::hstore AS result
+            ''')
+
+            res = await st.fetchrow({'ham': 'spam'})
+            res = res['result']
+
+            self.assertEqual(res, {'ham': 'spam'})
+
+            pt = st.get_parameters()
+            self.assertTrue(isinstance(pt, tuple))
+            self.assertEqual(len(pt), 1)
+            self.assertEqual(pt[0].name, 'hstore')
+            self.assertEqual(pt[0].kind, 'scalar')
+            self.assertEqual(pt[0].schema, 'public')
+
+            at = st.get_attributes()
+            self.assertTrue(isinstance(at, tuple))
+            self.assertEqual(len(at), 1)
+            self.assertEqual(at[0].name, 'result')
+            self.assertEqual(at[0].type, pt[0])
+
+            err = 'cannot use custom codec on non-scalar type public._hstore'
+            with self.assertRaisesRegex(ValueError, err):
+                await self.con.set_type_codec('_hstore',
+                                              encoder=hstore_encoder,
+                                              decoder=hstore_decoder)
+
+            await self.con.execute('''
+                CREATE TYPE mytype AS (a int);
+            ''')
+
+            try:
+                err = 'cannot use custom codec on non-scalar type ' + \
+                      'public.mytype'
+                with self.assertRaisesRegex(ValueError, err):
+                    await self.con.set_type_codec(
+                        'mytype', encoder=hstore_encoder,
+                        decoder=hstore_decoder)
+            finally:
+                await self.con.execute('''
+                    DROP TYPE mytype;
+                ''')
+
+        finally:
+            await self.con.execute('''
+                DROP EXTENSION hstore
+            ''')
+
+    async def test_custom_codec_binary(self):
+        """Test encoding/decoding using a custom codec in binary mode."""
+        await self.con.execute('''
+            CREATE EXTENSION IF NOT EXISTS hstore
+        ''')
+
+        longstruct = struct.Struct('!L')
+        ulong_unpack = lambda b: longstruct.unpack_from(b)[0]
+        ulong_pack = longstruct.pack
+
+        def hstore_decoder(data):
+            result = {}
+            n = ulong_unpack(data)
+            view = memoryview(data)
+            ptr = 4
+
+            for i in range(n):
+                klen = ulong_unpack(view[ptr:ptr + 4])
+                ptr += 4
+                k = bytes(view[ptr:ptr + klen]).decode()
+                ptr += klen
+                vlen = ulong_unpack(view[ptr:ptr + 4])
+                ptr += 4
+                if vlen == -1:
+                    v = None
+                else:
+                    v = bytes(view[ptr:ptr + vlen]).decode()
+                    ptr += vlen
+
+                result[k] = v
+
+            return result
+
+        def hstore_encoder(obj):
+            buffer = bytearray(ulong_pack(len(obj)))
+
+            for k, v in obj.items():
+                kenc = k.encode()
+                buffer += ulong_pack(len(kenc)) + kenc
+
+                if v is None:
+                    buffer += b'\xFF\xFF\xFF\xFF'  # -1
+                else:
+                    venc = v.encode()
+                    buffer += ulong_pack(len(venc)) + venc
+
+            return buffer
+
+        try:
+            await self.con.set_type_codec('hstore', encoder=hstore_encoder,
+                                          decoder=hstore_decoder,
+                                          format='binary')
+
+            st = await self.con.prepare('''
+                SELECT $1::hstore AS result
+            ''')
+
+            res = await st.fetchrow({'ham': 'spam'})
+            res = res['result']
+
+            self.assertEqual(res, {'ham': 'spam'})
+
+            pt = st.get_parameters()
+            self.assertTrue(isinstance(pt, tuple))
+            self.assertEqual(len(pt), 1)
+            self.assertEqual(pt[0].name, 'hstore')
+            self.assertEqual(pt[0].kind, 'scalar')
+            self.assertEqual(pt[0].schema, 'public')
+
+            at = st.get_attributes()
+            self.assertTrue(isinstance(at, tuple))
+            self.assertEqual(len(at), 1)
+            self.assertEqual(at[0].name, 'result')
+            self.assertEqual(at[0].type, pt[0])
+
+        finally:
+            await self.con.execute('''
+                DROP EXTENSION hstore
+            ''')
+
+    async def test_custom_codec_on_domain(self):
+        """Test encoding/decoding using a custom codec on a domain."""
+        await self.con.execute('''
+            CREATE DOMAIN custom_codec_t AS int
+        ''')
+
+        try:
+            await self.con.set_type_codec(
+                'custom_codec_t',
+                encoder=lambda v: str(v),
+                decoder=lambda v: int(v))
+
+            v = await self.con.fetchval('SELECT $1::custom_codec_t', 10)
+            self.assertEqual(v, 10)
+        finally:
+            await self.con.execute('DROP DOMAIN custom_codec_t')
+
+    async def test_custom_codec_on_enum(self):
+        """Test encoding/decoding using a custom codec on an enum."""
+        await self.con.execute('''
+            CREATE TYPE custom_codec_t AS ENUM ('foo', 'bar', 'baz')
+        ''')
+
+        try:
+            await self.con.set_type_codec(
+                'custom_codec_t',
+                encoder=lambda v: str(v).lstrip('enum :'),
+                decoder=lambda v: 'enum: ' + str(v))
+
+            v = await self.con.fetchval('SELECT $1::custom_codec_t', 'foo')
+            self.assertEqual(v, 'enum: foo')
+        finally:
+            await self.con.execute('DROP TYPE custom_codec_t')
+
+    async def test_custom_codec_override_binary(self):
+        """Test overriding core codecs."""
+        import json
+
+        conn = await self.connect()
+        try:
+            def _encoder(value):
+                return json.dumps(value).encode('utf-8')
+
+            def _decoder(value):
+                return json.loads(value.decode('utf-8'))
+
+            await conn.set_type_codec(
+                'json', encoder=_encoder, decoder=_decoder,
+                schema='pg_catalog', format='binary'
+            )
+
+            data = {'foo': 'bar', 'spam': 1}
+            res = await conn.fetchval('SELECT $1::json', data)
+            self.assertEqual(data, res)
+
+        finally:
+            await conn.close()
+
+    async def test_custom_codec_override_text(self):
+        """Test overriding core codecs."""
+        import json
+
+        conn = await self.connect()
+        try:
+            def _encoder(value):
+                return json.dumps(value)
+
+            def _decoder(value):
+                return json.loads(value)
+
+            await conn.set_type_codec(
+                'json', encoder=_encoder, decoder=_decoder,
+                schema='pg_catalog', format='text'
+            )
+
+            data = {'foo': 'bar', 'spam': 1}
+            res = await conn.fetchval('SELECT $1::json', data)
+            self.assertEqual(data, res)
+
+            def _encoder(value):
+                return value
+
+            def _decoder(value):
+                return value
+
+            await conn.set_type_codec(
+                'uuid', encoder=_encoder, decoder=_decoder,
+                schema='pg_catalog', format='text'
+            )
+
+            data = '14058ad9-0118-4b7e-ac15-01bc13e2ccd1'
+            res = await conn.fetchval('SELECT $1::uuid', data)
+            self.assertEqual(res, data)
+        finally:
+            await conn.close()
+
+    async def test_custom_codec_override_tuple(self):
+        """Test overriding core codecs."""
+        cases = [
+            ('date', (3,), '2000-01-04'),
+            ('date', (2**31 - 1,), 'infinity'),
+            ('date', (-2**31,), '-infinity'),
+            ('time', (60 * 10**6,), '00:01:00'),
+            ('timetz', (60 * 10**6, 12600), '00:01:00-03:30'),
+            ('timestamp', (60 * 10**6,), '2000-01-01 00:01:00'),
+            ('timestamp', (2**63 - 1,), 'infinity'),
+            ('timestamp', (-2**63,), '-infinity'),
+            ('timestamptz', (60 * 10**6,), '1999-12-31 19:01:00',
+                "tab.v AT TIME ZONE 'EST'"),
+            ('timestamptz', (2**63 - 1,), 'infinity'),
+            ('timestamptz', (-2**63,), '-infinity'),
+            ('interval', (2, 3, 1), '2 mons 3 days 00:00:00.000001')
+        ]
+
+        conn = await self.connect()
+
+        def _encoder(value):
+            return tuple(value)
+
+        def _decoder(value):
+            return tuple(value)
+
+        try:
+            for (typename, data, expected_result, *extra) in cases:
+                with self.subTest(type=typename):
+                    await self.con.execute(
+                        'CREATE TABLE tab (v {})'.format(typename))
+
+                    try:
+                        await conn.set_type_codec(
+                            typename, encoder=_encoder, decoder=_decoder,
+                            schema='pg_catalog', format='tuple'
+                        )
+
+                        await conn.execute(
+                            'INSERT INTO tab VALUES ($1)', data)
+
+                        res = await conn.fetchval('SELECT tab.v FROM tab')
+                        self.assertEqual(res, data)
+
+                        await conn.reset_type_codec(
+                            typename, schema='pg_catalog')
+
+                        if extra:
+                            val = extra[0]
+                        else:
+                            val = 'tab.v'
+
+                        res = await conn.fetchval(
+                            'SELECT ({val})::text FROM tab'.format(val=val))
+                        self.assertEqual(res, expected_result)
+                    finally:
+                        await self.con.execute('DROP TABLE tab')
+        finally:
+            await conn.close()
+
+    async def test_timetz_encoding(self):
+        try:
+            async with self.con.transaction():
+                await self.con.execute("SET TIME ZONE 'America/Toronto'")
+                # Check decoding:
+                row = await self.con.fetchrow(
+                    'SELECT extract(epoch from now()) AS epoch, '
+                    'now()::date as date, now()::timetz as time')
+                result = datetime.datetime.combine(row['date'], row['time'])
+                expected = datetime.datetime.fromtimestamp(row['epoch'],
+                                                           tz=result.tzinfo)
+                self.assertEqual(result, expected)
+
+                # Check encoding:
+                res = await self.con.fetchval(
+                    'SELECT now() = ($1::date + $2::timetz)',
+                    row['date'], row['time'])
+                self.assertTrue(res)
+        finally:
+            await self.con.execute('RESET ALL')
+
+    async def test_composites_in_arrays(self):
+        await self.con.execute('''
+            CREATE TYPE t AS (a text, b int);
+            CREATE TABLE tab (d t[]);
+        ''')
+
+        try:
+            await self.con.execute(
+                'INSERT INTO tab (d) VALUES ($1)',
+                [('a', 1)])
+
+            r = await self.con.fetchval('''
+                SELECT d FROM tab
+            ''')
+
+            self.assertEqual(r, [('a', 1)])
+        finally:
+            await self.con.execute('''
+                DROP TABLE tab;
+                DROP TYPE t;
+            ''')
+
+    async def test_table_as_composite(self):
+        await self.con.execute('''
+            CREATE TABLE tab (a text, b int);
+            INSERT INTO tab VALUES ('1', 1);
+        ''')
+
+        try:
+            r = await self.con.fetchrow('''
+                SELECT tab FROM tab
+            ''')
+
+            self.assertEqual(r, (('1', 1),))
+
+        finally:
+            await self.con.execute('''
+                DROP TABLE tab;
+            ''')
+
+    async def test_relacl_array_type(self):
+        await self.con.execute(r'''
+            CREATE USER """u1'";
+            CREATE USER "{u2";
+            CREATE USER ",u3";
+            CREATE USER "u4}";
+            CREATE USER "u5""";
+            CREATE USER "u6\""";
+            CREATE USER "u7\";
+            CREATE USER norm1;
+            CREATE USER norm2;
+            CREATE TABLE t0 (); GRANT SELECT ON t0 TO norm1;
+            CREATE TABLE t1 (); GRANT SELECT ON t1 TO """u1'";
+            CREATE TABLE t2 (); GRANT SELECT ON t2 TO "{u2";
+            CREATE TABLE t3 (); GRANT SELECT ON t3 TO ",u3";
+            CREATE TABLE t4 (); GRANT SELECT ON t4 TO "u4}";
+            CREATE TABLE t5 (); GRANT SELECT ON t5 TO "u5""";
+            CREATE TABLE t6 (); GRANT SELECT ON t6 TO "u6\""";
+            CREATE TABLE t7 (); GRANT SELECT ON t7 TO "u7\";
+
+            CREATE TABLE a1 ();
+                GRANT SELECT ON a1 TO """u1'";
+                GRANT SELECT ON a1 TO "{u2";
+                GRANT SELECT ON a1 TO ",u3";
+                GRANT SELECT ON a1 TO "norm1";
+                GRANT SELECT ON a1 TO "u4}";
+                GRANT SELECT ON a1 TO "u5""";
+                GRANT SELECT ON a1 TO "u6\""";
+                GRANT SELECT ON a1 TO "u7\";
+                GRANT SELECT ON a1 TO "norm2";
+
+            CREATE TABLE a2 ();
+                GRANT SELECT ON a2 TO """u1'" WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO "{u2"   WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO ",u3"   WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO "norm1" WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO "u4}"   WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO "u5"""  WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO "u6\""" WITH GRANT OPTION;
+                GRANT SELECT ON a2 TO "u7\"   WITH GRANT OPTION;
+
+            SET SESSION AUTHORIZATION """u1'"; GRANT SELECT ON a2 TO "norm2";
+            SET SESSION AUTHORIZATION "{u2";   GRANT SELECT ON a2 TO "norm2";
+            SET SESSION AUTHORIZATION ",u3";   GRANT SELECT ON a2 TO "norm2";
+            SET SESSION AUTHORIZATION "u4}";   GRANT SELECT ON a2 TO "norm2";
+            SET SESSION AUTHORIZATION "u5""";  GRANT SELECT ON a2 TO "norm2";
+            SET SESSION AUTHORIZATION "u6\"""; GRANT SELECT ON a2 TO "norm2";
+            SET SESSION AUTHORIZATION "u7\";   GRANT SELECT ON a2 TO "norm2";
+            RESET SESSION AUTHORIZATION;
+        ''')
+
+        try:
+            rows = await self.con.fetch('''
+                SELECT
+                    relacl,
+                    relacl::text[] AS chk,
+                    relacl::text[]::text AS text_
+                FROM
+                    pg_catalog.pg_class
+                WHERE
+                    relacl IS NOT NULL
+            ''')
+
+            for row in rows:
+                self.assertEqual(row['relacl'], row['chk'],)
+
+        finally:
+            await self.con.execute(r'''
+                DROP TABLE t0;
+                DROP TABLE t1;
+                DROP TABLE t2;
+                DROP TABLE t3;
+                DROP TABLE t4;
+                DROP TABLE t5;
+                DROP TABLE t6;
+                DROP TABLE t7;
+                DROP TABLE a1;
+                DROP TABLE a2;
+                DROP USER """u1'";
+                DROP USER "{u2";
+                DROP USER ",u3";
+                DROP USER "u4}";
+                DROP USER "u5""";
+                DROP USER "u6\""";
+                DROP USER "u7\";
+                DROP USER norm1;
+                DROP USER norm2;
+            ''')
+
+    async def test_enum(self):
+        await self.con.execute('''
+            CREATE TYPE enum_t AS ENUM ('abc', 'def', 'ghi');
+            CREATE TABLE tab (
+                a text,
+                b enum_t
+            );
+            INSERT INTO tab (a, b) VALUES ('foo', 'abc');
+            INSERT INTO tab (a, b) VALUES ('bar', 'def');
+        ''')
+
+        try:
+            for i in range(10):
+                r = await self.con.fetch('''
+                    SELECT a, b FROM tab ORDER BY b
+                ''')
+
+                self.assertEqual(r, [('foo', 'abc'), ('bar', 'def')])
+
+        finally:
+            await self.con.execute('''
+                DROP TABLE tab;
+                DROP TYPE enum_t;
+            ''')
+
+    async def test_unknown_type_text_fallback(self):
+        await self.con.execute(r'CREATE EXTENSION citext')
+        await self.con.execute(r'''
+            CREATE DOMAIN citext_dom AS citext
+        ''')
+        await self.con.execute(r'''
+            CREATE TYPE citext_range AS RANGE (SUBTYPE = citext)
+        ''')
+        await self.con.execute(r'''
+            CREATE TYPE citext_comp AS (t citext)
+        ''')
+
+        try:
+            # Check that plain fallback works.
+            result = await self.con.fetchval('''
+                SELECT $1::citext
+            ''', 'citext')
+
+            self.assertEqual(result, 'citext')
+
+            # Check that domain fallback works.
+            result = await self.con.fetchval('''
+                SELECT $1::citext_dom
+            ''', 'citext')
+
+            self.assertEqual(result, 'citext')
+
+            # Check that array fallback works.
+            cases = [
+                ['a', 'b'],
+                [None, 'b'],
+                [],
+                ['  a', '  b'],
+                ['"a', r'\""'],
+                [['"a', r'\""'], [',', '",']],
+            ]
+
+            for case in cases:
+                result = await self.con.fetchval('''
+                    SELECT
+                        $1::citext[]
+                ''', case)
+
+                self.assertEqual(result, case)
+
+            # Text encoding of ranges and composite types
+            # is not supported yet.
+            with self.assertRaisesRegex(
+                    RuntimeError,
+                    'text encoding of range types is not supported'):
+
+                await self.con.fetchval('''
+                    SELECT
+                        $1::citext_range
+                ''', ['a', 'z'])
+
+            with self.assertRaisesRegex(
+                    RuntimeError,
+                    'text encoding of composite types is not supported'):
+
+                await self.con.fetchval('''
+                    SELECT
+                        $1::citext_comp
+                ''', ('a',))
+
+            # Check that setting a custom codec clears the codec
+            # cache properly and that subsequent queries work
+            # as expected.
+            await self.con.set_type_codec(
+                'citext', encoder=lambda d: d, decoder=lambda d: 'CI: ' + d)
+
+            result = await self.con.fetchval('''
+                SELECT
+                    $1::citext[]
+            ''', ['a', 'b'])
+
+            self.assertEqual(result, ['CI: a', 'CI: b'])
+
+        finally:
+            await self.con.execute(r'DROP TYPE citext_comp')
+            await self.con.execute(r'DROP TYPE citext_range')
+            await self.con.execute(r'DROP TYPE citext_dom')
+            await self.con.execute(r'DROP EXTENSION citext')
+
+    async def test_enum_in_array(self):
+        await self.con.execute('''
+            CREATE TYPE enum_t AS ENUM ('abc', 'def', 'ghi');
+        ''')
+
+        try:
+            result = await self.con.fetchrow('''SELECT $1::enum_t[];''',
+                                             ['abc'])
+            self.assertEqual(result, (['abc'],))
+
+            result = await self.con.fetchrow('''SELECT ARRAY[$1::enum_t];''',
+                                             'abc')
+
+            self.assertEqual(result, (['abc'],))
+
+        finally:
+            await self.con.execute('''
+                DROP TYPE enum_t;
+            ''')
+
+    async def test_enum_and_range(self):
+        await self.con.execute('''
+            CREATE TYPE enum_t AS ENUM ('abc', 'def', 'ghi');
+            CREATE TABLE testtab (
+                a int4range,
+                b enum_t
+            );
+
+            INSERT INTO testtab VALUES (
+                '[10, 20)', 'abc'
+            );
+        ''')
+
+        try:
+            result = await self.con.fetchrow('''
+                SELECT testtab.a FROM testtab WHERE testtab.b = $1
+            ''', 'abc')
+
+            self.assertEqual(result, (asyncpg.Range(10, 20),))
+        finally:
+            await self.con.execute('''
+                DROP TABLE testtab;
+                DROP TYPE enum_t;
+            ''')
+
+    async def test_enum_in_composite(self):
+        await self.con.execute('''
+            CREATE TYPE enum_t AS ENUM ('abc', 'def', 'ghi');
+            CREATE TYPE composite_w_enum AS (a int, b enum_t);
+        ''')
+
+        try:
+            result = await self.con.fetchval('''
+                SELECT ROW(1, 'def'::enum_t)::composite_w_enum
+            ''')
+            self.assertEqual(set(result.items()), {('a', 1), ('b', 'def')})
+
+        finally:
+            await self.con.execute('''
+                DROP TYPE composite_w_enum;
+                DROP TYPE enum_t;
+            ''')
+
+    async def test_enum_function_return(self):
+        await self.con.execute('''
+            CREATE TYPE enum_t AS ENUM ('abc', 'def', 'ghi');
+            CREATE FUNCTION return_enum() RETURNS enum_t
+            LANGUAGE plpgsql AS $$
+            BEGIN
+                RETURN 'abc'::enum_t;
+            END;
+            $$;
+        ''')
+
+        try:
+            result = await self.con.fetchval('''SELECT return_enum()''')
+            self.assertEqual(result, 'abc')
+
+        finally:
+            await self.con.execute('''
+                DROP FUNCTION return_enum();
+                DROP TYPE enum_t;
+            ''')
+
+    async def test_no_result(self):
+        st = await self.con.prepare('rollback')
+        self.assertTupleEqual(st.get_attributes(), ())
+
+
+@unittest.skipIf(os.environ.get('PGHOST'), 'using remote cluster for testing')
+class TestCodecsLargeOIDs(tb.ConnectedTestCase):
+    LARGE_OID = 2147483648
+
+    @classmethod
+    def setup_cluster(cls):
+        cls.cluster = cls.new_cluster(pg_cluster.TempCluster)
+        cls.cluster.reset_wal(oid=cls.LARGE_OID)
+        cls.start_cluster(cls.cluster)
+
+    async def test_custom_codec_large_oid(self):
+        await self.con.execute('CREATE DOMAIN test_domain_t AS int')
+        try:
+            oid = await self.con.fetchval('''
+                SELECT oid FROM pg_type WHERE typname = 'test_domain_t'
+            ''')
+
+            expected_oid = self.LARGE_OID
+            if self.server_version >= (11, 0):
+                # PostgreSQL 11 automatically create a domain array type
+                # _before_ the domain type, so the expected OID is
+                # off by one.
+                expected_oid += 1
+
+            self.assertEqual(oid, expected_oid)
+
+            # Test that introspection handles large OIDs
+            v = await self.con.fetchval('SELECT $1::test_domain_t', 10)
+            self.assertEqual(v, 10)
+
+            # Test that custom codec logic handles large OIDs
+            await self.con.set_type_codec(
+                'test_domain_t',
+                encoder=lambda v: str(v),
+                decoder=lambda v: int(v))
+
+            v = await self.con.fetchval('SELECT $1::test_domain_t', 10)
+            self.assertEqual(v, 10)
+
+        finally:
+            await self.con.execute('DROP DOMAIN test_domain_t')
diff --git a/tests/test_connect.py b/tests/test_connect.py
new file mode 100644 (file)
index 0000000..1ad457e
--- /dev/null
@@ -0,0 +1,1114 @@
+# 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
+
+
+import asyncio
+import contextlib
+import gc
+import ipaddress
+import os
+import platform
+import ssl
+import stat
+import tempfile
+import textwrap
+import unittest
+import weakref
+
+import asyncpg
+from asyncpg import _testbase as tb
+from asyncpg import connection
+from asyncpg import connect_utils
+from asyncpg import cluster as pg_cluster
+from asyncpg import exceptions
+from asyncpg.serverversion import split_server_version_string
+
+_system = platform.uname().system
+
+
+CERTS = os.path.join(os.path.dirname(__file__), 'certs')
+SSL_CA_CERT_FILE = os.path.join(CERTS, 'ca.cert.pem')
+SSL_CERT_FILE = os.path.join(CERTS, 'server.cert.pem')
+SSL_KEY_FILE = os.path.join(CERTS, 'server.key.pem')
+
+
+class TestSettings(tb.ConnectedTestCase):
+
+    async def test_get_settings_01(self):
+        self.assertEqual(
+            self.con.get_settings().client_encoding,
+            'UTF8')
+
+    async def test_server_version_01(self):
+        version = self.con.get_server_version()
+        version_num = await self.con.fetchval("SELECT current_setting($1)",
+                                              'server_version_num', column=0)
+        ver_maj = int(version_num[:-4])
+        ver_min = int(version_num[-4:-2])
+        ver_fix = int(version_num[-2:])
+
+        self.assertEqual(version[:3], (ver_maj, ver_min, ver_fix))
+
+    def test_server_version_02(self):
+        versions = [
+            ("9.2", (9, 2, 0, 'final', 0),),
+            ("Postgres-XL 9.2.1", (9, 2, 1, 'final', 0),),
+            ("9.4beta1", (9, 4, 0, 'beta', 1),),
+            ("10devel", (10, 0, 0, 'devel', 0),),
+            ("10beta2", (10, 0, 0, 'beta', 2),),
+            # For PostgreSQL versions >=10 we always
+            # set version.minor to 0.
+            ("10.1", (10, 0, 1, 'final', 0),),
+            ("11.1.2", (11, 0, 1, 'final', 0),),
+            ("PostgreSQL 10.1 (Debian 10.1-3)", (10, 0, 1, 'final', 0),),
+        ]
+        for version, expected in versions:
+            result = split_server_version_string(version)
+            self.assertEqual(expected, result)
+
+
+class TestAuthentication(tb.ConnectedTestCase):
+    def setUp(self):
+        super().setUp()
+
+        if not self.cluster.is_managed():
+            self.skipTest('unmanaged cluster')
+
+        methods = [
+            ('trust', None),
+            ('reject', None),
+            ('md5', 'correctpassword'),
+            ('password', 'correctpassword'),
+        ]
+
+        self.cluster.reset_hba()
+
+        create_script = []
+        for method, password in methods:
+            create_script.append(
+                'CREATE ROLE {}_user WITH LOGIN{};'.format(
+                    method,
+                    ' PASSWORD {!r}'.format(password) if password else ''
+                )
+            )
+
+            if _system != 'Windows':
+                self.cluster.add_hba_entry(
+                    type='local',
+                    database='postgres', user='{}_user'.format(method),
+                    auth_method=method)
+
+            self.cluster.add_hba_entry(
+                type='host', address=ipaddress.ip_network('127.0.0.0/24'),
+                database='postgres', user='{}_user'.format(method),
+                auth_method=method)
+
+            self.cluster.add_hba_entry(
+                type='host', address=ipaddress.ip_network('::1/128'),
+                database='postgres', user='{}_user'.format(method),
+                auth_method=method)
+
+        # Put hba changes into effect
+        self.cluster.reload()
+
+        create_script = '\n'.join(create_script)
+        self.loop.run_until_complete(self.con.execute(create_script))
+
+    def tearDown(self):
+        # Reset cluster's pg_hba.conf since we've meddled with it
+        self.cluster.trust_local_connections()
+
+        methods = [
+            'trust',
+            'reject',
+            'md5',
+            'password',
+        ]
+
+        drop_script = []
+        for method in methods:
+            drop_script.append('DROP ROLE {}_user;'.format(method))
+
+        drop_script = '\n'.join(drop_script)
+        self.loop.run_until_complete(self.con.execute(drop_script))
+
+        super().tearDown()
+
+    async def _try_connect(self, **kwargs):
+        # On Windows the server sometimes just closes
+        # the connection sooner than we receive the
+        # actual error.
+        if _system == 'Windows':
+            for tried in range(3):
+                try:
+                    return await self.connect(**kwargs)
+                except asyncpg.ConnectionDoesNotExistError:
+                    pass
+
+        return await self.connect(**kwargs)
+
+    async def test_auth_bad_user(self):
+        with self.assertRaises(
+                asyncpg.InvalidAuthorizationSpecificationError):
+            await self._try_connect(user='__nonexistent__')
+
+    async def test_auth_trust(self):
+        conn = await self.connect(user='trust_user')
+        await conn.close()
+
+    async def test_auth_reject(self):
+        with self.assertRaisesRegex(
+                asyncpg.InvalidAuthorizationSpecificationError,
+                'pg_hba.conf rejects connection'):
+            await self._try_connect(user='reject_user')
+
+    async def test_auth_password_cleartext(self):
+        conn = await self.connect(
+            user='password_user',
+            password='correctpassword')
+        await conn.close()
+
+        with self.assertRaisesRegex(
+                asyncpg.InvalidPasswordError,
+                'password authentication failed for user "password_user"'):
+            await self._try_connect(
+                user='password_user',
+                password='wrongpassword')
+
+    async def test_auth_password_md5(self):
+        conn = await self.connect(
+            user='md5_user', password='correctpassword')
+        await conn.close()
+
+        with self.assertRaisesRegex(
+                asyncpg.InvalidPasswordError,
+                'password authentication failed for user "md5_user"'):
+            await self._try_connect(
+                user='md5_user', password='wrongpassword')
+
+    async def test_auth_unsupported(self):
+        pass
+
+
+class TestConnectParams(tb.TestCase):
+
+    TESTS = [
+        {
+            'env': {
+                'PGUSER': 'user',
+                'PGDATABASE': 'testdb',
+                'PGPASSWORD': 'passw',
+                'PGHOST': 'host',
+                'PGPORT': '123'
+            },
+            'result': ([('host', 123)], {
+                'user': 'user',
+                'password': 'passw',
+                'database': 'testdb'})
+        },
+
+        {
+            'env': {
+                'PGUSER': 'user',
+                'PGDATABASE': 'testdb',
+                'PGPASSWORD': 'passw',
+                'PGHOST': 'host',
+                'PGPORT': '123'
+            },
+
+            'host': 'host2',
+            'port': '456',
+            'user': 'user2',
+            'password': 'passw2',
+            'database': 'db2',
+
+            'result': ([('host2', 456)], {
+                'user': 'user2',
+                'password': 'passw2',
+                'database': 'db2'})
+        },
+
+        {
+            'env': {
+                'PGUSER': 'user',
+                'PGDATABASE': 'testdb',
+                'PGPASSWORD': 'passw',
+                'PGHOST': 'host',
+                'PGPORT': '123',
+                'PGSSLMODE': 'prefer'
+            },
+
+            'dsn': 'postgres://user3:123123@localhost/abcdef',
+
+            'host': 'host2',
+            'port': '456',
+            'user': 'user2',
+            'password': 'passw2',
+            'database': 'db2',
+            'ssl': False,
+
+            'result': ([('host2', 456)], {
+                'user': 'user2',
+                'password': 'passw2',
+                'database': 'db2',
+                'ssl': False})
+        },
+
+        {
+            'env': {
+                'PGUSER': 'user',
+                'PGDATABASE': 'testdb',
+                'PGPASSWORD': 'passw',
+                'PGHOST': 'host',
+                'PGPORT': '123',
+                'PGSSLMODE': 'prefer'
+            },
+
+            'dsn': 'postgres://user3:123123@localhost:5555/abcdef',
+
+            'result': ([('localhost', 5555)], {
+                'user': 'user3',
+                'password': '123123',
+                'database': 'abcdef',
+                'ssl': ssl.SSLContext,
+                'ssl_is_advisory': True})
+        },
+
+        {
+            'dsn': 'postgres://user3:123123@localhost:5555/abcdef',
+            'result': ([('localhost', 5555)], {
+                'user': 'user3',
+                'password': '123123',
+                'database': 'abcdef'})
+        },
+
+        {
+            'dsn': 'postgresql://user@host1,host2/db',
+            'result': ([('host1', 5432), ('host2', 5432)], {
+                'database': 'db',
+                'user': 'user',
+            })
+        },
+
+        {
+            'dsn': 'postgresql://user@host1:1111,host2:2222/db',
+            'result': ([('host1', 1111), ('host2', 2222)], {
+                'database': 'db',
+                'user': 'user',
+            })
+        },
+
+        {
+            'env': {
+                'PGHOST': 'host1:1111,host2:2222',
+                'PGUSER': 'foo',
+            },
+            'dsn': 'postgresql:///db',
+            'result': ([('host1', 1111), ('host2', 2222)], {
+                'database': 'db',
+                'user': 'foo',
+            })
+        },
+
+        {
+            'env': {
+                'PGUSER': 'foo',
+            },
+            'dsn': 'postgresql:///db?host=host1:1111,host2:2222',
+            'result': ([('host1', 1111), ('host2', 2222)], {
+                'database': 'db',
+                'user': 'foo',
+            })
+        },
+
+        {
+            'env': {
+                'PGUSER': 'foo',
+            },
+            'dsn': 'postgresql:///db',
+            'host': ['host1', 'host2'],
+            'result': ([('host1', 5432), ('host2', 5432)], {
+                'database': 'db',
+                'user': 'foo',
+            })
+        },
+
+        {
+            'dsn': 'postgresql://user3:123123@localhost:5555/'
+                   'abcdef?param=sss&param=123&host=testhost&user=testuser'
+                   '&port=2222&database=testdb&sslmode=require',
+            'host': '127.0.0.1',
+            'port': '888',
+            'user': 'me',
+            'password': 'ask',
+            'database': 'db',
+            'result': ([('127.0.0.1', 888)], {
+                'server_settings': {'param': '123'},
+                'user': 'me',
+                'password': 'ask',
+                'database': 'db',
+                'ssl': ssl.SSLContext,
+                'ssl_is_advisory': False})
+        },
+
+        {
+            'dsn': 'postgresql://user3:123123@localhost:5555/'
+                   'abcdef?param=sss&param=123&host=testhost&user=testuser'
+                   '&port=2222&database=testdb&sslmode=disable',
+            'host': '127.0.0.1',
+            'port': '888',
+            'user': 'me',
+            'password': 'ask',
+            'database': 'db',
+            'server_settings': {'aa': 'bb'},
+            'ssl': True,
+            'result': ([('127.0.0.1', 888)], {
+                'server_settings': {'aa': 'bb', 'param': '123'},
+                'user': 'me',
+                'password': 'ask',
+                'database': 'db',
+                'ssl': True})
+        },
+
+        {
+            'dsn': 'postgresql:///dbname?host=/unix_sock/test&user=spam',
+            'result': ([os.path.join('/unix_sock/test', '.s.PGSQL.5432')], {
+                'user': 'spam',
+                'database': 'dbname'})
+        },
+
+        {
+            'dsn': 'pq:///dbname?host=/unix_sock/test&user=spam',
+            'error': (ValueError, 'invalid DSN')
+        },
+        {
+            'dsn': 'postgresql://host1,host2,host3/db',
+            'port': [111, 222],
+            'error': (
+                exceptions.InterfaceError,
+                'could not match 2 port numbers to 3 hosts'
+            )
+        },
+        {
+            'dsn': 'postgres://user@?port=56226&host=%2Ftmp',
+            'result': (
+                [os.path.join('/tmp', '.s.PGSQL.56226')],
+                {
+                    'user': 'user',
+                    'database': 'user',
+                }
+            )
+        },
+    ]
+
+    @contextlib.contextmanager
+    def environ(self, **kwargs):
+        old_vals = {}
+        for key in kwargs:
+            if key in os.environ:
+                old_vals[key] = os.environ[key]
+
+        for key, val in kwargs.items():
+            if val is None:
+                if key in os.environ:
+                    del os.environ[key]
+            else:
+                os.environ[key] = val
+
+        try:
+            yield
+        finally:
+            for key in kwargs:
+                if key in os.environ:
+                    del os.environ[key]
+            for key, val in old_vals.items():
+                os.environ[key] = val
+
+    def run_testcase(self, testcase):
+        env = testcase.get('env', {})
+        test_env = {'PGHOST': None, 'PGPORT': None,
+                    'PGUSER': None, 'PGPASSWORD': None,
+                    'PGDATABASE': None, 'PGSSLMODE': None}
+        test_env.update(env)
+
+        dsn = testcase.get('dsn')
+        user = testcase.get('user')
+        port = testcase.get('port')
+        host = testcase.get('host')
+        password = testcase.get('password')
+        passfile = testcase.get('passfile')
+        database = testcase.get('database')
+        ssl = testcase.get('ssl')
+        server_settings = testcase.get('server_settings')
+
+        expected = testcase.get('result')
+        expected_error = testcase.get('error')
+        if expected is None and expected_error is None:
+            raise RuntimeError(
+                'invalid test case: either "result" or "error" key '
+                'has to be specified')
+        if expected is not None and expected_error is not None:
+            raise RuntimeError(
+                'invalid test case: either "result" or "error" key '
+                'has to be specified, got both')
+
+        with contextlib.ExitStack() as es:
+            es.enter_context(self.subTest(dsn=dsn, env=env))
+            es.enter_context(self.environ(**test_env))
+
+            if expected_error:
+                es.enter_context(self.assertRaisesRegex(*expected_error))
+
+            addrs, params = connect_utils._parse_connect_dsn_and_args(
+                dsn=dsn, host=host, port=port, user=user, password=password,
+                passfile=passfile, database=database, ssl=ssl,
+                connect_timeout=None, server_settings=server_settings)
+
+            params = {k: v for k, v in params._asdict().items()
+                      if v is not None}
+
+            result = (addrs, params)
+
+        if expected is not None:
+            for k, v in expected[1].items():
+                # If `expected` contains a type, allow that to "match" any
+                # instance of that type tyat `result` may contain. We need
+                # this because different SSLContexts don't compare equal.
+                if isinstance(v, type) and isinstance(result[1].get(k), v):
+                    result[1][k] = v
+            self.assertEqual(expected, result, 'Testcase: {}'.format(testcase))
+
+    def test_test_connect_params_environ(self):
+        self.assertNotIn('AAAAAAAAAA123', os.environ)
+        self.assertNotIn('AAAAAAAAAA456', os.environ)
+        self.assertNotIn('AAAAAAAAAA789', os.environ)
+
+        try:
+
+            os.environ['AAAAAAAAAA456'] = '123'
+            os.environ['AAAAAAAAAA789'] = '123'
+
+            with self.environ(AAAAAAAAAA123='1',
+                              AAAAAAAAAA456='2',
+                              AAAAAAAAAA789=None):
+
+                self.assertEqual(os.environ['AAAAAAAAAA123'], '1')
+                self.assertEqual(os.environ['AAAAAAAAAA456'], '2')
+                self.assertNotIn('AAAAAAAAAA789', os.environ)
+
+            self.assertNotIn('AAAAAAAAAA123', os.environ)
+            self.assertEqual(os.environ['AAAAAAAAAA456'], '123')
+            self.assertEqual(os.environ['AAAAAAAAAA789'], '123')
+
+        finally:
+            for key in {'AAAAAAAAAA123', 'AAAAAAAAAA456', 'AAAAAAAAAA789'}:
+                if key in os.environ:
+                    del os.environ[key]
+
+    def test_test_connect_params_run_testcase(self):
+        with self.environ(PGPORT='777'):
+            self.run_testcase({
+                'env': {
+                    'PGUSER': '__test__'
+                },
+                'host': 'abc',
+                'result': (
+                    [('abc', 5432)],
+                    {'user': '__test__', 'database': '__test__'}
+                )
+            })
+
+    def test_connect_params(self):
+        for testcase in self.TESTS:
+            self.run_testcase(testcase)
+
+    def test_connect_pgpass_regular(self):
+        passfile = tempfile.NamedTemporaryFile('w+t', delete=False)
+        passfile.write(textwrap.dedent(R'''
+            abc:*:*:user:password from pgpass for user@abc
+            localhost:*:*:*:password from pgpass for localhost
+            cde:5433:*:*:password from pgpass for cde:5433
+
+            *:*:*:testuser:password from pgpass for testuser
+            *:*:testdb:*:password from pgpass for testdb
+            # comment
+            *:*:test\:db:test\\:password from pgpass with escapes
+        '''))
+        passfile.close()
+        os.chmod(passfile.name, stat.S_IWUSR | stat.S_IRUSR)
+
+        try:
+            # passfile path in env
+            self.run_testcase({
+                'env': {
+                    'PGPASSFILE': passfile.name
+                },
+                'host': 'abc',
+                'user': 'user',
+                'database': 'db',
+                'result': (
+                    [('abc', 5432)],
+                    {
+                        'password': 'password from pgpass for user@abc',
+                        'user': 'user',
+                        'database': 'db',
+                    }
+                )
+            })
+
+            # passfile path as explicit arg
+            self.run_testcase({
+                'host': 'abc',
+                'user': 'user',
+                'database': 'db',
+                'passfile': passfile.name,
+                'result': (
+                    [('abc', 5432)],
+                    {
+                        'password': 'password from pgpass for user@abc',
+                        'user': 'user',
+                        'database': 'db',
+                    }
+                )
+            })
+
+            # passfile path in dsn
+            self.run_testcase({
+                'dsn': 'postgres://user@abc/db?passfile={}'.format(
+                    passfile.name),
+                'result': (
+                    [('abc', 5432)],
+                    {
+                        'password': 'password from pgpass for user@abc',
+                        'user': 'user',
+                        'database': 'db',
+                    }
+                )
+            })
+
+            self.run_testcase({
+                'host': 'localhost',
+                'user': 'user',
+                'database': 'db',
+                'passfile': passfile.name,
+                'result': (
+                    [('localhost', 5432)],
+                    {
+                        'password': 'password from pgpass for localhost',
+                        'user': 'user',
+                        'database': 'db',
+                    }
+                )
+            })
+
+            if _system != 'Windows':
+                # unix socket gets normalized as localhost
+                self.run_testcase({
+                    'host': '/tmp',
+                    'user': 'user',
+                    'database': 'db',
+                    'passfile': passfile.name,
+                    'result': (
+                        ['/tmp/.s.PGSQL.5432'],
+                        {
+                            'password': 'password from pgpass for localhost',
+                            'user': 'user',
+                            'database': 'db',
+                        }
+                    )
+                })
+
+            # port matching (also tests that `:` can be part of password)
+            self.run_testcase({
+                'host': 'cde',
+                'port': 5433,
+                'user': 'user',
+                'database': 'db',
+                'passfile': passfile.name,
+                'result': (
+                    [('cde', 5433)],
+                    {
+                        'password': 'password from pgpass for cde:5433',
+                        'user': 'user',
+                        'database': 'db',
+                    }
+                )
+            })
+
+            # user matching
+            self.run_testcase({
+                'host': 'def',
+                'user': 'testuser',
+                'database': 'db',
+                'passfile': passfile.name,
+                'result': (
+                    [('def', 5432)],
+                    {
+                        'password': 'password from pgpass for testuser',
+                        'user': 'testuser',
+                        'database': 'db',
+                    }
+                )
+            })
+
+            # database matching
+            self.run_testcase({
+                'host': 'efg',
+                'user': 'user',
+                'database': 'testdb',
+                'passfile': passfile.name,
+                'result': (
+                    [('efg', 5432)],
+                    {
+                        'password': 'password from pgpass for testdb',
+                        'user': 'user',
+                        'database': 'testdb',
+                    }
+                )
+            })
+
+            # test escaping
+            self.run_testcase({
+                'host': 'fgh',
+                'user': R'test\\',
+                'database': R'test\:db',
+                'passfile': passfile.name,
+                'result': (
+                    [('fgh', 5432)],
+                    {
+                        'password': 'password from pgpass with escapes',
+                        'user': R'test\\',
+                        'database': R'test\:db',
+                    }
+                )
+            })
+
+        finally:
+            os.unlink(passfile.name)
+
+    @unittest.skipIf(_system == 'Windows', 'no mode checking on Windows')
+    def test_connect_pgpass_badness_mode(self):
+        # Verify that .pgpass permissions are checked
+        with tempfile.NamedTemporaryFile('w+t') as passfile:
+            os.chmod(passfile.name,
+                     stat.S_IWUSR | stat.S_IRUSR | stat.S_IWGRP | stat.S_IRGRP)
+
+            with self.assertWarnsRegex(
+                    UserWarning,
+                    'password file .* has group or world access'):
+                self.run_testcase({
+                    'host': 'abc',
+                    'user': 'user',
+                    'database': 'db',
+                    'passfile': passfile.name,
+                    'result': (
+                        [('abc', 5432)],
+                        {
+                            'user': 'user',
+                            'database': 'db',
+                        }
+                    )
+                })
+
+    def test_connect_pgpass_badness_non_file(self):
+        # Verify warnings when .pgpass is not a file
+        with tempfile.TemporaryDirectory() as passfile:
+            with self.assertWarnsRegex(
+                    UserWarning,
+                    'password file .* is not a plain file'):
+                self.run_testcase({
+                    'host': 'abc',
+                    'user': 'user',
+                    'database': 'db',
+                    'passfile': passfile,
+                    'result': (
+                        [('abc', 5432)],
+                        {
+                            'user': 'user',
+                            'database': 'db',
+                        }
+                    )
+                })
+
+    def test_connect_pgpass_nonexistent(self):
+        # nonexistent passfile is OK
+        self.run_testcase({
+            'host': 'abc',
+            'user': 'user',
+            'database': 'db',
+            'passfile': 'totally nonexistent',
+            'result': (
+                [('abc', 5432)],
+                {
+                    'user': 'user',
+                    'database': 'db',
+                }
+            )
+        })
+
+    @unittest.skipIf(_system == 'Windows', 'no mode checking on Windows')
+    def test_connect_pgpass_inaccessible_file(self):
+        with tempfile.NamedTemporaryFile('w+t') as passfile:
+            os.chmod(passfile.name, stat.S_IWUSR)
+
+            # nonexistent passfile is OK
+            self.run_testcase({
+                'host': 'abc',
+                'user': 'user',
+                'database': 'db',
+                'passfile': passfile.name,
+                'result': (
+                    [('abc', 5432)],
+                    {
+                        'user': 'user',
+                        'database': 'db',
+                    }
+                )
+            })
+
+    @unittest.skipIf(_system == 'Windows', 'no mode checking on Windows')
+    def test_connect_pgpass_inaccessible_directory(self):
+        with tempfile.TemporaryDirectory() as passdir:
+            with tempfile.NamedTemporaryFile('w+t', dir=passdir) as passfile:
+                os.chmod(passdir, stat.S_IWUSR)
+
+                try:
+                    # nonexistent passfile is OK
+                    self.run_testcase({
+                        'host': 'abc',
+                        'user': 'user',
+                        'database': 'db',
+                        'passfile': passfile.name,
+                        'result': (
+                            [('abc', 5432)],
+                            {
+                                'user': 'user',
+                                'database': 'db',
+                            }
+                        )
+                    })
+                finally:
+                    os.chmod(passdir, stat.S_IRWXU)
+
+    async def test_connect_args_validation(self):
+        for val in {-1, 'a', True, False, 0}:
+            with self.assertRaisesRegex(ValueError, 'greater than 0'):
+                await asyncpg.connect(command_timeout=val, loop=self.loop)
+
+        for arg in {'max_cacheable_statement_size',
+                    'max_cached_statement_lifetime',
+                    'statement_cache_size'}:
+            for val in {None, -1, True, False}:
+                with self.assertRaisesRegex(ValueError, 'greater or equal'):
+                    await asyncpg.connect(**{arg: val}, loop=self.loop)
+
+
+class TestConnection(tb.ConnectedTestCase):
+
+    async def test_connection_isinstance(self):
+        self.assertTrue(isinstance(self.con, connection.Connection))
+        self.assertTrue(isinstance(self.con, object))
+        self.assertFalse(isinstance(self.con, list))
+
+    async def test_connection_use_after_close(self):
+        def check():
+            return self.assertRaisesRegex(asyncpg.InterfaceError,
+                                          'connection is closed')
+
+        await self.con.close()
+
+        with check():
+            await self.con.add_listener('aaa', lambda: None)
+
+        with check():
+            self.con.transaction()
+
+        with check():
+            await self.con.executemany('SELECT 1', [])
+
+        with check():
+            await self.con.set_type_codec('aaa', encoder=None, decoder=None)
+
+        with check():
+            await self.con.set_builtin_type_codec('aaa', codec_name='aaa')
+
+        for meth in ('execute', 'fetch', 'fetchval', 'fetchrow',
+                     'prepare', 'cursor'):
+
+            with check():
+                await getattr(self.con, meth)('SELECT 1')
+
+        with check():
+            await self.con.reset()
+
+    @unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster')
+    async def test_connection_ssl_to_no_ssl_server(self):
+        ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+        ssl_context.load_verify_locations(SSL_CA_CERT_FILE)
+
+        with self.assertRaisesRegex(ConnectionError, 'rejected SSL'):
+            await self.connect(
+                host='localhost',
+                user='ssl_user',
+                ssl=ssl_context)
+
+    @unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster')
+    async def test_connection_sslmode_no_ssl_server(self):
+        async def verify_works(sslmode):
+            con = None
+            try:
+                con = await self.connect(
+                    dsn='postgresql://foo/?sslmode=' + sslmode,
+                    host='localhost')
+                self.assertEqual(await con.fetchval('SELECT 42'), 42)
+            finally:
+                if con:
+                    await con.close()
+
+        async def verify_fails(sslmode):
+            con = None
+            try:
+                with self.assertRaises(ConnectionError):
+                    await self.connect(
+                        dsn='postgresql://foo/?sslmode=' + sslmode,
+                        host='localhost')
+                    await con.fetchval('SELECT 42')
+            finally:
+                if con:
+                    await con.close()
+
+        await verify_works('disable')
+        await verify_works('allow')
+        await verify_works('prefer')
+        await verify_fails('require')
+        await verify_fails('verify-ca')
+        await verify_fails('verify-full')
+
+    async def test_connection_ssl_unix(self):
+        ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+        ssl_context.load_verify_locations(SSL_CA_CERT_FILE)
+
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'can only be enabled for TCP addresses'):
+            await self.connect(
+                host='/tmp',
+                ssl=ssl_context)
+
+    async def test_connection_implicit_host(self):
+        conn_spec = self.get_connection_spec()
+        con = await asyncpg.connect(
+            port=conn_spec.get('port'),
+            database=conn_spec.get('database'),
+            user=conn_spec.get('user'),
+            loop=self.loop)
+        await con.close()
+
+
+@unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster')
+class TestSSLConnection(tb.ConnectedTestCase):
+    @classmethod
+    def get_server_settings(cls):
+        conf = super().get_server_settings()
+        conf.update({
+            'ssl': 'on',
+            'ssl_cert_file': SSL_CERT_FILE,
+            'ssl_key_file': SSL_KEY_FILE,
+        })
+
+        return conf
+
+    @classmethod
+    def setup_cluster(cls):
+        cls.cluster = cls.new_cluster(pg_cluster.TempCluster)
+        cls.start_cluster(
+            cls.cluster, server_settings=cls.get_server_settings())
+
+    def setUp(self):
+        super().setUp()
+
+        self.cluster.reset_hba()
+
+        create_script = []
+        create_script.append('CREATE ROLE ssl_user WITH LOGIN;')
+
+        self.cluster.add_hba_entry(
+            type='hostssl', address=ipaddress.ip_network('127.0.0.0/24'),
+            database='postgres', user='ssl_user',
+            auth_method='trust')
+
+        self.cluster.add_hba_entry(
+            type='hostssl', address=ipaddress.ip_network('::1/128'),
+            database='postgres', user='ssl_user',
+            auth_method='trust')
+
+        # Put hba changes into effect
+        self.cluster.reload()
+
+        create_script = '\n'.join(create_script)
+        self.loop.run_until_complete(self.con.execute(create_script))
+
+    def tearDown(self):
+        # Reset cluster's pg_hba.conf since we've meddled with it
+        self.cluster.trust_local_connections()
+
+        drop_script = []
+        drop_script.append('DROP ROLE ssl_user;')
+        drop_script = '\n'.join(drop_script)
+        self.loop.run_until_complete(self.con.execute(drop_script))
+
+        super().tearDown()
+
+    async def test_ssl_connection_custom_context(self):
+        ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+        ssl_context.load_verify_locations(SSL_CA_CERT_FILE)
+
+        con = await self.connect(
+            host='localhost',
+            user='ssl_user',
+            ssl=ssl_context)
+
+        try:
+            self.assertEqual(await con.fetchval('SELECT 42'), 42)
+
+            with self.assertRaises(asyncio.TimeoutError):
+                await con.execute('SELECT pg_sleep(5)', timeout=0.5)
+
+            self.assertEqual(await con.fetchval('SELECT 43'), 43)
+        finally:
+            await con.close()
+
+    async def test_ssl_connection_sslmode(self):
+        async def verify_works(sslmode, *, host='localhost'):
+            con = None
+            try:
+                con = await self.connect(
+                    dsn='postgresql://foo/?sslmode=' + sslmode,
+                    host=host,
+                    user='ssl_user')
+                self.assertEqual(await con.fetchval('SELECT 42'), 42)
+            finally:
+                if con:
+                    await con.close()
+
+        async def verify_fails(sslmode, *, host='localhost',
+                               exn_type=ssl.SSLError):
+            # XXX: uvloop artifact
+            old_handler = self.loop.get_exception_handler()
+            con = None
+            try:
+                self.loop.set_exception_handler(lambda *args: None)
+                with self.assertRaises(exn_type):
+                    await self.connect(
+                        dsn='postgresql://foo/?sslmode=' + sslmode,
+                        host=host,
+                        user='ssl_user')
+                    await con.fetchval('SELECT 42')
+            finally:
+                if con:
+                    await con.close()
+                self.loop.set_exception_handler(old_handler)
+
+        invalid_auth_err = asyncpg.InvalidAuthorizationSpecificationError
+        await verify_fails('disable', exn_type=invalid_auth_err)
+        await verify_works('allow')
+        await verify_works('prefer')
+        await verify_works('require')
+        await verify_fails('verify-ca')
+        await verify_fails('verify-full')
+
+        orig_create_default_context = ssl.create_default_context
+        try:
+            def custom_create_default_context(*args, **kwargs):
+                ctx = orig_create_default_context(*args, **kwargs)
+                ctx.load_verify_locations(cafile=SSL_CA_CERT_FILE)
+                return ctx
+            ssl.create_default_context = custom_create_default_context
+            await verify_works('verify-ca')
+            await verify_works('verify-ca', host='127.0.0.1')
+            await verify_works('verify-full')
+            await verify_fails('verify-full', host='127.0.0.1',
+                               exn_type=ssl.CertificateError)
+        finally:
+            ssl.create_default_context = orig_create_default_context
+
+    async def test_ssl_connection_default_context(self):
+        # XXX: uvloop artifact
+        old_handler = self.loop.get_exception_handler()
+        try:
+            self.loop.set_exception_handler(lambda *args: None)
+            with self.assertRaisesRegex(ssl.SSLError, 'verify failed'):
+                await self.connect(
+                    host='localhost',
+                    user='ssl_user',
+                    ssl=True)
+        finally:
+            self.loop.set_exception_handler(old_handler)
+
+    async def test_ssl_connection_pool(self):
+        ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+        ssl_context.load_verify_locations(SSL_CA_CERT_FILE)
+
+        pool = await self.create_pool(
+            host='localhost',
+            user='ssl_user',
+            database='postgres',
+            min_size=5,
+            max_size=10,
+            ssl=ssl_context)
+
+        async def worker():
+            async with pool.acquire() as con:
+                self.assertEqual(await con.fetchval('SELECT 42'), 42)
+
+                with self.assertRaises(asyncio.TimeoutError):
+                    await con.execute('SELECT pg_sleep(5)', timeout=0.5)
+
+                self.assertEqual(await con.fetchval('SELECT 43'), 43)
+
+        tasks = [worker() for _ in range(100)]
+        await asyncio.gather(*tasks, loop=self.loop)
+        await pool.close()
+
+
+class TestConnectionGC(tb.ClusterTestCase):
+
+    async def _run_no_explicit_close_test(self):
+        con = await self.connect()
+        proto = con._protocol
+        conref = weakref.ref(con)
+        del con
+
+        gc.collect()
+        gc.collect()
+        gc.collect()
+
+        self.assertIsNone(conref())
+        self.assertTrue(proto.is_closed())
+
+    async def test_no_explicit_close_no_debug(self):
+        olddebug = self.loop.get_debug()
+        self.loop.set_debug(False)
+        try:
+            with self.assertWarnsRegex(
+                    ResourceWarning,
+                    r'unclosed connection.*run in asyncio debug'):
+                await self._run_no_explicit_close_test()
+        finally:
+            self.loop.set_debug(olddebug)
+
+    async def test_no_explicit_close_with_debug(self):
+        olddebug = self.loop.get_debug()
+        self.loop.set_debug(True)
+        try:
+            with self.assertWarnsRegex(ResourceWarning,
+                                       r'unclosed connection') as rw:
+                await self._run_no_explicit_close_test()
+
+            msg = rw.warning.args[0]
+            self.assertIn(' created at:\n', msg)
+            self.assertIn('in test_no_explicit_close_with_debug', msg)
+        finally:
+            self.loop.set_debug(olddebug)
diff --git a/tests/test_copy.py b/tests/test_copy.py
new file mode 100644 (file)
index 0000000..6bedb23
--- /dev/null
@@ -0,0 +1,637 @@
+# 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
+
+
+import asyncio
+import datetime
+import io
+import tempfile
+
+import asyncpg
+from asyncpg import _testbase as tb
+from asyncpg import compat
+
+
+class TestCopyFrom(tb.ConnectedTestCase):
+
+    async def test_copy_from_table_basics(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, "b~" text, i int);
+            INSERT INTO copytab (a, "b~", i) (
+                SELECT 'a' || i::text, 'b' || i::text, i
+                FROM generate_series(1, 5) AS i
+            );
+            INSERT INTO copytab (a, "b~", i) VALUES('*', NULL, NULL);
+        ''')
+
+        try:
+            f = io.BytesIO()
+
+            # Basic functionality.
+            res = await self.con.copy_from_table('copytab', output=f)
+
+            self.assertEqual(res, 'COPY 6')
+
+            output = f.getvalue().decode().split('\n')
+            self.assertEqual(
+                output,
+                [
+                    'a1\tb1\t1',
+                    'a2\tb2\t2',
+                    'a3\tb3\t3',
+                    'a4\tb4\t4',
+                    'a5\tb5\t5',
+                    '*\t\\N\t\\N',
+                    ''
+                ]
+            )
+
+            # Test parameters.
+            await self.con.execute('SET search_path=none')
+
+            f.seek(0)
+            f.truncate()
+
+            res = await self.con.copy_from_table(
+                'copytab', output=f, columns=('a', 'b~'),
+                schema_name='public', format='csv',
+                delimiter='|', null='n-u-l-l', header=True,
+                quote='*', escape='!', force_quote=('a',))
+
+            output = f.getvalue().decode().split('\n')
+
+            self.assertEqual(
+                output,
+                [
+                    'a|b~',
+                    '*a1*|b1',
+                    '*a2*|b2',
+                    '*a3*|b3',
+                    '*a4*|b4',
+                    '*a5*|b5',
+                    '*!**|n-u-l-l',
+                    ''
+                ]
+            )
+
+            await self.con.execute('SET search_path=public')
+        finally:
+            await self.con.execute('DROP TABLE public.copytab')
+
+    async def test_copy_from_table_large_rows(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b text);
+            INSERT INTO copytab (a, b) (
+                SELECT
+                    repeat('a' || i::text, 500000),
+                    repeat('b' || i::text, 500000)
+                FROM
+                    generate_series(1, 5) AS i
+            );
+        ''')
+
+        try:
+            f = io.BytesIO()
+
+            # Basic functionality.
+            res = await self.con.copy_from_table('copytab', output=f)
+
+            self.assertEqual(res, 'COPY 5')
+
+            output = f.getvalue().decode().split('\n')
+            self.assertEqual(
+                output,
+                [
+                    'a1' * 500000 + '\t' + 'b1' * 500000,
+                    'a2' * 500000 + '\t' + 'b2' * 500000,
+                    'a3' * 500000 + '\t' + 'b3' * 500000,
+                    'a4' * 500000 + '\t' + 'b4' * 500000,
+                    'a5' * 500000 + '\t' + 'b5' * 500000,
+                    ''
+                ]
+            )
+        finally:
+            await self.con.execute('DROP TABLE public.copytab')
+
+    async def test_copy_from_query_basics(self):
+        f = io.BytesIO()
+
+        res = await self.con.copy_from_query('''
+            SELECT
+                repeat('a' || i::text, 500000),
+                repeat('b' || i::text, 500000)
+            FROM
+                generate_series(1, 5) AS i
+        ''', output=f)
+
+        self.assertEqual(res, 'COPY 5')
+
+        output = f.getvalue().decode().split('\n')
+        self.assertEqual(
+            output,
+            [
+                'a1' * 500000 + '\t' + 'b1' * 500000,
+                'a2' * 500000 + '\t' + 'b2' * 500000,
+                'a3' * 500000 + '\t' + 'b3' * 500000,
+                'a4' * 500000 + '\t' + 'b4' * 500000,
+                'a5' * 500000 + '\t' + 'b5' * 500000,
+                ''
+            ]
+        )
+
+    async def test_copy_from_query_with_args(self):
+        f = io.BytesIO()
+
+        res = await self.con.copy_from_query('''
+            SELECT
+                i, i * 10
+            FROM
+                generate_series(1, 5) AS i
+            WHERE
+                i = $1
+        ''', 3, output=f)
+
+        self.assertEqual(res, 'COPY 1')
+
+        output = f.getvalue().decode().split('\n')
+        self.assertEqual(
+            output,
+            [
+                '3\t30',
+                ''
+            ]
+        )
+
+    async def test_copy_from_query_to_path(self):
+        with tempfile.NamedTemporaryFile() as f:
+            f.close()
+            await self.con.copy_from_query('''
+                SELECT
+                    i, i * 10
+                FROM
+                    generate_series(1, 5) AS i
+                WHERE
+                    i = $1
+            ''', 3, output=f.name)
+
+            with open(f.name, 'rb') as fr:
+                output = fr.read().decode().split('\n')
+                self.assertEqual(
+                    output,
+                    [
+                        '3\t30',
+                        ''
+                    ]
+                )
+
+    async def test_copy_from_query_to_path_like(self):
+        with tempfile.NamedTemporaryFile() as f:
+            f.close()
+
+            class Path:
+                def __init__(self, path):
+                    self.path = path
+
+                def __fspath__(self):
+                    return self.path
+
+            await self.con.copy_from_query('''
+                SELECT
+                    i, i * 10
+                FROM
+                    generate_series(1, 5) AS i
+                WHERE
+                    i = $1
+            ''', 3, output=Path(f.name))
+
+            with open(f.name, 'rb') as fr:
+                output = fr.read().decode().split('\n')
+                self.assertEqual(
+                    output,
+                    [
+                        '3\t30',
+                        ''
+                    ]
+                )
+
+    async def test_copy_from_query_to_bad_output(self):
+        with self.assertRaisesRegex(TypeError, 'output is expected to be'):
+            await self.con.copy_from_query('''
+                SELECT
+                    i, i * 10
+                FROM
+                    generate_series(1, 5) AS i
+                WHERE
+                    i = $1
+            ''', 3, output=1)
+
+    async def test_copy_from_query_to_sink(self):
+        with tempfile.NamedTemporaryFile() as f:
+            async def writer(data):
+                # Sleeping here to simulate slow output sink to test
+                # backpressure.
+                await asyncio.sleep(0.05, loop=self.loop)
+                f.write(data)
+
+            await self.con.copy_from_query('''
+                SELECT
+                    repeat('a', 500)
+                FROM
+                    generate_series(1, 5000) AS i
+            ''', output=writer)
+
+            f.seek(0)
+
+            output = f.read().decode().split('\n')
+            self.assertEqual(
+                output,
+                [
+                    'a' * 500
+                ] * 5000 + ['']
+            )
+
+        self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+    async def test_copy_from_query_cancellation_explicit(self):
+        async def writer(data):
+            # Sleeping here to simulate slow output sink to test
+            # backpressure.
+            await asyncio.sleep(0.5, loop=self.loop)
+
+        coro = self.con.copy_from_query('''
+            SELECT
+                repeat('a', 500)
+            FROM
+                generate_series(1, 5000) AS i
+        ''', output=writer)
+
+        task = self.loop.create_task(coro)
+        await asyncio.sleep(0.7, loop=self.loop)
+        task.cancel()
+
+        with self.assertRaises(asyncio.CancelledError):
+            await task
+
+        self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+    async def test_copy_from_query_cancellation_on_sink_error(self):
+        async def writer(data):
+            await asyncio.sleep(0.05, loop=self.loop)
+            raise RuntimeError('failure')
+
+        coro = self.con.copy_from_query('''
+            SELECT
+                repeat('a', 500)
+            FROM
+                generate_series(1, 5000) AS i
+        ''', output=writer)
+
+        task = self.loop.create_task(coro)
+
+        with self.assertRaises(RuntimeError):
+            await task
+
+        self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+    async def test_copy_from_query_cancellation_while_waiting_for_data(self):
+        async def writer(data):
+            pass
+
+        coro = self.con.copy_from_query('''
+            SELECT
+                pg_sleep(60)
+            FROM
+                generate_series(1, 5000) AS i
+        ''', output=writer)
+
+        task = self.loop.create_task(coro)
+        await asyncio.sleep(0.7, loop=self.loop)
+        task.cancel()
+
+        with self.assertRaises(asyncio.CancelledError):
+            await task
+
+        self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+    async def test_copy_from_query_timeout_1(self):
+        async def writer(data):
+            await asyncio.sleep(0.05, loop=self.loop)
+
+        coro = self.con.copy_from_query('''
+            SELECT
+                repeat('a', 500)
+            FROM
+                generate_series(1, 5000) AS i
+        ''', output=writer, timeout=0.10)
+
+        task = self.loop.create_task(coro)
+
+        with self.assertRaises(asyncio.TimeoutError):
+            await task
+
+        self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+    async def test_copy_from_query_timeout_2(self):
+        async def writer(data):
+            try:
+                await asyncio.sleep(10, loop=self.loop)
+            except asyncio.TimeoutError:
+                raise
+            else:
+                self.fail('TimeoutError not raised')
+
+        coro = self.con.copy_from_query('''
+            SELECT
+                repeat('a', 500)
+            FROM
+                generate_series(1, 5000) AS i
+        ''', output=writer, timeout=0.10)
+
+        task = self.loop.create_task(coro)
+
+        with self.assertRaises(asyncio.TimeoutError):
+            await task
+
+        self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+
+class TestCopyTo(tb.ConnectedTestCase):
+
+    async def test_copy_to_table_basics(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, "b~" text, i int);
+        ''')
+
+        try:
+            f = io.BytesIO()
+            f.write(
+                '\n'.join([
+                    'a1\tb1\t1',
+                    'a2\tb2\t2',
+                    'a3\tb3\t3',
+                    'a4\tb4\t4',
+                    'a5\tb5\t5',
+                    '*\t\\N\t\\N',
+                    ''
+                ]).encode('utf-8')
+            )
+            f.seek(0)
+
+            res = await self.con.copy_to_table('copytab', source=f)
+            self.assertEqual(res, 'COPY 6')
+
+            output = await self.con.fetch("""
+                SELECT * FROM copytab ORDER BY a
+            """)
+            self.assertEqual(
+                output,
+                [
+                    ('*', None, None),
+                    ('a1', 'b1', 1),
+                    ('a2', 'b2', 2),
+                    ('a3', 'b3', 3),
+                    ('a4', 'b4', 4),
+                    ('a5', 'b5', 5),
+                ]
+            )
+
+            # Test parameters.
+            await self.con.execute('TRUNCATE copytab')
+            await self.con.execute('SET search_path=none')
+
+            f.seek(0)
+            f.truncate()
+
+            f.write(
+                '\n'.join([
+                    'a|b~',
+                    '*a1*|b1',
+                    '*a2*|b2',
+                    '*a3*|b3',
+                    '*a4*|b4',
+                    '*a5*|b5',
+                    '*!**|*n-u-l-l*',
+                    'n-u-l-l|bb'
+                ]).encode('utf-8')
+            )
+            f.seek(0)
+
+            if self.con.get_server_version() < (9, 4):
+                force_null = None
+                forced_null_expected = 'n-u-l-l'
+            else:
+                force_null = ('b~',)
+                forced_null_expected = None
+
+            res = await self.con.copy_to_table(
+                'copytab', source=f, columns=('a', 'b~'),
+                schema_name='public', format='csv',
+                delimiter='|', null='n-u-l-l', header=True,
+                quote='*', escape='!', force_not_null=('a',),
+                force_null=force_null)
+
+            self.assertEqual(res, 'COPY 7')
+
+            await self.con.execute('SET search_path=public')
+
+            output = await self.con.fetch("""
+                SELECT * FROM copytab ORDER BY a
+            """)
+            self.assertEqual(
+                output,
+                [
+                    ('*', forced_null_expected, None),
+                    ('a1', 'b1', None),
+                    ('a2', 'b2', None),
+                    ('a3', 'b3', None),
+                    ('a4', 'b4', None),
+                    ('a5', 'b5', None),
+                    ('n-u-l-l', 'bb', None),
+                ]
+            )
+
+        finally:
+            await self.con.execute('DROP TABLE public.copytab')
+
+    async def test_copy_to_table_large_rows(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b text);
+        ''')
+
+        try:
+            class _Source:
+                def __init__(self):
+                    self.rowcount = 0
+
+                @compat.aiter_compat
+                def __aiter__(self):
+                    return self
+
+                async def __anext__(self):
+                    if self.rowcount >= 100:
+                        raise StopAsyncIteration
+                    else:
+                        self.rowcount += 1
+                        return b'a1' * 500000 + b'\t' + b'b1' * 500000 + b'\n'
+
+            res = await self.con.copy_to_table('copytab', source=_Source())
+
+            self.assertEqual(res, 'COPY 100')
+
+        finally:
+            await self.con.execute('DROP TABLE copytab')
+
+    async def test_copy_to_table_from_bytes_like(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b text);
+        ''')
+
+        try:
+            data = memoryview((b'a1' * 500 + b'\t' + b'b1' * 500 + b'\n') * 2)
+            res = await self.con.copy_to_table('copytab', source=data)
+            self.assertEqual(res, 'COPY 2')
+        finally:
+            await self.con.execute('DROP TABLE copytab')
+
+    async def test_copy_to_table_fail_in_source_1(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b text);
+        ''')
+
+        try:
+            class _Source:
+                def __init__(self):
+                    self.rowcount = 0
+
+                @compat.aiter_compat
+                def __aiter__(self):
+                    return self
+
+                async def __anext__(self):
+                    raise RuntimeError('failure in source')
+
+            with self.assertRaisesRegex(RuntimeError, 'failure in source'):
+                await self.con.copy_to_table('copytab', source=_Source())
+
+            # Check that the protocol has recovered.
+            self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+        finally:
+            await self.con.execute('DROP TABLE copytab')
+
+    async def test_copy_to_table_fail_in_source_2(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b text);
+        ''')
+
+        try:
+            class _Source:
+                def __init__(self):
+                    self.rowcount = 0
+
+                @compat.aiter_compat
+                def __aiter__(self):
+                    return self
+
+                async def __anext__(self):
+                    if self.rowcount == 0:
+                        self.rowcount += 1
+                        return b'a\tb\n'
+                    else:
+                        raise RuntimeError('failure in source')
+
+            with self.assertRaisesRegex(RuntimeError, 'failure in source'):
+                await self.con.copy_to_table('copytab', source=_Source())
+
+            # Check that the protocol has recovered.
+            self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+        finally:
+            await self.con.execute('DROP TABLE copytab')
+
+    async def test_copy_to_table_timeout(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b text);
+        ''')
+
+        try:
+            class _Source:
+                def __init__(self, loop):
+                    self.rowcount = 0
+                    self.loop = loop
+
+                @compat.aiter_compat
+                def __aiter__(self):
+                    return self
+
+                async def __anext__(self):
+                    self.rowcount += 1
+                    await asyncio.sleep(60, loop=self.loop)
+                    return b'a1' * 50 + b'\t' + b'b1' * 50 + b'\n'
+
+            with self.assertRaises(asyncio.TimeoutError):
+                await self.con.copy_to_table(
+                    'copytab', source=_Source(self.loop), timeout=0.10)
+
+            # Check that the protocol has recovered.
+            self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+        finally:
+            await self.con.execute('DROP TABLE copytab')
+
+    async def test_copy_records_to_table_1(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a text, b int, c timestamptz);
+        ''')
+
+        try:
+            date = datetime.datetime.now(tz=datetime.timezone.utc)
+            delta = datetime.timedelta(days=1)
+
+            records = [
+                ('a-{}'.format(i), i, date + delta)
+                for i in range(100)
+            ]
+
+            records.append(('a-100', None, None))
+
+            res = await self.con.copy_records_to_table(
+                'copytab', records=records)
+
+            self.assertEqual(res, 'COPY 101')
+
+        finally:
+            await self.con.execute('DROP TABLE copytab')
+
+    async def test_copy_records_to_table_no_binary_codec(self):
+        await self.con.execute('''
+            CREATE TABLE copytab(a uuid);
+        ''')
+
+        try:
+            def _encoder(value):
+                return value
+
+            def _decoder(value):
+                return value
+
+            await self.con.set_type_codec(
+                'uuid', encoder=_encoder, decoder=_decoder,
+                schema='pg_catalog', format='text'
+            )
+
+            records = [('2975ab9a-f79c-4ab4-9be5-7bc134d952f0',)]
+
+            with self.assertRaisesRegex(
+                    asyncpg.InternalClientError, 'no binary format encoder'):
+                await self.con.copy_records_to_table(
+                    'copytab', records=records)
+
+        finally:
+            await self.con.reset_type_codec(
+                'uuid', schema='pg_catalog'
+            )
+            await self.con.execute('DROP TABLE copytab')
diff --git a/tests/test_cursor.py b/tests/test_cursor.py
new file mode 100644 (file)
index 0000000..565def8
--- /dev/null
@@ -0,0 +1,151 @@
+# 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
+
+
+import asyncpg
+import inspect
+
+from asyncpg import _testbase as tb
+
+
+class TestIterableCursor(tb.ConnectedTestCase):
+
+    async def test_cursor_iterable_01(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+        expected = await st.fetch()
+
+        for prefetch in range(1, 25):
+            with self.subTest(prefetch=prefetch):
+                async with self.con.transaction():
+                    result = []
+                    async for rec in st.cursor(prefetch=prefetch):
+                        result.append(rec)
+
+                self.assertEqual(
+                    result, expected,
+                    'result != expected for prefetch={}'.format(prefetch))
+
+    async def test_cursor_iterable_02(self):
+        # Test that it's not possible to create a cursor without hold
+        # outside of a transaction
+        s = await self.con.prepare(
+            'DECLARE t BINARY CURSOR WITHOUT HOLD FOR SELECT 1')
+        with self.assertRaises(asyncpg.NoActiveSQLTransactionError):
+            await s.fetch()
+
+        # Now test that statement.cursor() does not let you
+        # iterate over it outside of a transaction
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+
+        it = st.cursor(prefetch=5).__aiter__()
+        if inspect.isawaitable(it):
+            it = await it
+
+        with self.assertRaisesRegex(asyncpg.NoActiveSQLTransactionError,
+                                    'cursor cannot be created.*transaction'):
+            await it.__anext__()
+
+    async def test_cursor_iterable_03(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+
+        it = st.cursor().__aiter__()
+        if inspect.isawaitable(it):
+            it = await it
+
+        st._state.mark_closed()
+
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'statement is closed'):
+            async for _ in it:  # NOQA
+                pass
+
+    async def test_cursor_iterable_04(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+        st._state.mark_closed()
+
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'statement is closed'):
+            async for _ in st.cursor():  # NOQA
+                pass
+
+    async def test_cursor_iterable_05(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+        for prefetch in range(-1, 1):
+            with self.subTest(prefetch=prefetch):
+                with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                            'must be greater than zero'):
+                    async for _ in st.cursor(prefetch=prefetch):  # NOQA
+                        pass
+
+    async def test_cursor_iterable_06(self):
+        recs = []
+
+        async with self.con.transaction():
+            async for rec in self.con.cursor(
+                    'SELECT generate_series(0, $1::int)', 10):
+                recs.append(rec)
+
+        self.assertEqual(recs, [(i,) for i in range(11)])
+
+
+class TestCursor(tb.ConnectedTestCase):
+
+    async def test_cursor_01(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+        with self.assertRaisesRegex(asyncpg.NoActiveSQLTransactionError,
+                                    'cursor cannot be created.*transaction'):
+            await st.cursor()
+
+    async def test_cursor_02(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+        async with self.con.transaction():
+            cur = await st.cursor()
+
+            for i in range(-1, 1):
+                with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                            'greater than zero'):
+                    await cur.fetch(i)
+
+            res = await cur.fetch(2)
+            self.assertEqual(res, [(0,), (1,)])
+
+            rec = await cur.fetchrow()
+            self.assertEqual(rec, (2,))
+
+            r = repr(cur)
+            self.assertTrue(r.startswith('<asyncpg.Cursor '))
+            self.assertNotIn(' exhausted ', r)
+            self.assertIn('"SELECT generate', r)
+
+            moved = await cur.forward(5)
+            self.assertEqual(moved, 5)
+
+            rec = await cur.fetchrow()
+            self.assertEqual(rec, (8,))
+
+            res = await cur.fetch(100)
+            self.assertEqual(res, [(i,) for i in range(9, 21)])
+
+            self.assertIsNone(await cur.fetchrow())
+            self.assertEqual(await cur.fetch(5), [])
+
+            r = repr(cur)
+            self.assertTrue(r.startswith('<asyncpg.Cursor '))
+            self.assertIn(' exhausted ', r)
+            self.assertIn('"SELECT generate', r)
+
+    async def test_cursor_03(self):
+        st = await self.con.prepare('SELECT generate_series(0, 20)')
+        async with self.con.transaction():
+            with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                        'prefetch argument can only'):
+                await st.cursor(prefetch=10)
+
+    async def test_cursor_04(self):
+        async with self.con.transaction():
+            st = await self.con.cursor('SELECT generate_series(0, 100)')
+            await st.forward(42)
+            self.assertEqual(await st.fetchrow(), (42,))
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
new file mode 100644 (file)
index 0000000..dbffcc2
--- /dev/null
@@ -0,0 +1,50 @@
+# 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
+
+
+import asyncpg
+from asyncpg import _testbase as tb
+
+
+class TestExceptions(tb.ConnectedTestCase):
+
+    def test_exceptions_exported(self):
+        for err in ('PostgresError', 'SubstringError', 'InterfaceError'):
+            self.assertTrue(hasattr(asyncpg, err))
+            self.assertIn(err, asyncpg.__all__)
+
+        for err in ('PostgresMessage',):
+            self.assertFalse(hasattr(asyncpg, err))
+            self.assertNotIn(err, asyncpg.__all__)
+
+        self.assertIsNone(asyncpg.PostgresError.schema_name)
+
+    async def test_exceptions_unpacking(self):
+        try:
+            await self.con.execute('SELECT * FROM _nonexistent_')
+        except asyncpg.UndefinedTableError as e:
+            self.assertEqual(e.sqlstate, '42P01')
+            self.assertEqual(e.position, '15')
+            self.assertEqual(e.query, 'SELECT * FROM _nonexistent_')
+            self.assertIsNotNone(e.severity)
+        else:
+            self.fail('UndefinedTableError not raised')
+
+    async def test_exceptions_str(self):
+        try:
+            await self.con.execute('''
+                 CREATE FUNCTION foo() RETURNS bool AS $$ $$ LANGUAGE SQL;
+            ''')
+        except asyncpg.InvalidFunctionDefinitionError as e:
+            self.assertEqual(
+                e.detail,
+                "Function's final statement must be SELECT or "
+                "INSERT/UPDATE/DELETE RETURNING.")
+            self.assertIn(
+                'DETAIL:  Function', str(e)
+            )
+        else:
+            self.fail('InvalidFunctionDefinitionError not raised')
diff --git a/tests/test_execute.py b/tests/test_execute.py
new file mode 100644 (file)
index 0000000..ccde099
--- /dev/null
@@ -0,0 +1,153 @@
+# 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
+
+
+import asyncio
+import asyncpg
+
+from asyncpg import _testbase as tb
+
+
+class TestExecuteScript(tb.ConnectedTestCase):
+
+    async def test_execute_script_1(self):
+        self.assertEqual(self.con._protocol.queries_count, 0)
+        status = await self.con.execute('''
+            SELECT 1;
+
+            SELECT true FROM pg_type WHERE false = true;
+
+            SELECT generate_series(0, 9);
+        ''')
+        self.assertEqual(self.con._protocol.queries_count, 1)
+        self.assertEqual(status, 'SELECT 10')
+
+    async def test_execute_script_2(self):
+        status = await self.con.execute('''
+            CREATE TABLE mytab (a int);
+        ''')
+        self.assertEqual(status, 'CREATE TABLE')
+
+        try:
+            status = await self.con.execute('''
+                INSERT INTO mytab (a) VALUES ($1), ($2)
+            ''', 10, 20)
+            self.assertEqual(status, 'INSERT 0 2')
+        finally:
+            await self.con.execute('DROP TABLE mytab')
+
+    async def test_execute_script_3(self):
+        with self.assertRaisesRegex(asyncpg.PostgresSyntaxError,
+                                    'cannot insert multiple commands'):
+
+            await self.con.execute('''
+                CREATE TABLE mytab (a int);
+                INSERT INTO mytab (a) VALUES ($1), ($2);
+            ''', 10, 20)
+
+    async def test_execute_script_check_transactionality(self):
+        with self.assertRaises(asyncpg.PostgresError):
+            await self.con.execute('''
+                CREATE TABLE mytab (a int);
+                SELECT * FROM mytab WHERE 1 / 0 = 1;
+            ''')
+
+        with self.assertRaisesRegex(asyncpg.PostgresError,
+                                    '"mytab" does not exist'):
+
+            await self.con.prepare('''
+                SELECT * FROM mytab
+            ''')
+
+    async def test_execute_exceptions_1(self):
+        with self.assertRaisesRegex(asyncpg.PostgresError,
+                                    'relation "__dne__" does not exist'):
+
+            await self.con.execute('select * from __dne__')
+
+    async def test_execute_script_interrupted_close(self):
+        fut = self.loop.create_task(
+            self.con.execute('''SELECT pg_sleep(10)'''))
+
+        await asyncio.sleep(0.2, loop=self.loop)
+
+        self.assertFalse(self.con.is_closed())
+        await self.con.close()
+        self.assertTrue(self.con.is_closed())
+
+        with self.assertRaises(asyncpg.QueryCanceledError):
+            await fut
+
+    async def test_execute_script_interrupted_terminate(self):
+        fut = self.loop.create_task(
+            self.con.execute('''SELECT pg_sleep(10)'''))
+
+        await asyncio.sleep(0.2, loop=self.loop)
+
+        self.assertFalse(self.con.is_closed())
+        self.con.terminate()
+        self.assertTrue(self.con.is_closed())
+
+        with self.assertRaisesRegex(asyncpg.ConnectionDoesNotExistError,
+                                    'closed in the middle'):
+            await fut
+
+        self.con.terminate()
+
+    async def test_execute_many_1(self):
+        await self.con.execute('CREATE TEMP TABLE exmany (a text, b int)')
+
+        try:
+            result = await self.con.executemany('''
+                INSERT INTO exmany VALUES($1, $2)
+            ''', [
+                ('a', 1), ('b', 2), ('c', 3), ('d', 4)
+            ])
+
+            self.assertIsNone(result)
+
+            result = await self.con.fetch('''
+                SELECT * FROM exmany
+            ''')
+
+            self.assertEqual(result, [
+                ('a', 1), ('b', 2), ('c', 3), ('d', 4)
+            ])
+
+            # Empty set
+            result = await self.con.executemany('''
+                INSERT INTO exmany VALUES($1, $2)
+            ''', ())
+
+            result = await self.con.fetch('''
+                SELECT * FROM exmany
+            ''')
+
+            self.assertEqual(result, [
+                ('a', 1), ('b', 2), ('c', 3), ('d', 4)
+            ])
+        finally:
+            await self.con.execute('DROP TABLE exmany')
+
+    async def test_execute_many_2(self):
+        await self.con.execute('CREATE TEMP TABLE exmany (b int)')
+
+        try:
+            bad_data = ([1 / 0] for v in range(10))
+
+            with self.assertRaises(ZeroDivisionError):
+                async with self.con.transaction():
+                    await self.con.executemany('''
+                        INSERT INTO exmany VALUES($1)
+                    ''', bad_data)
+
+            good_data = ([v] for v in range(10))
+            async with self.con.transaction():
+                await self.con.executemany('''
+                    INSERT INTO exmany VALUES($1)
+                ''', good_data)
+        finally:
+            await self.con.execute('DROP TABLE exmany')
diff --git a/tests/test_introspection.py b/tests/test_introspection.py
new file mode 100644 (file)
index 0000000..92ebc7a
--- /dev/null
@@ -0,0 +1,177 @@
+# 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
+
+
+import asyncio
+import json
+
+from asyncpg import _testbase as tb
+from asyncpg import connection as apg_con
+
+
+MAX_RUNTIME = 0.1
+
+
+class SlowIntrospectionConnection(apg_con.Connection):
+    """Connection class to test introspection races."""
+    introspect_count = 0
+
+    async def _introspect_types(self, *args, **kwargs):
+        self.introspect_count += 1
+        await asyncio.sleep(0.4, loop=self._loop)
+        return await super()._introspect_types(*args, **kwargs)
+
+
+class TestIntrospection(tb.ConnectedTestCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.adminconn = cls.loop.run_until_complete(cls.connect())
+        cls.loop.run_until_complete(
+            cls.adminconn.execute('CREATE DATABASE asyncpg_intro_test'))
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.loop.run_until_complete(
+            cls.adminconn.execute('DROP DATABASE asyncpg_intro_test'))
+
+        cls.loop.run_until_complete(cls.adminconn.close())
+        cls.adminconn = None
+
+        super().tearDownClass()
+
+    @tb.with_connection_options(database='asyncpg_intro_test')
+    async def test_introspection_on_large_db(self):
+        await self.con.execute(
+            'CREATE TABLE base ({})'.format(
+                ','.join('c{:02} varchar'.format(n) for n in range(50))
+            )
+        )
+        for n in range(1000):
+            await self.con.execute(
+                'CREATE TABLE child_{:04} () inherits (base)'.format(n)
+            )
+
+        with self.assertRunUnder(MAX_RUNTIME):
+            await self.con.fetchval('SELECT $1::int[]', [1, 2])
+
+    @tb.with_connection_options(statement_cache_size=0)
+    async def test_introspection_no_stmt_cache_01(self):
+        old_uid = apg_con._uid
+
+        self.assertEqual(self.con._stmt_cache.get_max_size(), 0)
+        await self.con.fetchval('SELECT $1::int[]', [1, 2])
+
+        await self.con.execute('''
+            CREATE EXTENSION IF NOT EXISTS hstore
+        ''')
+
+        try:
+            await self.con.set_builtin_type_codec(
+                'hstore', codec_name='pg_contrib.hstore')
+        finally:
+            await self.con.execute('''
+                DROP EXTENSION hstore
+            ''')
+
+        self.assertEqual(apg_con._uid, old_uid)
+
+    @tb.with_connection_options(max_cacheable_statement_size=1)
+    async def test_introspection_no_stmt_cache_02(self):
+        # max_cacheable_statement_size will disable caching both for
+        # the user query and for the introspection query.
+        old_uid = apg_con._uid
+
+        await self.con.fetchval('SELECT $1::int[]', [1, 2])
+
+        await self.con.execute('''
+            CREATE EXTENSION IF NOT EXISTS hstore
+        ''')
+
+        try:
+            await self.con.set_builtin_type_codec(
+                'hstore', codec_name='pg_contrib.hstore')
+        finally:
+            await self.con.execute('''
+                DROP EXTENSION hstore
+            ''')
+
+        self.assertEqual(apg_con._uid, old_uid)
+
+    @tb.with_connection_options(max_cacheable_statement_size=10000)
+    async def test_introspection_no_stmt_cache_03(self):
+        # max_cacheable_statement_size will disable caching for
+        # the user query but not for the introspection query.
+        old_uid = apg_con._uid
+
+        await self.con.fetchval(
+            "SELECT $1::int[], '{foo}'".format(foo='a' * 10000), [1, 2])
+
+        self.assertEqual(apg_con._uid, old_uid + 1)
+
+    async def test_introspection_sticks_for_ps(self):
+        # Test that the introspected codec pipeline for a prepared
+        # statement is not affected by a subsequent codec cache bust.
+
+        ps = await self.con._prepare('SELECT $1::json[]', use_cache=True)
+
+        try:
+            # Setting a custom codec blows the codec cache for derived types.
+            await self.con.set_type_codec(
+                'json', encoder=lambda v: v, decoder=json.loads,
+                schema='pg_catalog', format='text'
+            )
+
+            # The originally prepared statement should still be OK and
+            # use the previously selected codec.
+            self.assertEqual(await ps.fetchval(['{"foo": 1}']), ['{"foo": 1}'])
+
+            # The new query uses the custom codec.
+            v = await self.con.fetchval('SELECT $1::json[]', ['{"foo": 1}'])
+            self.assertEqual(v, [{'foo': 1}])
+
+        finally:
+            await self.con.reset_type_codec(
+                'json', schema='pg_catalog')
+
+    async def test_introspection_retries_after_cache_bust(self):
+        # Test that codec cache bust racing with the introspection
+        # query would cause introspection to retry.
+        slow_intro_conn = await self.connect(
+            connection_class=SlowIntrospectionConnection)
+        try:
+            await self.con.execute('''
+                CREATE DOMAIN intro_1_t AS int;
+                CREATE DOMAIN intro_2_t AS int;
+            ''')
+
+            await slow_intro_conn.fetchval('''
+                SELECT $1::intro_1_t
+            ''', 10)
+            # slow_intro_conn cache is now populated with intro_1_t
+
+            async def wait_and_drop():
+                await asyncio.sleep(0.1, loop=self.loop)
+                await slow_intro_conn.reload_schema_state()
+
+            # Now, in parallel, run another query that
+            # references both intro_1_t and intro_2_t.
+            await asyncio.gather(
+                slow_intro_conn.fetchval('''
+                    SELECT $1::intro_1_t, $2::intro_2_t
+                ''', 10, 20),
+                wait_and_drop()
+            )
+
+            # Initial query + two tries for the second query.
+            self.assertEqual(slow_intro_conn.introspect_count, 3)
+
+        finally:
+            await self.con.execute('''
+                DROP DOMAIN intro_1_t;
+                DROP DOMAIN intro_2_t;
+            ''')
+            await slow_intro_conn.close()
diff --git a/tests/test_listeners.py b/tests/test_listeners.py
new file mode 100644 (file)
index 0000000..d4855c1
--- /dev/null
@@ -0,0 +1,277 @@
+# 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
+
+
+import asyncio
+
+from asyncpg import _testbase as tb
+from asyncpg import exceptions
+
+
+class TestListeners(tb.ClusterTestCase):
+
+    async def test_listen_01(self):
+        async with self.create_pool(database='postgres') as pool:
+            async with pool.acquire() as con:
+
+                q1 = asyncio.Queue(loop=self.loop)
+                q2 = asyncio.Queue(loop=self.loop)
+
+                def listener1(*args):
+                    q1.put_nowait(args)
+
+                def listener2(*args):
+                    q2.put_nowait(args)
+
+                await con.add_listener('test', listener1)
+                await con.add_listener('test', listener2)
+
+                await con.execute("NOTIFY test, 'aaaa'")
+
+                self.assertEqual(
+                    await q1.get(),
+                    (con, con.get_server_pid(), 'test', 'aaaa'))
+                self.assertEqual(
+                    await q2.get(),
+                    (con, con.get_server_pid(), 'test', 'aaaa'))
+
+                await con.remove_listener('test', listener2)
+
+                await con.execute("NOTIFY test, 'aaaa'")
+
+                self.assertEqual(
+                    await q1.get(),
+                    (con, con.get_server_pid(), 'test', 'aaaa'))
+                with self.assertRaises(asyncio.TimeoutError):
+                    await asyncio.wait_for(q2.get(),
+                                           timeout=0.05, loop=self.loop)
+
+                await con.reset()
+                await con.remove_listener('test', listener1)
+                await con.execute("NOTIFY test, 'aaaa'")
+
+                with self.assertRaises(asyncio.TimeoutError):
+                    await asyncio.wait_for(q1.get(),
+                                           timeout=0.05, loop=self.loop)
+                with self.assertRaises(asyncio.TimeoutError):
+                    await asyncio.wait_for(q2.get(),
+                                           timeout=0.05, loop=self.loop)
+
+    async def test_listen_02(self):
+        async with self.create_pool(database='postgres') as pool:
+            async with pool.acquire() as con1, pool.acquire() as con2:
+
+                q1 = asyncio.Queue(loop=self.loop)
+
+                def listener1(*args):
+                    q1.put_nowait(args)
+
+                await con1.add_listener('ipc', listener1)
+                await con2.execute("NOTIFY ipc, 'hello'")
+
+                self.assertEqual(
+                    await q1.get(),
+                    (con1, con2.get_server_pid(), 'ipc', 'hello'))
+
+                await con1.remove_listener('ipc', listener1)
+
+    async def test_listen_notletters(self):
+        async with self.create_pool(database='postgres') as pool:
+            async with pool.acquire() as con1, pool.acquire() as con2:
+
+                q1 = asyncio.Queue(loop=self.loop)
+
+                def listener1(*args):
+                    q1.put_nowait(args)
+
+                await con1.add_listener('12+"34', listener1)
+                await con2.execute("""NOTIFY "12+""34", 'hello'""")
+
+                self.assertEqual(
+                    await q1.get(),
+                    (con1, con2.get_server_pid(), '12+"34', 'hello'))
+
+                await con1.remove_listener('12+"34', listener1)
+
+    async def test_dangling_listener_warns(self):
+        async with self.create_pool(database='postgres') as pool:
+            with self.assertWarnsRegex(
+                    exceptions.InterfaceWarning,
+                    '.*Connection.*is being released to the pool but '
+                    'has 1 active notification listener'):
+                async with pool.acquire() as con:
+                    def listener1(*args):
+                        pass
+
+                    await con.add_listener('ipc', listener1)
+
+
+class TestLogListeners(tb.ConnectedTestCase):
+
+    @tb.with_connection_options(server_settings={
+        'client_min_messages': 'notice'
+    })
+    async def test_log_listener_01(self):
+        q1 = asyncio.Queue(loop=self.loop)
+
+        def notice_callb(con, message):
+            # Message fields depend on PG version, hide some values.
+            dct = message.as_dict()
+            del dct['server_source_line']
+            q1.put_nowait((con, type(message), dct))
+
+        async def raise_notice():
+            await self.con.execute(
+                """DO $$
+                    BEGIN RAISE NOTICE 'catch me!'; END;
+                $$ LANGUAGE plpgsql"""
+            )
+
+        async def raise_warning():
+            await self.con.execute(
+                """DO $$
+                    BEGIN RAISE WARNING 'catch me!'; END;
+                $$ LANGUAGE plpgsql"""
+            )
+
+        con = self.con
+        con.add_log_listener(notice_callb)
+
+        expected_msg = {
+            'context': 'PL/pgSQL function inline_code_block line 2 at RAISE',
+            'message': 'catch me!',
+            'server_source_filename': 'pl_exec.c',
+            'server_source_function': 'exec_stmt_raise',
+        }
+
+        expected_msg_notice = {
+            **expected_msg,
+            'severity': 'NOTICE',
+            'severity_en': 'NOTICE',
+            'sqlstate': '00000',
+        }
+
+        expected_msg_warn = {
+            **expected_msg,
+            'severity': 'WARNING',
+            'severity_en': 'WARNING',
+            'sqlstate': '01000',
+        }
+
+        if con.get_server_version() < (9, 6):
+            del expected_msg_notice['context']
+            del expected_msg_notice['severity_en']
+            del expected_msg_warn['context']
+            del expected_msg_warn['severity_en']
+
+        await raise_notice()
+        await raise_warning()
+
+        self.assertEqual(
+            await q1.get(),
+            (con, exceptions.PostgresLogMessage, expected_msg_notice))
+
+        self.assertEqual(
+            await q1.get(),
+            (con, exceptions.PostgresWarning, expected_msg_warn))
+
+        con.remove_log_listener(notice_callb)
+        await raise_notice()
+        self.assertTrue(q1.empty())
+
+        con.add_log_listener(notice_callb)
+        await raise_notice()
+        await q1.get()
+        self.assertTrue(q1.empty())
+        await con.reset()
+        await raise_notice()
+        self.assertTrue(q1.empty())
+
+    @tb.with_connection_options(server_settings={
+        'client_min_messages': 'notice'
+    })
+    async def test_log_listener_02(self):
+        q1 = asyncio.Queue(loop=self.loop)
+
+        cur_id = None
+
+        def notice_callb(con, message):
+            q1.put_nowait((con, cur_id, message.message))
+
+        con = self.con
+        await con.execute(
+            "CREATE FUNCTION _test(i INT) RETURNS int LANGUAGE plpgsql AS $$"
+            " BEGIN"
+            " RAISE NOTICE '1_%', i;"
+            " PERFORM pg_sleep(0.1);"
+            " RAISE NOTICE '2_%', i;"
+            " RETURN i;"
+            " END"
+            "$$"
+        )
+
+        try:
+            con.add_log_listener(notice_callb)
+            for cur_id in range(10):
+                await con.execute("SELECT _test($1)", cur_id)
+
+            for cur_id in range(10):
+                self.assertEqual(
+                    q1.get_nowait(),
+                    (con, cur_id, '1_%s' % cur_id))
+                self.assertEqual(
+                    q1.get_nowait(),
+                    (con, cur_id, '2_%s' % cur_id))
+
+            con.remove_log_listener(notice_callb)
+            self.assertTrue(q1.empty())
+        finally:
+            await con.execute('DROP FUNCTION _test(i INT)')
+
+    @tb.with_connection_options(server_settings={
+        'client_min_messages': 'notice'
+    })
+    async def test_log_listener_03(self):
+        q1 = asyncio.Queue(loop=self.loop)
+
+        async def raise_message(level, code):
+            await self.con.execute("""
+                DO $$ BEGIN
+                    RAISE {} 'catch me!' USING ERRCODE = '{}';
+                END; $$ LANGUAGE plpgsql;
+            """.format(level, code))
+
+        def notice_callb(con, message):
+            # Message fields depend on PG version, hide some values.
+            q1.put_nowait(message)
+
+        self.con.add_log_listener(notice_callb)
+
+        await raise_message('WARNING', '99999')
+        msg = await q1.get()
+        self.assertIsInstance(msg, exceptions.PostgresWarning)
+        self.assertEqual(msg.sqlstate, '99999')
+
+        await raise_message('WARNING', '01004')
+        msg = await q1.get()
+        self.assertIsInstance(msg, exceptions.StringDataRightTruncation)
+        self.assertEqual(msg.sqlstate, '01004')
+
+        with self.assertRaises(exceptions.InvalidCharacterValueForCastError):
+            await raise_message('', '22018')
+        self.assertTrue(q1.empty())
+
+    async def test_dangling_log_listener_warns(self):
+        async with self.create_pool(database='postgres') as pool:
+            with self.assertWarnsRegex(
+                    exceptions.InterfaceWarning,
+                    '.*Connection.*is being released to the pool but '
+                    'has 1 active log listener'):
+                async with pool.acquire() as con:
+                    def listener1(*args):
+                        pass
+
+                    con.add_log_listener(listener1)
diff --git a/tests/test_pool.py b/tests/test_pool.py
new file mode 100644 (file)
index 0000000..3b53f17
--- /dev/null
@@ -0,0 +1,987 @@
+# 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
+
+
+import asyncio
+import inspect
+import os
+import platform
+import random
+import sys
+import textwrap
+import time
+import unittest
+
+import asyncpg
+from asyncpg import _testbase as tb
+from asyncpg import connection as pg_connection
+from asyncpg import cluster as pg_cluster
+from asyncpg import pool as pg_pool
+
+_system = platform.uname().system
+
+
+if os.environ.get('TRAVIS_OS_NAME') == 'osx':
+    # Travis' macOS is _slow_.
+    POOL_NOMINAL_TIMEOUT = 0.5
+else:
+    POOL_NOMINAL_TIMEOUT = 0.1
+
+
+class SlowResetConnection(pg_connection.Connection):
+    """Connection class to simulate races with Connection.reset()."""
+    async def reset(self, *, timeout=None):
+        await asyncio.sleep(0.2, loop=self._loop)
+        return await super().reset(timeout=timeout)
+
+
+class SlowCancelConnection(pg_connection.Connection):
+    """Connection class to simulate races with Connection._cancel()."""
+    async def _cancel(self, waiter):
+        await asyncio.sleep(0.2, loop=self._loop)
+        return await super()._cancel(waiter)
+
+
+class TestPool(tb.ConnectedTestCase):
+
+    async def test_pool_01(self):
+        for n in {1, 5, 10, 20, 100}:
+            with self.subTest(tasksnum=n):
+                pool = await self.create_pool(database='postgres',
+                                              min_size=5, max_size=10)
+
+                async def worker():
+                    con = await pool.acquire()
+                    self.assertEqual(await con.fetchval('SELECT 1'), 1)
+                    await pool.release(con)
+
+                tasks = [worker() for _ in range(n)]
+                await asyncio.gather(*tasks, loop=self.loop)
+                await pool.close()
+
+    async def test_pool_02(self):
+        for n in {1, 3, 5, 10, 20, 100}:
+            with self.subTest(tasksnum=n):
+                async with self.create_pool(database='postgres',
+                                            min_size=5, max_size=5) as pool:
+
+                    async def worker():
+                        con = await pool.acquire(timeout=5)
+                        self.assertEqual(await con.fetchval('SELECT 1'), 1)
+                        await pool.release(con)
+
+                    tasks = [worker() for _ in range(n)]
+                    await asyncio.gather(*tasks, loop=self.loop)
+
+    async def test_pool_03(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        con = await pool.acquire(timeout=1)
+        with self.assertRaises(asyncio.TimeoutError):
+            await pool.acquire(timeout=0.03)
+
+        pool.terminate()
+        del con
+
+    async def test_pool_04(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        con = await pool.acquire(timeout=POOL_NOMINAL_TIMEOUT)
+
+        # Manual termination of pool connections releases the
+        # pool item immediately.
+        con.terminate()
+        self.assertIsNone(pool._holders[0]._con)
+        self.assertIsNone(pool._holders[0]._in_use)
+
+        con = await pool.acquire(timeout=POOL_NOMINAL_TIMEOUT)
+        self.assertEqual(await con.fetchval('SELECT 1'), 1)
+
+        await con.close()
+        self.assertIsNone(pool._holders[0]._con)
+        self.assertIsNone(pool._holders[0]._in_use)
+        # Calling release should not hurt.
+        await pool.release(con)
+
+        pool.terminate()
+
+    async def test_pool_05(self):
+        for n in {1, 3, 5, 10, 20, 100}:
+            with self.subTest(tasksnum=n):
+                pool = await self.create_pool(database='postgres',
+                                              min_size=5, max_size=10)
+
+                async def worker():
+                    async with pool.acquire() as con:
+                        self.assertEqual(await con.fetchval('SELECT 1'), 1)
+
+                tasks = [worker() for _ in range(n)]
+                await asyncio.gather(*tasks, loop=self.loop)
+                await pool.close()
+
+    async def test_pool_06(self):
+        fut = asyncio.Future(loop=self.loop)
+
+        async def setup(con):
+            fut.set_result(con)
+
+        async with self.create_pool(database='postgres',
+                                    min_size=5, max_size=5,
+                                    setup=setup) as pool:
+            async with pool.acquire() as con:
+                pass
+
+        self.assertIs(con, await fut)
+
+    async def test_pool_07(self):
+        cons = set()
+
+        async def setup(con):
+            if con._con not in cons:  # `con` is `PoolConnectionProxy`.
+                raise RuntimeError('init was not called before setup')
+
+        async def init(con):
+            if con in cons:
+                raise RuntimeError('init was called more than once')
+            cons.add(con)
+
+        async def user(pool):
+            async with pool.acquire() as con:
+                if con._con not in cons:  # `con` is `PoolConnectionProxy`.
+                    raise RuntimeError('init was not called')
+
+        async with self.create_pool(database='postgres',
+                                    min_size=2, max_size=5,
+                                    init=init,
+                                    setup=setup) as pool:
+            users = asyncio.gather(*[user(pool) for _ in range(10)],
+                                   loop=self.loop)
+            await users
+
+        self.assertEqual(len(cons), 5)
+
+    async def test_pool_08(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        con = await pool.acquire(timeout=POOL_NOMINAL_TIMEOUT)
+        with self.assertRaisesRegex(asyncpg.InterfaceError, 'is not a member'):
+            await pool.release(con._con)
+
+    async def test_pool_09(self):
+        pool1 = await self.create_pool(database='postgres',
+                                       min_size=1, max_size=1)
+
+        pool2 = await self.create_pool(database='postgres',
+                                       min_size=1, max_size=1)
+
+        try:
+            con = await pool1.acquire(timeout=POOL_NOMINAL_TIMEOUT)
+            with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                        'is not a member'):
+                await pool2.release(con)
+        finally:
+            await pool1.release(con)
+
+        await pool1.close()
+        await pool2.close()
+
+    async def test_pool_10(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        con = await pool.acquire()
+        await pool.release(con)
+        await pool.release(con)
+
+        await pool.close()
+
+    async def test_pool_11(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        async with pool.acquire() as con:
+            self.assertIn(repr(con._con), repr(con))  # Test __repr__.
+
+            ps = await con.prepare('SELECT 1')
+            txn = con.transaction()
+            async with con.transaction():
+                cur = await con.cursor('SELECT 1')
+                ps_cur = await ps.cursor()
+
+        self.assertIn('[released]', repr(con))
+
+        with self.assertRaisesRegex(
+                asyncpg.InterfaceError,
+                r'cannot call Connection\.execute.*released back to the pool'):
+
+            con.execute('select 1')
+
+        for meth in ('fetchval', 'fetchrow', 'fetch', 'explain',
+                     'get_query', 'get_statusmsg', 'get_parameters',
+                     'get_attributes'):
+            with self.assertRaisesRegex(
+                    asyncpg.InterfaceError,
+                    r'cannot call PreparedStatement\.{meth}.*released '
+                    r'back to the pool'.format(meth=meth)):
+
+                getattr(ps, meth)()
+
+        for c in (cur, ps_cur):
+            for meth in ('fetch', 'fetchrow'):
+                with self.assertRaisesRegex(
+                        asyncpg.InterfaceError,
+                        r'cannot call Cursor\.{meth}.*released '
+                        r'back to the pool'.format(meth=meth)):
+
+                    getattr(c, meth)()
+
+            with self.assertRaisesRegex(
+                    asyncpg.InterfaceError,
+                    r'cannot call Cursor\.forward.*released '
+                    r'back to the pool'.format(meth=meth)):
+
+                c.forward(1)
+
+        for meth in ('start', 'commit', 'rollback'):
+            with self.assertRaisesRegex(
+                    asyncpg.InterfaceError,
+                    r'cannot call Transaction\.{meth}.*released '
+                    r'back to the pool'.format(meth=meth)):
+
+                getattr(txn, meth)()
+
+        await pool.close()
+
+    async def test_pool_12(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        async with pool.acquire() as con:
+            self.assertTrue(isinstance(con, pg_connection.Connection))
+            self.assertFalse(isinstance(con, list))
+
+        await pool.close()
+
+    async def test_pool_13(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        async with pool.acquire() as con:
+            self.assertIn('Execute an SQL command', con.execute.__doc__)
+            self.assertEqual(con.execute.__name__, 'execute')
+
+            self.assertIn(
+                str(inspect.signature(con.execute))[1:],
+                str(inspect.signature(pg_connection.Connection.execute)))
+
+        await pool.close()
+
+    def test_pool_init_run_until_complete(self):
+        pool_init = self.create_pool(database='postgres')
+        pool = self.loop.run_until_complete(pool_init)
+        self.assertIsInstance(pool, asyncpg.pool.Pool)
+
+    async def test_pool_exception_in_setup_and_init(self):
+        class Error(Exception):
+            pass
+
+        async def setup(con):
+            nonlocal setup_calls, last_con
+            last_con = con
+            setup_calls += 1
+            if setup_calls > 1:
+                cons.append(con)
+            else:
+                cons.append('error')
+                raise Error
+
+        with self.subTest(method='setup'):
+            setup_calls = 0
+            last_con = None
+            cons = []
+            async with self.create_pool(database='postgres',
+                                        min_size=1, max_size=1,
+                                        setup=setup) as pool:
+                with self.assertRaises(Error):
+                    await pool.acquire()
+                self.assertTrue(last_con.is_closed())
+
+                async with pool.acquire() as con:
+                    self.assertEqual(cons, ['error', con])
+
+        with self.subTest(method='init'):
+            setup_calls = 0
+            last_con = None
+            cons = []
+            async with self.create_pool(database='postgres',
+                                        min_size=0, max_size=1,
+                                        init=setup) as pool:
+                with self.assertRaises(Error):
+                    await pool.acquire()
+                self.assertTrue(last_con.is_closed())
+
+                async with pool.acquire() as con:
+                    self.assertEqual(await con.fetchval('select 1::int'), 1)
+                    self.assertEqual(cons, ['error', con._con])
+
+    async def test_pool_auth(self):
+        if not self.cluster.is_managed():
+            self.skipTest('unmanaged cluster')
+
+        self.cluster.reset_hba()
+
+        if _system != 'Windows':
+            self.cluster.add_hba_entry(
+                type='local',
+                database='postgres', user='pooluser',
+                auth_method='md5')
+
+        self.cluster.add_hba_entry(
+            type='host', address='127.0.0.1/32',
+            database='postgres', user='pooluser',
+            auth_method='md5')
+
+        self.cluster.add_hba_entry(
+            type='host', address='::1/128',
+            database='postgres', user='pooluser',
+            auth_method='md5')
+
+        self.cluster.reload()
+
+        try:
+            await self.con.execute('''
+                CREATE ROLE pooluser WITH LOGIN PASSWORD 'poolpassword'
+            ''')
+
+            pool = await self.create_pool(database='postgres',
+                                          user='pooluser',
+                                          password='poolpassword',
+                                          min_size=5, max_size=10)
+
+            async def worker():
+                con = await pool.acquire()
+                self.assertEqual(await con.fetchval('SELECT 1'), 1)
+                await pool.release(con)
+
+            tasks = [worker() for _ in range(5)]
+            await asyncio.gather(*tasks, loop=self.loop)
+            await pool.close()
+
+        finally:
+            await self.con.execute('DROP ROLE pooluser')
+
+            # Reset cluster's pg_hba.conf since we've meddled with it
+            self.cluster.trust_local_connections()
+            self.cluster.reload()
+
+    async def test_pool_handles_task_cancel_in_release(self):
+        # Use SlowResetConnectionPool to simulate
+        # the Task.cancel() and __aexit__ race.
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1,
+                                      connection_class=SlowResetConnection)
+
+        async def worker():
+            async with pool.acquire():
+                pass
+
+        task = self.loop.create_task(worker())
+        # Let the worker() run.
+        await asyncio.sleep(0.1, loop=self.loop)
+        # Cancel the worker.
+        task.cancel()
+        # Wait to make sure the cleanup has completed.
+        await asyncio.sleep(0.4, loop=self.loop)
+        # Check that the connection has been returned to the pool.
+        self.assertEqual(pool._queue.qsize(), 1)
+
+    async def test_pool_handles_query_cancel_in_release(self):
+        # Use SlowResetConnectionPool to simulate
+        # the Task.cancel() and __aexit__ race.
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1,
+                                      connection_class=SlowCancelConnection)
+
+        async def worker():
+            async with pool.acquire() as con:
+                await con.execute('SELECT pg_sleep(10)')
+
+        task = self.loop.create_task(worker())
+        # Let the worker() run.
+        await asyncio.sleep(0.1, loop=self.loop)
+        # Cancel the worker.
+        task.cancel()
+        # Wait to make sure the cleanup has completed.
+        await asyncio.sleep(0.5, loop=self.loop)
+        # Check that the connection has been returned to the pool.
+        self.assertEqual(pool._queue.qsize(), 1)
+
+    async def test_pool_no_acquire_deadlock(self):
+        async with self.create_pool(database='postgres',
+                                    min_size=1, max_size=1,
+                                    max_queries=1) as pool:
+
+            async def sleep_and_release():
+                async with pool.acquire() as con:
+                    await con.execute('SELECT pg_sleep(1)')
+
+            asyncio.ensure_future(sleep_and_release(), loop=self.loop)
+            await asyncio.sleep(0.5, loop=self.loop)
+
+            async with pool.acquire() as con:
+                await con.fetchval('SELECT 1')
+
+    async def test_pool_config_persistence(self):
+        N = 100
+        cons = set()
+
+        class MyConnection(asyncpg.Connection):
+            async def foo(self):
+                return 42
+
+            async def fetchval(self, query):
+                res = await super().fetchval(query)
+                return res + 1
+
+        async def test(pool):
+            async with pool.acquire() as con:
+                self.assertEqual(await con.fetchval('SELECT 1'), 2)
+                self.assertEqual(await con.foo(), 42)
+                self.assertTrue(isinstance(con, MyConnection))
+                self.assertEqual(con._con._config.statement_cache_size, 3)
+                cons.add(con)
+
+        async with self.create_pool(
+                database='postgres', min_size=10, max_size=10,
+                max_queries=1, connection_class=MyConnection,
+                statement_cache_size=3) as pool:
+
+            await asyncio.gather(*[test(pool) for _ in range(N)],
+                                 loop=self.loop)
+
+        self.assertEqual(len(cons), N)
+
+    async def test_pool_release_in_xact(self):
+        """Test that Connection.reset() closes any open transaction."""
+        async with self.create_pool(database='postgres',
+                                    min_size=1, max_size=1) as pool:
+            async def get_xact_id(con):
+                return await con.fetchval('select txid_current()')
+
+            with self.assertLoopErrorHandlerCalled('an active transaction'):
+                async with pool.acquire() as con:
+                    real_con = con._con  # unwrap PoolConnectionProxy
+
+                    id1 = await get_xact_id(con)
+
+                    tr = con.transaction()
+                    self.assertIsNone(con._con._top_xact)
+                    await tr.start()
+                    self.assertIs(real_con._top_xact, tr)
+
+                    id2 = await get_xact_id(con)
+                    self.assertNotEqual(id1, id2)
+
+            self.assertIsNone(real_con._top_xact)
+
+            async with pool.acquire() as con:
+                self.assertIs(con._con, real_con)
+                self.assertIsNone(con._con._top_xact)
+                id3 = await get_xact_id(con)
+                self.assertNotEqual(id2, id3)
+
+    async def test_pool_connection_methods(self):
+        async def test_fetch(pool):
+            i = random.randint(0, 20)
+            await asyncio.sleep(random.random() / 100, loop=self.loop)
+            r = await pool.fetch('SELECT {}::int'.format(i))
+            self.assertEqual(r, [(i,)])
+            return 1
+
+        async def test_fetchrow(pool):
+            i = random.randint(0, 20)
+            await asyncio.sleep(random.random() / 100, loop=self.loop)
+            r = await pool.fetchrow('SELECT {}::int'.format(i))
+            self.assertEqual(r, (i,))
+            return 1
+
+        async def test_fetchval(pool):
+            i = random.randint(0, 20)
+            await asyncio.sleep(random.random() / 100, loop=self.loop)
+            r = await pool.fetchval('SELECT {}::int'.format(i))
+            self.assertEqual(r, i)
+            return 1
+
+        async def test_execute(pool):
+            await asyncio.sleep(random.random() / 100, loop=self.loop)
+            r = await pool.execute('SELECT generate_series(0, 10)')
+            self.assertEqual(r, 'SELECT {}'.format(11))
+            return 1
+
+        async def test_execute_with_arg(pool):
+            i = random.randint(0, 20)
+            await asyncio.sleep(random.random() / 100, loop=self.loop)
+            r = await pool.execute('SELECT generate_series(0, $1)', i)
+            self.assertEqual(r, 'SELECT {}'.format(i + 1))
+            return 1
+
+        async def run(N, meth):
+            async with self.create_pool(database='postgres',
+                                        min_size=5, max_size=10) as pool:
+
+                coros = [meth(pool) for _ in range(N)]
+                res = await asyncio.gather(*coros, loop=self.loop)
+                self.assertEqual(res, [1] * N)
+
+        methods = [test_fetch, test_fetchrow, test_fetchval,
+                   test_execute, test_execute_with_arg]
+
+        with tb.silence_asyncio_long_exec_warning():
+            for method in methods:
+                with self.subTest(method=method.__name__):
+                    await run(200, method)
+
+    async def test_pool_connection_execute_many(self):
+        async def worker(pool):
+            await asyncio.sleep(random.random() / 100, loop=self.loop)
+            await pool.executemany('''
+                INSERT INTO exmany VALUES($1, $2)
+            ''', [
+                ('a', 1), ('b', 2), ('c', 3), ('d', 4)
+            ])
+            return 1
+
+        N = 200
+
+        async with self.create_pool(database='postgres',
+                                    min_size=5, max_size=10) as pool:
+
+            await pool.execute('CREATE TABLE exmany (a text, b int)')
+            try:
+
+                coros = [worker(pool) for _ in range(N)]
+                res = await asyncio.gather(*coros, loop=self.loop)
+                self.assertEqual(res, [1] * N)
+
+                n_rows = await pool.fetchval('SELECT count(*) FROM exmany')
+                self.assertEqual(n_rows, N * 4)
+
+            finally:
+                await pool.execute('DROP TABLE exmany')
+
+    async def test_pool_max_inactive_time_01(self):
+        async with self.create_pool(
+                database='postgres', min_size=1, max_size=1,
+                max_inactive_connection_lifetime=0.1) as pool:
+
+            # Test that it's OK if a query takes longer time to execute
+            # than `max_inactive_connection_lifetime`.
+
+            con = pool._holders[0]._con
+
+            for _ in range(3):
+                await pool.execute('SELECT pg_sleep(0.5)')
+                self.assertIs(pool._holders[0]._con, con)
+
+                self.assertEqual(
+                    await pool.execute('SELECT 1::int'),
+                    'SELECT 1')
+                self.assertIs(pool._holders[0]._con, con)
+
+    async def test_pool_max_inactive_time_02(self):
+        async with self.create_pool(
+                database='postgres', min_size=1, max_size=1,
+                max_inactive_connection_lifetime=0.5) as pool:
+
+            # Test that we have a new connection after pool not
+            # being used longer than `max_inactive_connection_lifetime`.
+
+            con = pool._holders[0]._con
+
+            self.assertEqual(
+                await pool.execute('SELECT 1::int'),
+                'SELECT 1')
+            self.assertIs(pool._holders[0]._con, con)
+
+            await asyncio.sleep(1, loop=self.loop)
+            self.assertIs(pool._holders[0]._con, None)
+
+            self.assertEqual(
+                await pool.execute('SELECT 1::int'),
+                'SELECT 1')
+            self.assertIsNot(pool._holders[0]._con, con)
+
+    async def test_pool_max_inactive_time_03(self):
+        async with self.create_pool(
+                database='postgres', min_size=1, max_size=1,
+                max_inactive_connection_lifetime=1) as pool:
+
+            # Test that we start counting inactive time *after*
+            # the connection is being released back to the pool.
+
+            con = pool._holders[0]._con
+
+            await pool.execute('SELECT pg_sleep(0.5)')
+            await asyncio.sleep(0.6, loop=self.loop)
+
+            self.assertIs(pool._holders[0]._con, con)
+
+            self.assertEqual(
+                await pool.execute('SELECT 1::int'),
+                'SELECT 1')
+            self.assertIs(pool._holders[0]._con, con)
+
+    async def test_pool_max_inactive_time_04(self):
+        # Chaos test for max_inactive_connection_lifetime.
+        DURATION = 2.0
+        START = time.monotonic()
+        N = 0
+
+        async def worker(pool):
+            nonlocal N
+            await asyncio.sleep(random.random() / 10 + 0.1, loop=self.loop)
+            async with pool.acquire() as con:
+                if random.random() > 0.5:
+                    await con.execute('SELECT pg_sleep({:.2f})'.format(
+                        random.random() / 10))
+                self.assertEqual(
+                    await con.fetchval('SELECT 42::int'),
+                    42)
+
+            if time.monotonic() - START < DURATION:
+                await worker(pool)
+
+            N += 1
+
+        async with self.create_pool(
+                database='postgres', min_size=10, max_size=30,
+                max_inactive_connection_lifetime=0.1) as pool:
+
+            workers = [worker(pool) for _ in range(50)]
+            await asyncio.gather(*workers, loop=self.loop)
+
+        self.assertGreaterEqual(N, 50)
+
+    async def test_pool_handles_inactive_connection_errors(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        con = await pool.acquire(timeout=POOL_NOMINAL_TIMEOUT)
+
+        true_con = con._con
+
+        await pool.release(con)
+
+        # we simulate network error by terminating the connection
+        true_con.terminate()
+
+        # now pool should reopen terminated connection
+        async with pool.acquire(timeout=POOL_NOMINAL_TIMEOUT) as con:
+            self.assertEqual(await con.fetchval('SELECT 1'), 1)
+            await con.close()
+
+        await pool.close()
+
+    @unittest.skipIf(sys.version_info[:2] < (3, 6), 'no asyncgen support')
+    async def test_pool_handles_transaction_exit_in_asyncgen_1(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        locals_ = {}
+        exec(textwrap.dedent('''\
+            async def iterate(con):
+                async with con.transaction():
+                    for record in await con.fetch("SELECT 1"):
+                        yield record
+        '''), globals(), locals_)
+        iterate = locals_['iterate']
+
+        class MyException(Exception):
+            pass
+
+        with self.assertRaises(MyException):
+            async with pool.acquire() as con:
+                async for _ in iterate(con):  # noqa
+                    raise MyException()
+
+    @unittest.skipIf(sys.version_info[:2] < (3, 6), 'no asyncgen support')
+    async def test_pool_handles_transaction_exit_in_asyncgen_2(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        locals_ = {}
+        exec(textwrap.dedent('''\
+            async def iterate(con):
+                async with con.transaction():
+                    for record in await con.fetch("SELECT 1"):
+                        yield record
+        '''), globals(), locals_)
+        iterate = locals_['iterate']
+
+        class MyException(Exception):
+            pass
+
+        with self.assertRaises(MyException):
+            async with pool.acquire() as con:
+                iterator = iterate(con)
+                async for _ in iterator:  # noqa
+                    raise MyException()
+
+            del iterator
+
+    @unittest.skipIf(sys.version_info[:2] < (3, 6), 'no asyncgen support')
+    async def test_pool_handles_asyncgen_finalization(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        locals_ = {}
+        exec(textwrap.dedent('''\
+            async def iterate(con):
+                for record in await con.fetch("SELECT 1"):
+                    yield record
+        '''), globals(), locals_)
+        iterate = locals_['iterate']
+
+        class MyException(Exception):
+            pass
+
+        with self.assertRaises(MyException):
+            async with pool.acquire() as con:
+                async with con.transaction():
+                    async for _ in iterate(con):  # noqa
+                        raise MyException()
+
+    async def test_pool_close_waits_for_release(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        flag = self.loop.create_future()
+        conn_released = False
+
+        async def worker():
+            nonlocal conn_released
+
+            async with pool.acquire() as connection:
+                async with connection.transaction():
+                    flag.set_result(True)
+                    await asyncio.sleep(0.1, loop=self.loop)
+
+            conn_released = True
+
+        self.loop.create_task(worker())
+
+        await flag
+        await pool.close()
+        self.assertTrue(conn_released)
+
+    async def test_pool_close_timeout(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        flag = self.loop.create_future()
+
+        async def worker():
+            async with pool.acquire():
+                flag.set_result(True)
+                await asyncio.sleep(0.5, loop=self.loop)
+
+        task = self.loop.create_task(worker())
+
+        with self.assertRaises(asyncio.TimeoutError):
+            await flag
+            await asyncio.wait_for(pool.close(), timeout=0.1)
+
+        await task
+
+    async def test_pool_expire_connections(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        con = await pool.acquire()
+        try:
+            await pool.expire_connections()
+        finally:
+            await pool.release(con)
+
+        self.assertIsNone(pool._holders[0]._con)
+
+    async def test_pool_set_connection_args(self):
+        pool = await self.create_pool(database='postgres',
+                                      min_size=1, max_size=1)
+
+        # Test that connection is expired on release.
+        con = await pool.acquire()
+        connspec = self.get_connection_spec()
+        try:
+            connspec['server_settings']['application_name'] = \
+                'set_conn_args_test'
+        except KeyError:
+            connspec['server_settings'] = {
+                'application_name': 'set_conn_args_test'
+            }
+
+        pool.set_connect_args(**connspec)
+        await pool.expire_connections()
+        await pool.release(con)
+
+        con = await pool.acquire()
+        self.assertEqual(con.get_settings().application_name,
+                         'set_conn_args_test')
+        await pool.release(con)
+
+        # Test that connection is expired before acquire.
+        connspec = self.get_connection_spec()
+        try:
+            connspec['server_settings']['application_name'] = \
+                'set_conn_args_test'
+        except KeyError:
+            connspec['server_settings'] = {
+                'application_name': 'set_conn_args_test_2'
+            }
+
+        pool.set_connect_args(**connspec)
+        await pool.expire_connections()
+
+        con = await pool.acquire()
+        self.assertEqual(con.get_settings().application_name,
+                         'set_conn_args_test_2')
+
+    async def test_pool_init_race(self):
+        pool = self.create_pool(database='postgres', min_size=1, max_size=1)
+
+        t1 = asyncio.ensure_future(pool, loop=self.loop)
+        t2 = asyncio.ensure_future(pool, loop=self.loop)
+
+        await t1
+        with self.assertRaisesRegex(
+                asyncpg.InterfaceError,
+                r'pool is being initialized in another task'):
+            await t2
+
+        await pool.close()
+
+    async def test_pool_init_and_use_race(self):
+        pool = self.create_pool(database='postgres', min_size=1, max_size=1)
+
+        pool_task = asyncio.ensure_future(pool, loop=self.loop)
+        await asyncio.sleep(0, loop=self.loop)
+
+        with self.assertRaisesRegex(
+                asyncpg.InterfaceError,
+                r'being initialized, but not yet ready'):
+
+            await pool.fetchval('SELECT 1')
+
+        await pool_task
+        await pool.close()
+
+    async def test_pool_remote_close(self):
+        pool = await self.create_pool(min_size=1, max_size=1)
+        backend_pid_fut = self.loop.create_future()
+
+        async def worker():
+            async with pool.acquire() as conn:
+                pool_backend_pid = await conn.fetchval(
+                    'SELECT pg_backend_pid()')
+                backend_pid_fut.set_result(pool_backend_pid)
+                await asyncio.sleep(0.2, loop=self.loop)
+
+        task = self.loop.create_task(worker())
+        try:
+            conn = await self.connect()
+            backend_pid = await backend_pid_fut
+            await conn.execute('SELECT pg_terminate_backend($1)', backend_pid)
+        finally:
+            await conn.close()
+
+        await task
+
+        # Check that connection_lost has released the pool holder.
+        conn = await pool.acquire(timeout=0.1)
+        await pool.release(conn)
+
+
+@unittest.skipIf(os.environ.get('PGHOST'), 'using remote cluster for testing')
+class TestHotStandby(tb.ClusterTestCase):
+    @classmethod
+    def setup_cluster(cls):
+        cls.master_cluster = cls.new_cluster(pg_cluster.TempCluster)
+        cls.start_cluster(
+            cls.master_cluster,
+            server_settings={
+                'max_wal_senders': 10,
+                'wal_level': 'hot_standby'
+            }
+        )
+
+        con = None
+
+        try:
+            con = cls.loop.run_until_complete(
+                cls.master_cluster.connect(
+                    database='postgres', user='postgres', loop=cls.loop))
+
+            cls.loop.run_until_complete(
+                con.execute('''
+                    CREATE ROLE replication WITH LOGIN REPLICATION
+                '''))
+
+            cls.master_cluster.trust_local_replication_by('replication')
+
+            conn_spec = cls.master_cluster.get_connection_spec()
+
+            cls.standby_cluster = cls.new_cluster(
+                pg_cluster.HotStandbyCluster,
+                cluster_kwargs={
+                    'master': conn_spec,
+                    'replication_user': 'replication'
+                }
+            )
+            cls.start_cluster(
+                cls.standby_cluster,
+                server_settings={
+                    'hot_standby': True
+                }
+            )
+
+        finally:
+            if con is not None:
+                cls.loop.run_until_complete(con.close())
+
+    def create_pool(self, **kwargs):
+        conn_spec = self.standby_cluster.get_connection_spec()
+        conn_spec.update(kwargs)
+        return pg_pool.create_pool(loop=self.loop, **conn_spec)
+
+    async def test_standby_pool_01(self):
+        for n in {1, 3, 5, 10, 20, 100}:
+            with self.subTest(tasksnum=n):
+                pool = await self.create_pool(
+                    database='postgres', user='postgres',
+                    min_size=5, max_size=10)
+
+                async def worker():
+                    con = await pool.acquire()
+                    self.assertEqual(await con.fetchval('SELECT 1'), 1)
+                    await pool.release(con)
+
+                tasks = [worker() for _ in range(n)]
+                await asyncio.gather(*tasks, loop=self.loop)
+                await pool.close()
+
+    async def test_standby_cursors(self):
+        con = await self.standby_cluster.connect(
+            database='postgres', user='postgres', loop=self.loop)
+
+        try:
+            async with con.transaction():
+                cursor = await con.cursor('SELECT 1')
+                self.assertEqual(await cursor.fetchrow(), (1,))
+        finally:
+            await con.close()
diff --git a/tests/test_prepare.py b/tests/test_prepare.py
new file mode 100644 (file)
index 0000000..8fc06e3
--- /dev/null
@@ -0,0 +1,602 @@
+# 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
+
+
+import asyncio
+import asyncpg
+import gc
+import unittest
+
+from asyncpg import _testbase as tb
+from asyncpg import exceptions
+
+
+class TestPrepare(tb.ConnectedTestCase):
+
+    async def test_prepare_01(self):
+        self.assertEqual(self.con._protocol.queries_count, 0)
+        st = await self.con.prepare('SELECT 1 = $1 AS test')
+        self.assertEqual(self.con._protocol.queries_count, 0)
+        self.assertEqual(st.get_query(), 'SELECT 1 = $1 AS test')
+
+        rec = await st.fetchrow(1)
+        self.assertEqual(self.con._protocol.queries_count, 1)
+        self.assertTrue(rec['test'])
+        self.assertEqual(len(rec), 1)
+
+        self.assertEqual(False, await st.fetchval(10))
+        self.assertEqual(self.con._protocol.queries_count, 2)
+
+    async def test_prepare_02(self):
+        with self.assertRaisesRegex(Exception, 'column "a" does not exist'):
+            await self.con.prepare('SELECT a')
+
+    async def test_prepare_03(self):
+        cases = [
+            ('text', ("'NULL'", 'NULL'), [
+                'aaa',
+                None
+            ]),
+
+            ('decimal', ('0', 0), [
+                123,
+                123.5,
+                None
+            ])
+        ]
+
+        for type, (none_name, none_val), vals in cases:
+            st = await self.con.prepare('''
+                    SELECT CASE WHEN $1::{type} IS NULL THEN {default}
+                    ELSE $1::{type} END'''.format(
+                type=type, default=none_name))
+
+            for val in vals:
+                with self.subTest(type=type, value=val):
+                    res = await st.fetchval(val)
+                    if val is None:
+                        self.assertEqual(res, none_val)
+                    else:
+                        self.assertEqual(res, val)
+
+    async def test_prepare_04(self):
+        s = await self.con.prepare('SELECT $1::smallint')
+        self.assertEqual(await s.fetchval(10), 10)
+
+        s = await self.con.prepare('SELECT $1::smallint * 2')
+        self.assertEqual(await s.fetchval(10), 20)
+
+        s = await self.con.prepare('SELECT generate_series(5,10)')
+        self.assertEqual(await s.fetchval(), 5)
+        # Since the "execute" message was sent with a limit=1,
+        # we will receive a PortalSuspended message, instead of
+        # CommandComplete.  Which means there will be no status
+        # message set.
+        self.assertIsNone(s.get_statusmsg())
+        # Repeat the same test for 'fetchrow()'.
+        self.assertEqual(await s.fetchrow(), (5,))
+        self.assertIsNone(s.get_statusmsg())
+
+    async def test_prepare_05_unknownoid(self):
+        s = await self.con.prepare("SELECT 'test'")
+        self.assertEqual(await s.fetchval(), 'test')
+
+    async def test_prepare_06_interrupted_close(self):
+        stmt = await self.con.prepare('''SELECT pg_sleep(10)''')
+        fut = self.loop.create_task(stmt.fetch())
+
+        await asyncio.sleep(0.2, loop=self.loop)
+
+        self.assertFalse(self.con.is_closed())
+        await self.con.close()
+        self.assertTrue(self.con.is_closed())
+
+        with self.assertRaises(asyncpg.QueryCanceledError):
+            await fut
+
+        # Test that it's OK to call close again
+        await self.con.close()
+
+    async def test_prepare_07_interrupted_terminate(self):
+        stmt = await self.con.prepare('''SELECT pg_sleep(10)''')
+        fut = self.loop.create_task(stmt.fetchval())
+
+        await asyncio.sleep(0.2, loop=self.loop)
+
+        self.assertFalse(self.con.is_closed())
+        self.con.terminate()
+        self.assertTrue(self.con.is_closed())
+
+        with self.assertRaisesRegex(asyncpg.ConnectionDoesNotExistError,
+                                    'closed in the middle'):
+            await fut
+
+        # Test that it's OK to call terminate again
+        self.con.terminate()
+
+    async def test_prepare_08_big_result(self):
+        stmt = await self.con.prepare('select generate_series(0,10000)')
+        result = await stmt.fetch()
+
+        self.assertEqual(len(result), 10001)
+        self.assertEqual(
+            [r[0] for r in result],
+            list(range(10001)))
+
+    async def test_prepare_09_raise_error(self):
+        # Stress test ReadBuffer.read_cstr()
+        msg = '0' * 1024 * 100
+        query = """
+        DO language plpgsql $$
+        BEGIN
+        RAISE EXCEPTION '{}';
+        END
+        $$;""".format(msg)
+
+        stmt = await self.con.prepare(query)
+        with self.assertRaisesRegex(asyncpg.RaiseError, msg):
+            with tb.silence_asyncio_long_exec_warning():
+                await stmt.fetchval()
+
+    async def test_prepare_10_stmt_lru(self):
+        cache = self.con._stmt_cache
+
+        query = 'select {}'
+        cache_max = cache.get_max_size()
+        iter_max = cache_max * 2 + 11
+
+        # First, we have no cached statements.
+        self.assertEqual(len(cache), 0)
+
+        stmts = []
+        for i in range(iter_max):
+            s = await self.con._prepare(query.format(i), use_cache=True)
+            self.assertEqual(await s.fetchval(), i)
+            stmts.append(s)
+
+        # At this point our cache should be full.
+        self.assertEqual(len(cache), cache_max)
+        self.assertTrue(all(not s.closed for s in cache.iter_statements()))
+
+        # Since there are references to the statements (`stmts` list),
+        # no statements are scheduled to be closed.
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        # Removing refs to statements and preparing a new statement
+        # will cause connection to cleanup any stale statements.
+        stmts.clear()
+        gc.collect()
+
+        # Now we have a bunch of statements that have no refs to them
+        # scheduled to be closed.
+        self.assertEqual(len(self.con._stmts_to_close), iter_max - cache_max)
+        self.assertTrue(all(s.closed for s in self.con._stmts_to_close))
+        self.assertTrue(all(not s.closed for s in cache.iter_statements()))
+
+        zero = await self.con.prepare(query.format(0))
+        # Hence, all stale statements should be closed now.
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        # The number of cached statements will stay the same though.
+        self.assertEqual(len(cache), cache_max)
+        self.assertTrue(all(not s.closed for s in cache.iter_statements()))
+
+        # After closing all statements will be closed.
+        await self.con.close()
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+        self.assertEqual(len(cache), 0)
+
+        # An attempt to perform an operation on a closed statement
+        # will trigger an error.
+        with self.assertRaisesRegex(asyncpg.InterfaceError, 'is closed'):
+            await zero.fetchval()
+
+    async def test_prepare_11_stmt_gc(self):
+        # Test that prepared statements should stay in the cache after
+        # they are GCed.
+
+        cache = self.con._stmt_cache
+
+        # First, we have no cached statements.
+        self.assertEqual(len(cache), 0)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        # The prepared statement that we'll create will be GCed
+        # right await.  However, its state should be still in
+        # in the statements LRU cache.
+        await self.con._prepare('select 1', use_cache=True)
+        gc.collect()
+
+        self.assertEqual(len(cache), 1)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+    async def test_prepare_12_stmt_gc(self):
+        # Test that prepared statements are closed when there is no space
+        # for them in the LRU cache and there are no references to them.
+
+        cache = self.con._stmt_cache
+        cache_max = cache.get_max_size()
+
+        # First, we have no cached statements.
+        self.assertEqual(len(cache), 0)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        stmt = await self.con._prepare('select 100000000', use_cache=True)
+        self.assertEqual(len(cache), 1)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        for i in range(cache_max):
+            await self.con._prepare('select {}'.format(i), use_cache=True)
+
+        self.assertEqual(len(cache), cache_max)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        del stmt
+        gc.collect()
+
+        self.assertEqual(len(cache), cache_max)
+        self.assertEqual(len(self.con._stmts_to_close), 1)
+
+    async def test_prepare_13_connect(self):
+        v = await self.con.fetchval(
+            'SELECT $1::smallint AS foo', 10, column='foo')
+        self.assertEqual(v, 10)
+
+        r = await self.con.fetchrow('SELECT $1::smallint * 2 AS test', 10)
+        self.assertEqual(r['test'], 20)
+
+        rows = await self.con.fetch('SELECT generate_series(0,$1::int)', 3)
+        self.assertEqual([r[0] for r in rows], [0, 1, 2, 3])
+
+    async def test_prepare_14_explain(self):
+        # Test simple EXPLAIN.
+        stmt = await self.con.prepare('SELECT typname FROM pg_type')
+        plan = await stmt.explain()
+        self.assertEqual(plan[0]['Plan']['Relation Name'], 'pg_type')
+
+        # Test "EXPLAIN ANALYZE".
+        stmt = await self.con.prepare(
+            'SELECT typname, typlen FROM pg_type WHERE typlen > $1')
+        plan = await stmt.explain(2, analyze=True)
+        self.assertEqual(plan[0]['Plan']['Relation Name'], 'pg_type')
+        self.assertIn('Actual Total Time', plan[0]['Plan'])
+
+        # Test that 'EXPLAIN ANALYZE' is executed in a transaction
+        # that gets rollbacked.
+        tr = self.con.transaction()
+        await tr.start()
+        try:
+            await self.con.execute('CREATE TABLE mytab (a int)')
+            stmt = await self.con.prepare(
+                'INSERT INTO mytab (a) VALUES (1), (2)')
+            plan = await stmt.explain(analyze=True)
+            self.assertEqual(plan[0]['Plan']['Operation'], 'Insert')
+
+            # Check that no data was inserted
+            res = await self.con.fetch('SELECT * FROM mytab')
+            self.assertEqual(res, [])
+        finally:
+            await tr.rollback()
+
+    async def test_prepare_15_stmt_gc_cache_disabled(self):
+        # Test that even if the statements cache is off, we're still
+        # cleaning up GCed statements.
+
+        cache = self.con._stmt_cache
+
+        self.assertEqual(len(cache), 0)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        # Disable cache
+        cache.set_max_size(0)
+
+        stmt = await self.con._prepare('select 100000000', use_cache=True)
+        self.assertEqual(len(cache), 0)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        del stmt
+        gc.collect()
+
+        # After GC, _stmts_to_close should contain stmt's state
+        self.assertEqual(len(cache), 0)
+        self.assertEqual(len(self.con._stmts_to_close), 1)
+
+        # Next "prepare" call will trigger a cleanup
+        stmt = await self.con._prepare('select 1', use_cache=True)
+        self.assertEqual(len(cache), 0)
+        self.assertEqual(len(self.con._stmts_to_close), 0)
+
+        del stmt
+
+    async def test_prepare_16_command_result(self):
+        async def status(query):
+            stmt = await self.con.prepare(query)
+            await stmt.fetch()
+            return stmt.get_statusmsg()
+
+        try:
+            self.assertEqual(
+                await status('CREATE TABLE mytab (a int)'),
+                'CREATE TABLE')
+
+            self.assertEqual(
+                await status('INSERT INTO mytab (a) VALUES (1), (2)'),
+                'INSERT 0 2')
+
+            self.assertEqual(
+                await status('SELECT a FROM mytab'),
+                'SELECT 2')
+
+            self.assertEqual(
+                await status('UPDATE mytab SET a = 3 WHERE a = 1'),
+                'UPDATE 1')
+        finally:
+            self.assertEqual(
+                await status('DROP TABLE mytab'),
+                'DROP TABLE')
+
+    async def test_prepare_17_stmt_closed_lru(self):
+        st = await self.con.prepare('SELECT 1')
+        st._state.mark_closed()
+        with self.assertRaisesRegex(asyncpg.InterfaceError, 'is closed'):
+            await st.fetch()
+
+        st = await self.con.prepare('SELECT 1')
+        self.assertEqual(await st.fetchval(), 1)
+
+    async def test_prepare_18_empty_result(self):
+        # test EmptyQueryResponse protocol message
+        st = await self.con.prepare('')
+        self.assertEqual(await st.fetch(), [])
+        self.assertIsNone(await st.fetchval())
+        self.assertIsNone(await st.fetchrow())
+
+        self.assertEqual(await self.con.fetch(''), [])
+        self.assertIsNone(await self.con.fetchval(''))
+        self.assertIsNone(await self.con.fetchrow(''))
+
+    async def test_prepare_19_concurrent_calls(self):
+        st = self.loop.create_task(self.con.fetchval(
+            'SELECT ROW(pg_sleep(0.1), 1)'))
+
+        # Wait for some time to make sure the first query is fully
+        # prepared (!) and is now awaiting the results (!!).
+        await asyncio.sleep(0.01, loop=self.loop)
+
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'another operation'):
+            await self.con.execute('SELECT 2')
+
+        self.assertEqual(await st, (None, 1))
+
+    async def test_prepare_20_concurrent_calls(self):
+        expected = ((None, 1),)
+
+        for methname, val in [('fetch', [expected]),
+                              ('fetchval', expected[0]),
+                              ('fetchrow', expected)]:
+
+            with self.subTest(meth=methname):
+
+                meth = getattr(self.con, methname)
+
+                vf = self.loop.create_task(
+                    meth('SELECT ROW(pg_sleep(0.1), 1)'))
+
+                await asyncio.sleep(0.01, loop=self.loop)
+
+                with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                            'another operation'):
+                    await meth('SELECT 2')
+
+                self.assertEqual(await vf, val)
+
+    async def test_prepare_21_errors(self):
+        stmt = await self.con.prepare('SELECT 10 / $1::int')
+
+        with self.assertRaises(asyncpg.DivisionByZeroError):
+            await stmt.fetchval(0)
+
+        self.assertEqual(await stmt.fetchval(5), 2)
+
+    async def test_prepare_22_empty(self):
+        # Support for empty target list was added in PostgreSQL 9.4
+        if self.server_version < (9, 4):
+            raise unittest.SkipTest(
+                'PostgreSQL servers < 9.4 do not support empty target list.')
+
+        result = await self.con.fetchrow('SELECT')
+        self.assertEqual(result, ())
+        self.assertEqual(repr(result), '<Record>')
+
+    async def test_prepare_statement_invalid(self):
+        await self.con.execute('CREATE TABLE tab1(a int, b int)')
+
+        try:
+            await self.con.execute('INSERT INTO tab1 VALUES (1, 2)')
+
+            stmt = await self.con.prepare('SELECT * FROM tab1')
+
+            await self.con.execute(
+                'ALTER TABLE tab1 ALTER COLUMN b SET DATA TYPE text')
+
+            with self.assertRaisesRegex(asyncpg.InvalidCachedStatementError,
+                                        'cached statement plan is invalid'):
+                await stmt.fetchrow()
+
+        finally:
+            await self.con.execute('DROP TABLE tab1')
+
+    @tb.with_connection_options(statement_cache_size=0)
+    async def test_prepare_23_no_stmt_cache_seq(self):
+        self.assertEqual(self.con._stmt_cache.get_max_size(), 0)
+
+        async def check_simple():
+            # Run a simple query a few times.
+            self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+            self.assertEqual(await self.con.fetchval('SELECT 2'), 2)
+            self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
+
+        await check_simple()
+
+        # Run a query that timeouts.
+        with self.assertRaises(asyncio.TimeoutError):
+            await self.con.fetchrow('select pg_sleep(10)', timeout=0.02)
+
+        # Check that we can run new queries after a timeout.
+        await check_simple()
+
+        # Try a cursor/timeout combination. Cursors should always use
+        # named prepared statements.
+        async with self.con.transaction():
+            with self.assertRaises(asyncio.TimeoutError):
+                async for _ in self.con.cursor(   # NOQA
+                        'select pg_sleep(10)', timeout=0.1):
+                    pass
+
+        # Check that we can run queries after a failed cursor
+        # operation.
+        await check_simple()
+
+    @tb.with_connection_options(max_cached_statement_lifetime=142)
+    async def test_prepare_24_max_lifetime(self):
+        cache = self.con._stmt_cache
+
+        self.assertEqual(cache.get_max_lifetime(), 142)
+        cache.set_max_lifetime(1)
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        state = s._state
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        self.assertIs(s._state, state)
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        self.assertIs(s._state, state)
+
+        await asyncio.sleep(1, loop=self.loop)
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        self.assertIsNot(s._state, state)
+
+    @tb.with_connection_options(max_cached_statement_lifetime=0.5)
+    async def test_prepare_25_max_lifetime_reset(self):
+        cache = self.con._stmt_cache
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        state = s._state
+
+        # Disable max_lifetime
+        cache.set_max_lifetime(0)
+
+        await asyncio.sleep(1, loop=self.loop)
+
+        # The statement should still be cached (as we disabled the timeout).
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        self.assertIs(s._state, state)
+
+    @tb.with_connection_options(max_cached_statement_lifetime=0.5)
+    async def test_prepare_26_max_lifetime_max_size(self):
+        cache = self.con._stmt_cache
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        state = s._state
+
+        # Disable max_lifetime
+        cache.set_max_size(0)
+
+        s = await self.con._prepare('SELECT 1', use_cache=True)
+        self.assertIsNot(s._state, state)
+
+        # Check that nothing crashes after the initial timeout
+        await asyncio.sleep(1, loop=self.loop)
+
+    @tb.with_connection_options(max_cacheable_statement_size=50)
+    async def test_prepare_27_max_cacheable_statement_size(self):
+        cache = self.con._stmt_cache
+
+        await self.con._prepare('SELECT 1', use_cache=True)
+        self.assertEqual(len(cache), 1)
+
+        # Test that long and explicitly created prepared statements
+        # are not cached.
+        await self.con._prepare("SELECT \'" + "a" * 50 + "\'", use_cache=True)
+        self.assertEqual(len(cache), 1)
+
+        # Test that implicitly created long prepared statements
+        # are not cached.
+        await self.con.fetchval("SELECT \'" + "a" * 50 + "\'")
+        self.assertEqual(len(cache), 1)
+
+        # Test that short prepared statements can still be cached.
+        await self.con._prepare('SELECT 2', use_cache=True)
+        self.assertEqual(len(cache), 2)
+
+    async def test_prepare_28_max_args(self):
+        N = 32768
+        args = ','.join('${}'.format(i) for i in range(1, N + 1))
+        query = 'SELECT ARRAY[{}]'.format(args)
+
+        with self.assertRaisesRegex(
+                exceptions.InterfaceError,
+                'the number of query arguments cannot exceed 32767'):
+            await self.con.fetchval(query, *range(1, N + 1))
+
+    async def test_prepare_29_duplicates(self):
+        # In addition to test_record.py, let's have a full functional
+        # test for records with duplicate keys.
+        r = await self.con.fetchrow('SELECT 1 as a, 2 as b, 3 as a')
+        self.assertEqual(list(r.items()), [('a', 1), ('b', 2), ('a', 3)])
+        self.assertEqual(list(r.keys()), ['a', 'b', 'a'])
+        self.assertEqual(list(r.values()), [1, 2, 3])
+        self.assertEqual(r['a'], 3)
+        self.assertEqual(r['b'], 2)
+        self.assertEqual(r[0], 1)
+        self.assertEqual(r[1], 2)
+        self.assertEqual(r[2], 3)
+
+    async def test_prepare_30_invalid_arg_count(self):
+        with self.assertRaisesRegex(
+                exceptions.InterfaceError,
+                'the server expects 1 argument for this query, 0 were passed'):
+            await self.con.fetchval('SELECT $1::int')
+
+        with self.assertRaisesRegex(
+                exceptions.InterfaceError,
+                'the server expects 0 arguments for this query, 1 was passed'):
+            await self.con.fetchval('SELECT 1', 1)
+
+    async def test_prepare_31_pgbouncer_note(self):
+        try:
+            await self.con.execute("""
+                DO $$ BEGIN
+                    RAISE EXCEPTION
+                        'duplicate statement' USING ERRCODE = '42P05';
+                END; $$ LANGUAGE plpgsql;
+            """)
+        except asyncpg.DuplicatePreparedStatementError as e:
+            self.assertTrue('pgbouncer' in e.hint)
+        else:
+            self.fail('DuplicatePreparedStatementError not raised')
+
+        try:
+            await self.con.execute("""
+                DO $$ BEGIN
+                    RAISE EXCEPTION
+                        'invalid statement' USING ERRCODE = '26000';
+                END; $$ LANGUAGE plpgsql;
+            """)
+        except asyncpg.InvalidSQLStatementNameError as e:
+            self.assertTrue('pgbouncer' in e.hint)
+        else:
+            self.fail('InvalidSQLStatementNameError not raised')
+
+    async def test_prepare_does_not_use_cache(self):
+        cache = self.con._stmt_cache
+
+        # prepare with disabled cache
+        await self.con.prepare('select 1')
+        self.assertEqual(len(cache), 0)
diff --git a/tests/test_record.py b/tests/test_record.py
new file mode 100644 (file)
index 0000000..e9abab4
--- /dev/null
@@ -0,0 +1,341 @@
+# 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
+
+
+import contextlib
+import collections
+import gc
+import pickle
+import sys
+
+import asyncpg
+from asyncpg import _testbase as tb
+from asyncpg.protocol.protocol import _create_record as Record
+
+
+R_A = collections.OrderedDict([('a', 0)])
+R_AB = collections.OrderedDict([('a', 0), ('b', 1)])
+R_AC = collections.OrderedDict([('a', 0), ('c', 1)])
+R_ABC = collections.OrderedDict([('a', 0), ('b', 1), ('c', 2)])
+
+
+class TestRecord(tb.ConnectedTestCase):
+
+    @contextlib.contextmanager
+    def checkref(self, *objs):
+        cnt = [sys.getrefcount(objs[i]) for i in range(len(objs))]
+        yield
+        for _ in range(3):
+            gc.collect()
+        for i in range(len(objs)):
+            before = cnt[i]
+            after = sys.getrefcount(objs[i])
+            if before != after:
+                self.fail('refcounts differ for {!r}: {:+}'.format(
+                    objs[i], after - before))
+
+    def test_record_gc(self):
+        elem = object()
+        mapping = {}
+        with self.checkref(mapping, elem):
+            r = Record(mapping, (elem,))
+            del r
+
+        key = 'spam'
+        val = int('101010')
+        mapping = {key: val}
+        with self.checkref(key, val):
+            r = Record(mapping, (0,))
+            with self.assertRaises(RuntimeError):
+                r[key]
+            del r
+
+        key = 'spam'
+        val = 'ham'
+        mapping = {key: val}
+        with self.checkref(key, val):
+            r = Record(mapping, (0,))
+            with self.assertRaises(RuntimeError):
+                r[key]
+            del r
+
+    def test_record_freelist_ok(self):
+        for _ in range(10000):
+            Record(R_A, (42,))
+            Record(R_AB, (42, 42,))
+
+    def test_record_len_getindex(self):
+        r = Record(R_A, (42,))
+        self.assertEqual(len(r), 1)
+        self.assertEqual(r[0], 42)
+        self.assertEqual(r['a'], 42)
+
+        r = Record(R_AB, (42, 43))
+        self.assertEqual(len(r), 2)
+        self.assertEqual(r[0], 42)
+        self.assertEqual(r[1], 43)
+        self.assertEqual(r['a'], 42)
+        self.assertEqual(r['b'], 43)
+
+        with self.assertRaisesRegex(IndexError,
+                                    'record index out of range'):
+            r[1000]
+
+        with self.assertRaisesRegex(KeyError, 'spam'):
+            r['spam']
+
+        with self.assertRaisesRegex(KeyError, 'spam'):
+            Record(None, (1,))['spam']
+
+        with self.assertRaisesRegex(RuntimeError, 'invalid record descriptor'):
+            Record({'spam': 123}, (1,))['spam']
+
+    def test_record_slice(self):
+        r = Record(R_ABC, (1, 2, 3))
+        self.assertEqual(r[:], (1, 2, 3))
+        self.assertEqual(r[:1], (1,))
+        self.assertEqual(r[::-1], (3, 2, 1))
+        self.assertEqual(r[::-2], (3, 1))
+        self.assertEqual(r[1:2], (2,))
+        self.assertEqual(r[2:2], ())
+
+    def test_record_immutable(self):
+        r = Record(R_A, (42,))
+        with self.assertRaisesRegex(TypeError, 'does not support item'):
+            r[0] = 1
+
+    def test_record_repr(self):
+        self.assertEqual(
+            repr(Record(R_A, (42,))),
+            '<Record a=42>')
+
+        self.assertEqual(
+            repr(Record(R_AB, (42, -1))),
+            '<Record a=42 b=-1>')
+
+        # test invalid records just in case
+        with self.assertRaisesRegex(RuntimeError, 'invalid .* mapping'):
+            repr(Record(R_A, (42, 43)))
+        self.assertEqual(repr(Record(R_AB, (42,))), '<Record a=42>')
+
+        class Key:
+            def __str__(self):
+                1 / 0
+
+            def __repr__(self):
+                1 / 0
+
+        with self.assertRaises(ZeroDivisionError):
+            repr(Record({Key(): 0}, (42,)))
+        with self.assertRaises(ZeroDivisionError):
+            repr(Record(R_A, (Key(),)))
+
+    def test_record_iter(self):
+        r = Record(R_AB, (42, 43))
+        with self.checkref(r):
+            self.assertEqual(iter(r).__length_hint__(), 2)
+            self.assertEqual(tuple(r), (42, 43))
+
+    def test_record_values(self):
+        r = Record(R_AB, (42, 43))
+        vv = r.values()
+        self.assertEqual(tuple(vv), (42, 43))
+        self.assertTrue(repr(vv).startswith('<RecordIterator '))
+
+    def test_record_keys(self):
+        r = Record(R_AB, (42, 43))
+        vv = r.keys()
+        self.assertEqual(tuple(vv), ('a', 'b'))
+        self.assertEqual(list(Record(None, (42, 43)).keys()), [])
+
+    def test_record_items(self):
+        r = Record(R_AB, (42, 43))
+
+        self.assertEqual(dict(r), {'a': 42, 'b': 43})
+        self.assertEqual(
+            list(collections.OrderedDict(r).items()),
+            [('a', 42), ('b', 43)])
+
+        with self.checkref(r):
+            rk = r.items()
+            self.assertEqual(rk.__length_hint__(), 2)
+            self.assertEqual(next(rk), ('a', 42))
+            self.assertEqual(rk.__length_hint__(), 1)
+            self.assertEqual(next(rk), ('b', 43))
+            self.assertEqual(rk.__length_hint__(), 0)
+
+            with self.assertRaises(StopIteration):
+                next(rk)
+            with self.assertRaises(StopIteration):
+                next(rk)
+
+            self.assertEqual(rk.__length_hint__(), 0)
+
+        self.assertEqual(list(r.items()), [('a', 42), ('b', 43)])
+
+        # Check invalid records just in case
+        r = Record(R_A, (42, 43))
+        self.assertEqual(list(r.items()), [('a', 42)])
+        r = Record(R_AB, (42,))
+        self.assertEqual(list(r.items()), [('a', 42)])
+
+        # Try to iterate over exhausted items() iterator
+        r = Record(R_A, (42, 43))
+        it = r.items()
+        list(it)
+        list(it)
+
+    def test_record_hash(self):
+        AB = collections.namedtuple('AB', ('a', 'b'))
+        r1 = Record(R_AB, (42, 43))
+        r2 = Record(R_AB, (42, 43))
+        r3 = Record(R_AB, (42, 45))
+        r4 = (42, 43)
+        r5 = AB(42, 43)
+
+        self.assertEqual(hash(r1), hash(r2))
+        self.assertNotEqual(hash(r1), hash(r3))
+        self.assertEqual(hash(r1), hash(r4))
+        self.assertEqual(hash(r1), hash(r5))
+
+        d = {}
+        d[r1] = 123
+        self.assertEqual(d[r1], 123)
+        self.assertIn(r2, d)
+        self.assertEqual(d[r2], 123)
+        self.assertNotIn(r3, d)
+        self.assertIn(r4, d)
+
+    def test_record_contains(self):
+        r = Record(R_AB, (42, 43))
+        self.assertIn('a', r)
+        self.assertIn('b', r)
+        self.assertNotIn('z', r)
+
+        r = Record(None, (42, 43))
+        self.assertNotIn('a', r)
+
+        with self.assertRaises(TypeError):
+            type(r).__contains__(None, 'a')
+
+    def test_record_cmp(self):
+        AB = collections.namedtuple('AB', ('a', 'b'))
+
+        r1 = Record(R_AB, (42, 43))
+        r2 = Record(R_AB, (42, 43))
+        r3 = Record(R_AB.copy(), (42, 43))
+
+        r4 = Record(R_AB.copy(), (42, 45))
+        r5 = Record(R_ABC, (42, 46, 57))
+        r6 = Record(R_AC, (42, 43))
+
+        r7 = (42, 43)
+        r8 = [42, 43]
+
+        r9 = AB(42, 43)
+        r10 = AB(42, 44)
+
+        self.assertEqual(r1, r2)
+        self.assertEqual(r1, r3)
+        self.assertEqual(r1, r6)
+        self.assertEqual(r1, r7)
+        self.assertEqual(r1, r9)
+
+        self.assertNotEqual(r1, r4)
+        self.assertNotEqual(r1, r10)
+        self.assertNotEqual(r1, (42,))
+        self.assertNotEqual(r1, r5)
+        self.assertNotEqual(r4, r5)
+        self.assertNotEqual(r4, r6)
+        self.assertNotEqual(r6, r5)
+        self.assertNotEqual(r1, r8)
+        self.assertNotEqual(r8, r6)
+
+        self.assertLess(r1, r4)
+        self.assertGreater(r4, r1)
+
+        self.assertLess(r1, r5)
+        self.assertLess(r7, r5)
+        self.assertLess(r1, r10)
+        self.assertGreater(r5, r6)
+        self.assertGreater(r5, r7)
+        self.assertGreater(r5, r4)
+
+        with self.assertRaisesRegex(
+                TypeError, "unorderable|'<' not supported"):
+            r1 < r8
+
+        self.assertEqual(
+            sorted([r1, r2, r3, r4, r5, r6, r7]),
+            [r1, r2, r3, r6, r7, r4, r5])
+
+    def test_record_get(self):
+        r = Record(R_AB, (42, 43))
+        with self.checkref(r):
+            self.assertEqual(r.get('a'), 42)
+            self.assertEqual(r.get('nonexistent'), None)
+            self.assertEqual(r.get('nonexistent', 'default'), 'default')
+
+    def test_record_not_pickleable(self):
+        r = Record(R_A, (42,))
+        with self.assertRaises(Exception):
+            pickle.dumps(r)
+
+    def test_record_empty(self):
+        r = Record(None, ())
+        self.assertEqual(r, ())
+        self.assertLess(r, (1,))
+        self.assertEqual(len(r), 0)
+        self.assertFalse(r)
+        self.assertNotIn('a', r)
+        self.assertEqual(repr(r), '<Record>')
+        self.assertEqual(str(r), '<Record>')
+        with self.assertRaisesRegex(KeyError, 'aaa'):
+            r['aaa']
+        self.assertEqual(dict(r.items()), {})
+        self.assertEqual(list(r.keys()), [])
+        self.assertEqual(list(r.values()), [])
+
+    async def test_record_duplicate_colnames(self):
+        """Test that Record handles duplicate column names."""
+
+        records_descs = [
+            [('a', 1)],
+            [('a', 1), ('a', 2)],
+            [('a', 1), ('b', 2), ('a', 3)],
+            [('a', 1), ('b', 2), ('a', 3), ('c', 4), ('b', 5)],
+        ]
+
+        for desc in records_descs:
+            items = collections.OrderedDict(desc)
+
+            query = 'SELECT ' + ', '.join(
+                ['{} as {}'.format(p[1], p[0]) for p in desc])
+
+            with self.subTest(query=query):
+                r = await self.con.fetchrow(query)
+                for idx, (field, val) in enumerate(desc):
+                    self.assertEqual(r[idx], val)
+                    self.assertEqual(r[field], items[field])
+
+                expected_repr = '<Record {}>'.format(
+                    ' '.join('{}={}'.format(p[0], p[1]) for p in desc))
+                self.assertEqual(repr(r), expected_repr)
+
+                self.assertEqual(list(r.items()), desc)
+                self.assertEqual(list(r.values()), [p[1] for p in desc])
+                self.assertEqual(list(r.keys()), [p[0] for p in desc])
+
+    async def test_record_isinstance(self):
+        """Test that Record works with isinstance."""
+        r = await self.con.fetchrow('SELECT 1 as a, 2 as b')
+        self.assertTrue(isinstance(r, asyncpg.Record))
+
+    async def test_record_no_new(self):
+        """Instances of Record cannot be directly created."""
+        with self.assertRaisesRegex(
+                TypeError, "cannot create 'asyncpg.Record' instances"):
+            asyncpg.Record()
diff --git a/tests/test_test.py b/tests/test_test.py
new file mode 100644 (file)
index 0000000..9e04a18
--- /dev/null
@@ -0,0 +1,46 @@
+# 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
+
+
+import asyncio
+import types
+import unittest
+
+
+from asyncpg import _testbase as tb
+
+
+class BaseSimpleTestCase:
+
+    async def test_tests_zero_error(self):
+        await asyncio.sleep(0.01, loop=self.loop)
+        1 / 0
+
+
+class TestTests(unittest.TestCase):
+
+    def test_tests_fail_1(self):
+        SimpleTestCase = types.new_class('SimpleTestCase',
+                                         (BaseSimpleTestCase, tb.TestCase))
+
+        suite = unittest.TestSuite()
+        suite.addTest(SimpleTestCase('test_tests_zero_error'))
+
+        result = unittest.TestResult()
+        suite.run(result)
+
+        self.assertIn('ZeroDivisionError', result.errors[0][1])
+
+
+class TestHelpers(tb.TestCase):
+
+    async def test_tests_assertLoopErrorHandlerCalled_01(self):
+        with self.assertRaisesRegex(AssertionError, r'no message.*was logged'):
+            with self.assertLoopErrorHandlerCalled('aa'):
+                self.loop.call_exception_handler({'message': 'bb a bb'})
+
+        with self.assertLoopErrorHandlerCalled('aa'):
+            self.loop.call_exception_handler({'message': 'bbaabb'})
diff --git a/tests/test_timeout.py b/tests/test_timeout.py
new file mode 100644 (file)
index 0000000..e03a338
--- /dev/null
@@ -0,0 +1,154 @@
+# 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
+
+
+import asyncio
+
+import asyncpg
+from asyncpg import connection as pg_connection
+from asyncpg import _testbase as tb
+
+
+MAX_RUNTIME = 0.5
+
+
+class TestTimeout(tb.ConnectedTestCase):
+
+    async def test_timeout_01(self):
+        for methname in {'fetch', 'fetchrow', 'fetchval', 'execute'}:
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                meth = getattr(self.con, methname)
+                await meth('select pg_sleep(10)', timeout=0.02)
+            self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+    async def test_timeout_02(self):
+        st = await self.con.prepare('select pg_sleep(10)')
+
+        for methname in {'fetch', 'fetchrow', 'fetchval'}:
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                meth = getattr(st, methname)
+                await meth(timeout=0.02)
+            self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+    async def test_timeout_03(self):
+        task = self.loop.create_task(
+            self.con.fetch('select pg_sleep(10)', timeout=0.2))
+        await asyncio.sleep(0.05, loop=self.loop)
+        task.cancel()
+        with self.assertRaises(asyncio.CancelledError), \
+                self.assertRunUnder(MAX_RUNTIME):
+            await task
+        self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+    async def test_timeout_04(self):
+        st = await self.con.prepare('select pg_sleep(10)', timeout=0.1)
+        with self.assertRaises(asyncio.TimeoutError), \
+                self.assertRunUnder(MAX_RUNTIME):
+            async with self.con.transaction():
+                async for _ in st.cursor(timeout=0.1):  # NOQA
+                    pass
+        self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+        st = await self.con.prepare('select pg_sleep(10)', timeout=0.1)
+        async with self.con.transaction():
+            cur = await st.cursor()
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                await cur.fetch(1, timeout=0.1)
+        self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+    async def test_timeout_05(self):
+        # Stress-test timeouts - try to trigger a race condition
+        # between a cancellation request to Postgres and next
+        # query (SELECT 1)
+        for _ in range(500):
+            with self.assertRaises(asyncio.TimeoutError):
+                await self.con.fetch('SELECT pg_sleep(1)', timeout=1e-10)
+            self.assertEqual(await self.con.fetch('SELECT 1'), [(1,)])
+
+    async def test_timeout_06(self):
+        async with self.con.transaction():
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                async for _ in self.con.cursor(   # NOQA
+                        'select pg_sleep(10)', timeout=0.1):
+                    pass
+        self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+        async with self.con.transaction():
+            cur = await self.con.cursor('select pg_sleep(10)')
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                await cur.fetch(1, timeout=0.1)
+
+        async with self.con.transaction():
+            cur = await self.con.cursor('select pg_sleep(10)')
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                await cur.forward(1, timeout=1e-10)
+
+        async with self.con.transaction():
+            cur = await self.con.cursor('select pg_sleep(10)')
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                await cur.fetchrow(timeout=0.1)
+
+        async with self.con.transaction():
+            cur = await self.con.cursor('select pg_sleep(10)')
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                await cur.fetchrow(timeout=0.1)
+
+            with self.assertRaises(asyncpg.InFailedSQLTransactionError):
+                await cur.fetch(1)
+
+        self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+    async def test_invalid_timeout(self):
+        for command_timeout in ('a', False, -1):
+            with self.subTest(command_timeout=command_timeout):
+                with self.assertRaisesRegex(ValueError,
+                                            'invalid command_timeout'):
+                    await self.connect(command_timeout=command_timeout)
+
+        # Note: negative timeouts are OK for method calls.
+        for methname in {'fetch', 'fetchrow', 'fetchval', 'execute'}:
+            for timeout in ('a', False):
+                with self.subTest(timeout=timeout):
+                    with self.assertRaisesRegex(ValueError, 'invalid timeout'):
+                        await self.con.execute('SELECT 1', timeout=timeout)
+
+
+class TestConnectionCommandTimeout(tb.ConnectedTestCase):
+
+    @tb.with_connection_options(command_timeout=0.2)
+    async def test_command_timeout_01(self):
+        for methname in {'fetch', 'fetchrow', 'fetchval', 'execute'}:
+            with self.assertRaises(asyncio.TimeoutError), \
+                    self.assertRunUnder(MAX_RUNTIME):
+                meth = getattr(self.con, methname)
+                await meth('select pg_sleep(10)')
+            self.assertEqual(await self.con.fetch('select 1'), [(1,)])
+
+
+class SlowPrepareConnection(pg_connection.Connection):
+    """Connection class to test timeouts."""
+    async def _get_statement(self, query, timeout):
+        await asyncio.sleep(0.3, loop=self._loop)
+        return await super()._get_statement(query, timeout)
+
+
+class TestTimeoutCoversPrepare(tb.ConnectedTestCase):
+
+    @tb.with_connection_options(connection_class=SlowPrepareConnection,
+                                command_timeout=0.3)
+    async def test_timeout_covers_prepare_01(self):
+        for methname in {'fetch', 'fetchrow', 'fetchval', 'execute'}:
+            with self.assertRaises(asyncio.TimeoutError):
+                meth = getattr(self.con, methname)
+                await meth('select pg_sleep($1)', 0.2)
diff --git a/tests/test_transaction.py b/tests/test_transaction.py
new file mode 100644 (file)
index 0000000..eb2d948
--- /dev/null
@@ -0,0 +1,181 @@
+# 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
+
+
+import asyncpg
+
+from asyncpg import _testbase as tb
+
+
+class TestTransaction(tb.ConnectedTestCase):
+
+    async def test_transaction_regular(self):
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+        tr = self.con.transaction()
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        with self.assertRaises(ZeroDivisionError):
+            async with tr as with_tr:
+                self.assertIs(self.con._top_xact, tr)
+                self.assertTrue(self.con.is_in_transaction())
+
+                # We don't return the transaction object from __aenter__,
+                # to make it harder for people to use '.rollback()' and
+                # '.commit()' from within an 'async with' block.
+                self.assertIsNone(with_tr)
+
+                await self.con.execute('''
+                    CREATE TABLE mytab (a int);
+                ''')
+
+                1 / 0
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        with self.assertRaisesRegex(asyncpg.PostgresError,
+                                    '"mytab" does not exist'):
+            await self.con.prepare('''
+                SELECT * FROM mytab
+            ''')
+
+    async def test_transaction_nested(self):
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        tr = self.con.transaction()
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        with self.assertRaises(ZeroDivisionError):
+            async with tr:
+                self.assertIs(self.con._top_xact, tr)
+                self.assertTrue(self.con.is_in_transaction())
+
+                await self.con.execute('''
+                    CREATE TABLE mytab (a int);
+                ''')
+
+                async with self.con.transaction():
+                    self.assertIs(self.con._top_xact, tr)
+                    self.assertTrue(self.con.is_in_transaction())
+
+                    await self.con.execute('''
+                        INSERT INTO mytab (a) VALUES (1), (2);
+                    ''')
+
+                self.assertIs(self.con._top_xact, tr)
+                self.assertTrue(self.con.is_in_transaction())
+
+                with self.assertRaises(ZeroDivisionError):
+                    in_tr = self.con.transaction()
+                    async with in_tr:
+
+                        self.assertIs(self.con._top_xact, tr)
+                        self.assertTrue(self.con.is_in_transaction())
+
+                        await self.con.execute('''
+                            INSERT INTO mytab (a) VALUES (3), (4);
+                        ''')
+
+                        1 / 0
+
+                st = await self.con.prepare('SELECT * FROM mytab;')
+
+                recs = []
+                async for rec in st.cursor():
+                    recs.append(rec)
+
+                self.assertEqual(len(recs), 2)
+                self.assertEqual(recs[0][0], 1)
+                self.assertEqual(recs[1][0], 2)
+
+                self.assertIs(self.con._top_xact, tr)
+                self.assertTrue(self.con.is_in_transaction())
+
+                1 / 0
+
+        self.assertIs(self.con._top_xact, None)
+        self.assertFalse(self.con.is_in_transaction())
+
+        with self.assertRaisesRegex(asyncpg.PostgresError,
+                                    '"mytab" does not exist'):
+            await self.con.prepare('''
+                SELECT * FROM mytab
+            ''')
+
+    async def test_transaction_interface_errors(self):
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        tr = self.con.transaction(readonly=True, isolation='serializable')
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'cannot start; .* already started'):
+            async with tr:
+                await tr.start()
+
+        self.assertTrue(repr(tr).startswith(
+            '<asyncpg.Transaction state:rolledback serializable readonly'))
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'cannot start; .* already rolled back'):
+            async with tr:
+                pass
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        tr = self.con.transaction()
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'cannot manually commit.*async with'):
+            async with tr:
+                await tr.commit()
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        tr = self.con.transaction()
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'cannot manually rollback.*async with'):
+            async with tr:
+                await tr.rollback()
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        tr = self.con.transaction()
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'cannot enter context:.*async with'):
+            async with tr:
+                async with tr:
+                    pass
+
+    async def test_transaction_within_manual_transaction(self):
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
+
+        await self.con.execute('BEGIN')
+
+        tr = self.con.transaction()
+        self.assertIsNone(self.con._top_xact)
+        self.assertTrue(self.con.is_in_transaction())
+
+        with self.assertRaisesRegex(asyncpg.InterfaceError,
+                                    'cannot use Connection.transaction'):
+            await tr.start()
+
+        with self.assertLoopErrorHandlerCalled(
+                'Resetting connection with an active transaction'):
+            await self.con.reset()
+
+        self.assertIsNone(self.con._top_xact)
+        self.assertFalse(self.con.is_in_transaction())
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644 (file)
index 0000000..30cecc3
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright (C) 2016-present the ayncpg 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
+
+
+import datetime
+
+from asyncpg import utils
+from asyncpg import _testbase as tb
+
+
+class TestUtils(tb.ConnectedTestCase):
+
+    async def test_mogrify_simple(self):
+        cases = [
+            ('timestamp',
+                datetime.datetime(2016, 10, 10),
+                "SELECT '2016-10-10 00:00:00'::timestamp"),
+            ('int[]',
+                [[1, 2], [3, 4]],
+                "SELECT '{{1,2},{3,4}}'::int[]"),
+        ]
+
+        for typename, data, expected in cases:
+            with self.subTest(value=data, type=typename):
+                mogrified = await utils._mogrify(
+                    self.con, 'SELECT $1::{}'.format(typename), [data])
+                self.assertEqual(mogrified, expected)
+
+    async def test_mogrify_multiple(self):
+        mogrified = await utils._mogrify(
+            self.con, 'SELECT $1::int, $2::int[]',
+            [1, [2, 3, 4, 5]])
+        expected = "SELECT '1'::int, '{2,3,4,5}'::int[]"
+        self.assertEqual(mogrified, expected)