Module: NNQ::Zstd

Defined in:
lib/nnq/zstd.rb,
lib/nnq/zstd.rb,
lib/nnq/zstd/codec.rb,
lib/nnq/zstd/version.rb,
lib/nnq/zstd/wrapper.rb

Defined Under Namespace

Classes: Codec, ProtocolError, Wrapper

Constant Summary collapse

RESERVED_DICT_ID_LOW_MAX =
32_767
RESERVED_DICT_ID_HIGH_MIN =
2**31
USER_DICT_ID_RANGE =
(32_768..(2**31 - 1)).freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.wrap(socket, level: -3,, dict: nil) ⇒ Object

Wraps an NNQ::Socket with transparent Zstd compression.

Both peers must wrap their sockets; there is no negotiation. See RFC.md for the wire protocol.

A receive-only “passive” decoder needs no special flag — wrap the socket and just never call ‘send`. Training is driven by outbound traffic, so a socket that only receives naturally skips training and dict shipping.

Parameters:

  • socket (NNQ::Socket)
  • level (Integer) (defaults to: -3,)

    Zstd level (default -3; fast strategy)

  • dict (String, Array<String>, nil) (defaults to: nil)

    pre-built dictionary bytes. If provided, training is skipped and all supplied dicts are shipped to peers on the wire. Each buffer MUST be a valid Zstd dictionary (ZDICT magic + header).



41
42
43
# File 'lib/nnq/zstd.rb', line 41

def self.wrap(socket, level: -3, dict: nil)
  Wrapper.new(socket, level: level, dicts: Array(dict).compact)
end