mirror of
https://github.com/hanzo-ds/driver.git
synced 2026-10-30 20:32:40 +00:00
Imports read `datastore_driver`, distribution `datastore-driver`, so nothing has to import another product's name to talk to Hanzo Datastore. Cut from upstream 0.2.9 — the version this stack already ran — rather than from upstream HEAD, so it is a PURE RENAME with no behaviour change. Forking from HEAD would have dragged versions along with the name (connect alone jumped 0.8.17 -> 1.6.0, a major), which is a different and much riskier change wearing a rename's clothes. X-ClickHouse-* headers are untouched: they are wire protocol the server sends and expects, and a different token shape from the module name.
68 lines
1.3 KiB
Python
68 lines
1.3 KiB
Python
import struct
|
|
|
|
from .varint import write_varint
|
|
|
|
|
|
MAX_UINT64 = (1 << 64) - 1
|
|
MAX_INT64 = (1 << 63) - 1
|
|
|
|
|
|
def _byte(b):
|
|
return bytes((b, ))
|
|
|
|
|
|
def write_binary_str(text, buf):
|
|
text = text.encode('utf-8')
|
|
write_binary_bytes(text, buf)
|
|
|
|
|
|
def write_binary_bytes(text, buf):
|
|
write_varint(len(text), buf)
|
|
buf.write(text)
|
|
|
|
|
|
def write_binary_int(number, buf, fmt):
|
|
"""
|
|
Writes int from buffer with provided format.
|
|
"""
|
|
fmt = '<' + fmt
|
|
buf.write(struct.pack(fmt, number))
|
|
|
|
|
|
def write_binary_int8(number, buf):
|
|
write_binary_int(number, buf, 'b')
|
|
|
|
|
|
def write_binary_int16(number, buf):
|
|
write_binary_int(number, buf, 'h')
|
|
|
|
|
|
def write_binary_int32(number, buf):
|
|
write_binary_int(number, buf, 'i')
|
|
|
|
|
|
def write_binary_int64(number, buf):
|
|
write_binary_int(number, buf, 'q')
|
|
|
|
|
|
def write_binary_uint8(number, buf):
|
|
write_binary_int(number, buf, 'B')
|
|
|
|
|
|
def write_binary_uint16(number, buf):
|
|
write_binary_int(number, buf, 'H')
|
|
|
|
|
|
def write_binary_uint32(number, buf):
|
|
write_binary_int(number, buf, 'I')
|
|
|
|
|
|
def write_binary_uint64(number, buf):
|
|
write_binary_int(number, buf, 'Q')
|
|
|
|
|
|
def write_binary_uint128(number, buf):
|
|
fmt = '<QQ'
|
|
packed = struct.pack(fmt, (number >> 64) & MAX_UINT64, number & MAX_UINT64)
|
|
buf.write(packed)
|