ChDriver. Protocol. Block. Compressed
(ch_driver v0.1.1)
Copy Markdown
Encodes and decodes ClickHouse's compressed block envelope: a checksum and a method marker wrapped around a block's bytes, LZ4-compressed or plain.
Multiple blocks are concatenated back-to-back with no extra framing —
call decode/1 repeatedly, threading the returned rest through, until
the buffer is exhausted.
This is what backs the :compression option on ChDriver.start_link/1
and ChDriver.query/4 — you won't normally call encode/2/decode/1
directly. Built on ChDriver.Codec's LZ4/CityHash primitives.
Summary
Functions
Decodes a single block envelope from the front of binary.
Encodes iodata into a single compressed block envelope using method
(defaults to :lz4).
Types
Functions
@spec decode(binary()) :: {:ok, binary(), binary()} | {:incomplete, non_neg_integer()} | {:error, term()}
Decodes a single block envelope from the front of binary.
Returns:
{:ok, decompressed, rest}on success, whererestis any unconsumed bytes following this block (e.g. the start of the next one).{:incomplete, missing_byte_count}if not enough bytes are buffered yet to make progress.missing_byte_countis how many more bytes are needed before callingdecode/1again is worth doing.{:error, reason}if the checksum doesn't match or the method byte is unrecognized.
Encodes iodata into a single compressed block envelope using method
(defaults to :lz4).