omq-zstd 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e725966f3527f9ad15396b9dc6b4a182a93a3cdf5b1f6916b6ccb25ba39b146
4
- data.tar.gz: 4c6bc2ed5ba87c77868ff93781dc9269a8929b78df8e190097bc943e84c2c46c
3
+ metadata.gz: 0460be7b61085b54ba2e2de90033ed296524f08bfd56db2385ba3c69284713f1
4
+ data.tar.gz: 0061e9188f071929d68a19415fcd3207fae5f929cdddf80bd022e127007302e3
5
5
  SHA512:
6
- metadata.gz: fa50d84a5d8a53a0a0bad2c5df4cee8d9435f04612f260082d02a226740f438d91f33702e29c3b974fda0ef6302080ab96d61a4e804e0abb409b2892a7f24e92
7
- data.tar.gz: 74119b06fa29d1dc339803c153fe2571c9d401d638a6fdc36cf1b5c64e28f2ba951e935ebbe7203475332d58c1e3a4be2622fb2acd5ac5da9ff713122f10d53b
6
+ metadata.gz: 6730b00146a3ce45053466f14496b792b6cf619557555dafaed72debcd667c3dedf6a06200036114afb7adda81183c276d6212f42652a03b40ac62f13d2fa947
7
+ data.tar.gz: 46519bf5bf3e3f3f944404aa174591a49faa240946acce52f743cf0fcb5263a7a3a609d26667eb6bd2f1f38f406be22779c26ffad81e5f9c6f122f3379474536
data/DESIGN.md CHANGED
@@ -151,7 +151,6 @@ individual parts are within bounds.
151
151
  ## Constants
152
152
 
153
153
  ```
154
- MAX_DECOMPRESSED_SIZE = 16 MiB (absolute cap per frame)
155
154
  MAX_DICT_SIZE = 64 KiB (reject oversized dicts)
156
155
  DICT_CAPACITY = 8 KiB (training target size)
157
156
  TRAIN_MAX_SAMPLES = 1000
data/RFC.md CHANGED
@@ -435,7 +435,6 @@ DEFAULT_LEVEL = -3
435
435
  MIN_COMPRESS_NO_DICT = 512 bytes
436
436
  MIN_COMPRESS_WITH_DICT = 64 bytes
437
437
 
438
- MAX_DECOMPRESSED_SIZE = 16 MiB (absolute cap per frame)
439
438
  MAX_DICT_SIZE = 64 KiB
440
439
 
441
440
  TRAIN_MAX_SAMPLES = 1000
@@ -26,7 +26,12 @@ module OMQ
26
26
  @level = level
27
27
  @max_message_size = max_message_size
28
28
 
29
- @send_dict = nil
29
+ # Start with a no-dict FrameCodec. Once a dict is configured
30
+ # (either via the `dict:` kwarg or via auto-training), this is
31
+ # replaced with a fresh dict-bound FrameCodec — per rzstd 0.4,
32
+ # dict is a permanent property of the codec, so swapping dicts
33
+ # means constructing a new one.
34
+ @send_codec = RZstd::FrameCodec.new(level: @level)
30
35
  @send_dict_bytes = nil
31
36
 
32
37
  @training = dict.nil?
@@ -108,7 +113,7 @@ module OMQ
108
113
  @training = false
109
114
  @train_samples = nil
110
115
 
111
- patched = patch_auto_dict_id(trained)
116
+ patched = patch_auto_dict_id(trained.bytes)
112
117
  install_send_dict(patched)
113
118
  end
114
119
 
@@ -130,22 +135,20 @@ module OMQ
130
135
  raise ProtocolError, "dict exceeds #{MAX_DICT_SIZE} bytes"
131
136
  end
132
137
 
133
- @send_dict = RZstd::Dictionary.new(bytes, level: @level)
138
+ # Replace the no-dict send codec with a fresh dict-bound one;
139
+ # the old codec is GC'd. rzstd 0.4 treats dict as a permanent
140
+ # codec property, so install-time is always a fresh build.
141
+ @send_codec = RZstd::FrameCodec.new(dict: bytes, level: @level)
134
142
  @send_dict_bytes = bytes
135
143
  end
136
144
 
137
145
 
138
146
  def compress_or_plain(part)
139
147
  bytes = part.is_a?(String) && part.encoding == Encoding::BINARY ? part : part.to_s.b
140
- threshold = @send_dict ? MIN_COMPRESS_WITH_DICT : MIN_COMPRESS_NO_DICT
148
+ threshold = @send_dict_bytes ? MIN_COMPRESS_WITH_DICT : MIN_COMPRESS_NO_DICT
141
149
  return plain(bytes) if bytes.bytesize < threshold
142
150
 
143
- compressed =
144
- if @send_dict
145
- @send_dict.compress(bytes)
146
- else
147
- RZstd.compress(bytes, level: @level)
148
- end
151
+ compressed = @send_codec.compress(bytes)
149
152
 
150
153
  return plain(bytes) if compressed.bytesize >= bytes.bytesize - 4
151
154
 
@@ -15,7 +15,13 @@ module OMQ
15
15
  super(conn)
16
16
  @codec = codec
17
17
  @dict_shipped = false
18
- @recv_dict = nil
18
+ # rzstd 0.4: FrameCodec is the decoder. Starts no-dict; when a
19
+ # dict shipment arrives on this direction, we build a fresh
20
+ # dict-bound FrameCodec and replace this one. Level is a
21
+ # compression parameter only — not consulted on decompress —
22
+ # so we don't carry the send-side level through to recv.
23
+ @recv_codec = RZstd::FrameCodec.new
24
+ @recv_dict_bytes = nil
19
25
  @last_wire_size_in = nil
20
26
  end
21
27
 
@@ -122,11 +128,7 @@ module OMQ
122
128
 
123
129
  decompress_opts = budget ? { max_output_size: budget } : {}
124
130
 
125
- if @recv_dict
126
- @recv_dict.decompress(wire, **decompress_opts)
127
- else
128
- RZstd.decompress(wire, **decompress_opts)
129
- end
131
+ @recv_codec.decompress(wire, **decompress_opts)
130
132
  rescue RZstd::DecompressError => e
131
133
  raise ProtocolError, "decompression failed: #{e.message}"
132
134
  rescue RZstd::MissingContentSizeError => e
@@ -145,7 +147,11 @@ module OMQ
145
147
  raise ProtocolError, "dict exceeds #{Codec::MAX_DICT_SIZE} bytes"
146
148
  end
147
149
 
148
- @recv_dict = RZstd::Dictionary.new(wire.b)
150
+ # Replace the no-dict recv codec with a fresh dict-bound one;
151
+ # the old codec is GC'd (rzstd 0.4: dict is a permanent codec
152
+ # property).
153
+ @recv_codec = RZstd::FrameCodec.new(dict: wire.b)
154
+ @recv_dict_bytes = wire.b
149
155
  end
150
156
 
151
157
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OMQ
4
4
  module Zstd
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omq-zstd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -27,16 +27,16 @@ dependencies:
27
27
  name: rzstd
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - ">="
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.2'
32
+ version: '0.4'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.2'
39
+ version: '0.4'
40
40
  description: Adds zstd+tcp:// endpoint support to OMQ with per-frame Zstd compression,
41
41
  bounded decompression, in-band dictionary shipping, and sender-side dictionary training.
42
42
  email: