paquito 0.9.0 → 0.9.2

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: 2882e208a7d6cc2c9b98f748578ea1c8e91133a5ecc71fdc4e41861bb7788f7e
4
- data.tar.gz: 8376bc939c974028dd6957e1d98467594c33807cdf13fc0470b216aa2476f9ce
3
+ metadata.gz: beedd98334166781382fbe4d773b19f27e58ea8cfe8c83fa211c745c7c752deb
4
+ data.tar.gz: 2912c724ee66b3b9547477e56aeb2bc1a0622128c41bf06b0be221c54eb0e8b0
5
5
  SHA512:
6
- metadata.gz: 7bb6ab11609d478cae8993c65fb12db8ea22363064401c718f6e6915ccdd75ad9ddd5c3f7a5a88a8c0562e943c2fda44c4dab101a3db4266f26134ae2ac0e26f
7
- data.tar.gz: 268549cd0b872b554397b7d685e0ba9f8db9572690091ebaa4936e7a488a26569e9691ad0bfdf2447d1521a36aa5c26b8a7acf96a04271d449c0a6036de7d777
6
+ metadata.gz: ba2c02fa73d7b1a27577e36c8f8e2a2ea73a57446939e0519ea3d1fbd1ababf6af4c0bdda47bfba074ce0af60ae0269c8ea838abcb5ad0cba75a5d2f81848297
7
+ data.tar.gz: fb527d860bfd14dd71c42c75320fd694ad1335ca4e21b7edacf798612b55125bd19d1a5bf7126f8e4770ad0b68c448d003fe8fad450b7686d7e8a97ad4921dbb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Unreleased
2
2
 
3
+
4
+ # 0.9.2
5
+
6
+ * Support cast of coder in translate errors. (#24)
7
+
8
+ # 0.9.1
9
+
10
+ * Fix a bug when handle `compress / decompress` coders. (#23)
11
+ * `SingleBytePrefixVersionWithStringBypass` accepts another coder for strings.
12
+
3
13
  # 0.9.0
4
14
 
5
15
  * Handle `compress / decompress` coders (#22)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paquito (0.9.0)
4
+ paquito (0.9.2)
5
5
  msgpack (>= 1.5.2)
6
6
 
7
7
  GEM
@@ -23,34 +23,40 @@ GEM
23
23
  concurrent-ruby (1.1.10)
24
24
  i18n (1.12.0)
25
25
  concurrent-ruby (~> 1.0)
26
+ json (2.6.3)
27
+ mini_portile2 (2.8.0)
26
28
  minitest (5.16.3)
27
29
  msgpack (1.6.0)
28
30
  parallel (1.22.1)
29
- parser (3.1.2.1)
31
+ parser (3.1.3.0)
30
32
  ast (~> 2.4.1)
31
33
  rainbow (3.1.1)
32
34
  rake (13.0.6)
33
- regexp_parser (2.5.0)
35
+ regexp_parser (2.6.1)
34
36
  rexml (3.2.5)
35
- rubocop (1.30.1)
37
+ rubocop (1.40.0)
38
+ json (~> 2.3)
36
39
  parallel (~> 1.10)
37
- parser (>= 3.1.0.0)
40
+ parser (>= 3.1.2.1)
38
41
  rainbow (>= 2.2.2, < 4.0)
39
42
  regexp_parser (>= 1.8, < 3.0)
40
43
  rexml (>= 3.2.5, < 4.0)
41
- rubocop-ast (>= 1.18.0, < 2.0)
44
+ rubocop-ast (>= 1.23.0, < 2.0)
42
45
  ruby-progressbar (~> 1.7)
43
46
  unicode-display_width (>= 1.4.0, < 3.0)
44
- rubocop-ast (1.21.0)
47
+ rubocop-ast (1.24.0)
45
48
  parser (>= 3.1.1.0)
46
- rubocop-shopify (2.5.0)
47
- rubocop (~> 1.25)
49
+ rubocop-shopify (2.10.1)
50
+ rubocop (~> 1.35)
48
51
  ruby-progressbar (1.11.0)
49
- sorbet-runtime (0.5.10365)
50
- sqlite3 (1.4.4)
52
+ sorbet-runtime (0.5.10577)
53
+ sqlite3 (1.5.4)
54
+ mini_portile2 (~> 2.8.0)
55
+ sqlite3 (1.5.4-x86_64-darwin)
56
+ sqlite3 (1.5.4-x86_64-linux)
51
57
  tzinfo (2.0.5)
52
58
  concurrent-ruby (~> 1.0)
53
- unicode-display_width (2.2.0)
59
+ unicode-display_width (2.3.0)
54
60
 
55
61
  PLATFORMS
56
62
  ruby
data/README.md CHANGED
@@ -70,6 +70,18 @@ in an optimized way.
70
70
  When the object to serialize is an `UTF-8`, `ASCII` or `BINARY` string, rather than invoking the underlying serializer, it simply
71
71
  prepends a single byte to the string which indicates the encoding.
72
72
 
73
+ Additionally, you can pass a distinct serializer for strings only:
74
+
75
+ Example:
76
+
77
+ ```ruby
78
+ coder = Paquito::SingleBytePrefixVersion.new(
79
+ 1,
80
+ { 0 => YAML, 1 => JSON },
81
+ Paquito::ConditionalCompressor.new(Zlib, 1024), # Large strings will be compressed but not serialized in JSON.
82
+ )
83
+ ```
84
+
73
85
  The larger the string the larger the speed gain is, e.g. for a 1MB string, it's over 500x faster than going through `MessagePack` or `Marshal`.
74
86
 
75
87
  ### `CommentPrefixVersion`
@@ -18,7 +18,7 @@ FLAT = Paquito::FlatCacheEntryCoder.new(
18
18
  Paquito::SingleBytePrefixVersionWithStringBypass.new(
19
19
  0,
20
20
  0 => CODEC,
21
- )
21
+ ),
22
22
  )
23
23
 
24
24
  entries = {
@@ -6,15 +6,20 @@ module Paquito
6
6
  BINARY_VERSION = 254
7
7
  ASCII_VERSION = 253
8
8
 
9
+ def initialize(current_version, coders, string_coder = nil)
10
+ super(current_version, coders)
11
+ @string_coder = string_coder
12
+ end
13
+
9
14
  def dump(object)
10
15
  if object.class == String # We don't want to match subclasses
11
16
  case object.encoding
12
17
  when Encoding::UTF_8
13
- UTF8_VERSION.chr(Encoding::BINARY) << object
18
+ UTF8_VERSION.chr(Encoding::BINARY) << (@string_coder ? @string_coder.dump(object) : object)
14
19
  when Encoding::BINARY
15
- BINARY_VERSION.chr(Encoding::BINARY) << object
20
+ BINARY_VERSION.chr(Encoding::BINARY) << (@string_coder ? @string_coder.dump(object) : object)
16
21
  when Encoding::US_ASCII
17
- ASCII_VERSION.chr(Encoding::BINARY) << object
22
+ ASCII_VERSION.chr(Encoding::BINARY) << (@string_coder ? @string_coder.dump(object) : object)
18
23
  else
19
24
  super
20
25
  end
@@ -31,11 +36,14 @@ module Paquito
31
36
 
32
37
  case payload_version
33
38
  when UTF8_VERSION
34
- payload.byteslice(1..-1).force_encoding(Encoding::UTF_8)
39
+ string = payload.byteslice(1..-1).force_encoding(Encoding::UTF_8)
40
+ @string_coder ? @string_coder.load(string) : string
35
41
  when BINARY_VERSION
36
- payload.byteslice(1..-1).force_encoding(Encoding::BINARY)
42
+ string = payload.byteslice(1..-1).force_encoding(Encoding::BINARY)
43
+ @string_coder ? @string_coder.load(string) : string
37
44
  when ASCII_VERSION
38
- payload.byteslice(1..-1).force_encoding(Encoding::US_ASCII)
45
+ string = payload.byteslice(1..-1).force_encoding(Encoding::US_ASCII)
46
+ @string_coder ? @string_coder.load(string) : string
39
47
  else
40
48
  coder = @coders.fetch(payload_version) do
41
49
  raise UnsupportedCodec, "Unsupported packer version #{payload_version}"
@@ -3,7 +3,7 @@
3
3
  module Paquito
4
4
  class TranslateErrors
5
5
  def initialize(coder)
6
- @coder = coder
6
+ @coder = Paquito.cast(coder)
7
7
  end
8
8
 
9
9
  def dump(object)
@@ -15,7 +15,7 @@ module Paquito
15
15
  0x7f,
16
16
  Object,
17
17
  packer: ->(value) { raise PackError.new("undeclared type", value) },
18
- unpacker: ->(*) {}
18
+ unpacker: ->(*) {},
19
19
  )
20
20
 
21
21
  core_types = [String, Integer, TrueClass, FalseClass, NilClass, Float, Array, Hash]
data/lib/paquito/types.rb CHANGED
@@ -217,7 +217,7 @@ module Paquito
217
217
  factory.register_type(
218
218
  type_attributes.fetch(:code),
219
219
  type,
220
- type_attributes
220
+ type_attributes,
221
221
  )
222
222
  end
223
223
  end
@@ -242,7 +242,7 @@ module Paquito
242
242
 
243
243
  unpacker = CustomTypesRegistry.unpacker(klass)
244
244
  unpacker.call(payload)
245
- end
245
+ end,
246
246
  )
247
247
  end
248
248
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paquito
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.2"
5
5
  end
data/lib/paquito.rb CHANGED
@@ -10,6 +10,7 @@ require "msgpack"
10
10
 
11
11
  require "paquito/version"
12
12
  require "paquito/deflater"
13
+ require "paquito/compressor"
13
14
  require "paquito/allow_nil"
14
15
  require "paquito/translate_errors"
15
16
  require "paquito/safe_yaml"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paquito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-08 00:00:00.000000000 Z
11
+ date: 2022-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack