MCPcopy Create free account
hub / github.com/erans/pgsqlite / read_message

Function read_message

tests/python/test_row_description_debug.py:11–29  ·  view source on GitHub ↗

Read a PostgreSQL wire protocol message

(sock)

Source from the content-addressed store, hash-verified

9import struct
10
11def read_message(sock):
12 """Read a PostgreSQL wire protocol message"""
13 # Read message type (1 byte) and length (4 bytes)
14 header = sock.recv(5)
15 if len(header) < 5:
16 return None, None
17
18 msg_type = chr(header[0])
19 msg_len = struct.unpack('!I', header[1:5])[0] - 4
20
21 # Read message body
22 body = b''
23 while len(body) < msg_len:
24 chunk = sock.recv(msg_len - len(body))
25 if not chunk:
26 break
27 body += chunk
28
29 return msg_type, body
30
31def send_message(sock, msg_type, body):
32 """Send a PostgreSQL wire protocol message"""

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected