paquito 0.10.0 → 0.11.0
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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/cla.yml +22 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +32 -36
- data/dev.yml +1 -1
- data/lib/paquito/coder_chain.rb +2 -1
- data/lib/paquito/safe_yaml.rb +11 -2
- data/lib/paquito/types.rb +191 -141
- data/lib/paquito/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa49c77308b2c81f81faa1308ab462dd0bcc15f91244ab080800ffe0e2ebd9f
|
4
|
+
data.tar.gz: 8909a37d22acd65c197c2c38dbc2e8f2e8e717d61f848996058e1c764cdadba7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25f2d1f9e05ddf14b7edbb798acd253e0590089a6d70296c493d8f8cbb63a2abdbe2b4fcfee7e72d201226b1a729b31c8b3cd1cf240d000abd3db21a4e0ff2d4
|
7
|
+
data.tar.gz: 034dea4d9c9e276af49d5aa892e2231eeda24d275a32f846da246334fec167a8a3568972908ac75d8c413f794edfb418253732e903d5e7073e0625a9cff8019d
|
data/.github/workflows/ci.yml
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Contributor License Agreement (CLA)
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [opened, synchronize]
|
6
|
+
issue_comment:
|
7
|
+
types: [created]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
cla:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
if: |
|
13
|
+
(github.event.issue.pull_request
|
14
|
+
&& !github.event.issue.pull_request.merged_at
|
15
|
+
&& contains(github.event.comment.body, 'signed')
|
16
|
+
)
|
17
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
18
|
+
steps:
|
19
|
+
- uses: Shopify/shopify-cla-action@v1
|
20
|
+
with:
|
21
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 0.11.0
|
4
|
+
|
5
|
+
* Convert some lambdas into proper methods to make them more discoverable by profilers.
|
6
|
+
* Optimize `Time` and `ActiveSupport::TimeWithZone` serializers when `active_support/core_ext/time/calculations` is loaded.
|
7
|
+
|
3
8
|
# 0.10.0
|
4
9
|
|
5
10
|
* Introduce a new version `1` format that better handles `Time` and `DateTime` objects. It can be enabled by setting `Paquito.format_version = 1`.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,71 +1,67 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paquito (0.
|
4
|
+
paquito (0.11.0)
|
5
5
|
msgpack (>= 1.5.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (7.0.
|
11
|
-
activesupport (= 7.0.
|
12
|
-
activerecord (7.0.
|
13
|
-
activemodel (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
15
|
-
activesupport (7.0.
|
10
|
+
activemodel (7.0.7.1)
|
11
|
+
activesupport (= 7.0.7.1)
|
12
|
+
activerecord (7.0.7.1)
|
13
|
+
activemodel (= 7.0.7.1)
|
14
|
+
activesupport (= 7.0.7.1)
|
15
|
+
activesupport (7.0.7.1)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
20
|
ast (2.4.2)
|
21
|
-
benchmark-ips (2.
|
21
|
+
benchmark-ips (2.12.0)
|
22
22
|
byebug (11.1.3)
|
23
|
-
concurrent-ruby (1.
|
24
|
-
i18n (1.
|
23
|
+
concurrent-ruby (1.2.2)
|
24
|
+
i18n (1.14.1)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
26
|
json (2.6.3)
|
27
|
-
|
28
|
-
|
29
|
-
msgpack (1.6.0)
|
27
|
+
minitest (5.18.0)
|
28
|
+
msgpack (1.7.2)
|
30
29
|
parallel (1.22.1)
|
31
|
-
parser (3.1.
|
30
|
+
parser (3.2.1.1)
|
32
31
|
ast (~> 2.4.1)
|
33
32
|
rainbow (3.1.1)
|
34
33
|
rake (13.0.6)
|
35
|
-
regexp_parser (2.
|
34
|
+
regexp_parser (2.7.0)
|
36
35
|
rexml (3.2.5)
|
37
|
-
rubocop (1.
|
36
|
+
rubocop (1.48.1)
|
38
37
|
json (~> 2.3)
|
39
38
|
parallel (~> 1.10)
|
40
|
-
parser (>= 3.
|
39
|
+
parser (>= 3.2.0.0)
|
41
40
|
rainbow (>= 2.2.2, < 4.0)
|
42
41
|
regexp_parser (>= 1.8, < 3.0)
|
43
42
|
rexml (>= 3.2.5, < 4.0)
|
44
|
-
rubocop-ast (>= 1.
|
43
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
45
44
|
ruby-progressbar (~> 1.7)
|
46
|
-
unicode-display_width (>=
|
47
|
-
rubocop-ast (1.
|
48
|
-
parser (>= 3.
|
49
|
-
rubocop-shopify (2.
|
50
|
-
rubocop (~> 1.
|
51
|
-
ruby-progressbar (1.
|
52
|
-
sorbet-runtime (0.5.
|
53
|
-
sqlite3 (1.
|
54
|
-
|
55
|
-
|
56
|
-
sqlite3 (1.5.4-x86_64-linux)
|
57
|
-
tzinfo (2.0.5)
|
45
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
46
|
+
rubocop-ast (1.27.0)
|
47
|
+
parser (>= 3.2.1.0)
|
48
|
+
rubocop-shopify (2.12.0)
|
49
|
+
rubocop (~> 1.44)
|
50
|
+
ruby-progressbar (1.13.0)
|
51
|
+
sorbet-runtime (0.5.10712)
|
52
|
+
sqlite3 (1.6.1-arm64-darwin)
|
53
|
+
sqlite3 (1.6.1-x86_64-linux)
|
54
|
+
tzinfo (2.0.6)
|
58
55
|
concurrent-ruby (~> 1.0)
|
59
|
-
unicode-display_width (2.
|
56
|
+
unicode-display_width (2.4.2)
|
60
57
|
|
61
58
|
PLATFORMS
|
62
|
-
|
63
|
-
x86_64-darwin-20
|
59
|
+
arm64-darwin
|
64
60
|
x86_64-linux
|
65
61
|
|
66
62
|
DEPENDENCIES
|
67
|
-
activerecord
|
68
|
-
activesupport
|
63
|
+
activerecord (>= 7)
|
64
|
+
activesupport (>= 7)
|
69
65
|
benchmark-ips
|
70
66
|
byebug
|
71
67
|
minitest (~> 5.0)
|
@@ -77,4 +73,4 @@ DEPENDENCIES
|
|
77
73
|
sqlite3
|
78
74
|
|
79
75
|
BUNDLED WITH
|
80
|
-
2.3.
|
76
|
+
2.3.22
|
data/dev.yml
CHANGED
data/lib/paquito/coder_chain.rb
CHANGED
@@ -4,6 +4,7 @@ module Paquito
|
|
4
4
|
class CoderChain
|
5
5
|
def initialize(*coders)
|
6
6
|
@coders = coders.flatten.map { |c| Paquito.cast(c) }
|
7
|
+
@reverse_coders = @coders.reverse
|
7
8
|
end
|
8
9
|
|
9
10
|
def dump(object)
|
@@ -14,7 +15,7 @@ module Paquito
|
|
14
15
|
|
15
16
|
def load(payload)
|
16
17
|
object = payload
|
17
|
-
@
|
18
|
+
@reverse_coders.each { |c| object = c.load(object) }
|
18
19
|
object
|
19
20
|
end
|
20
21
|
end
|
data/lib/paquito/safe_yaml.rb
CHANGED
@@ -3,8 +3,17 @@
|
|
3
3
|
module Paquito
|
4
4
|
class SafeYAML
|
5
5
|
ALL_SYMBOLS = [].freeze # Restricting symbols isn't really useful since symbols are no longer immortal
|
6
|
-
BASE_PERMITTED_CLASSNAMES = [
|
7
|
-
|
6
|
+
BASE_PERMITTED_CLASSNAMES = [
|
7
|
+
"TrueClass",
|
8
|
+
"FalseClass",
|
9
|
+
"NilClass",
|
10
|
+
"Numeric",
|
11
|
+
"String",
|
12
|
+
"Array",
|
13
|
+
"Hash",
|
14
|
+
"Integer",
|
15
|
+
"Float",
|
16
|
+
].freeze
|
8
17
|
|
9
18
|
def initialize(permitted_classes: [], deprecated_classes: [], aliases: false)
|
10
19
|
permitted_classes += BASE_PERMITTED_CLASSNAMES
|
data/lib/paquito/types.rb
CHANGED
@@ -75,6 +75,181 @@ module Paquito
|
|
75
75
|
|
76
76
|
# Do not change any #code, this would break current codecs.
|
77
77
|
# New types can be added as long as they have unique #code.
|
78
|
+
class << self
|
79
|
+
def time_pack_deprecated(value)
|
80
|
+
rational = value.to_r
|
81
|
+
if rational.numerator > MAX_INT64 || rational.denominator > MAX_UINT32
|
82
|
+
raise PackError, "Time instance out of bounds (#{rational.inspect}), see: https://github.com/Shopify/paquito/issues/26"
|
83
|
+
end
|
84
|
+
|
85
|
+
[rational.numerator, rational.denominator].pack(TIME_FORMAT)
|
86
|
+
end
|
87
|
+
|
88
|
+
def time_unpack_deprecated(payload)
|
89
|
+
numerator, denominator = payload.unpack(TIME_FORMAT)
|
90
|
+
at = begin
|
91
|
+
Rational(numerator, denominator)
|
92
|
+
rescue ZeroDivisionError
|
93
|
+
raise UnpackError, "Corrupted Time object, see: https://github.com/Shopify/paquito/issues/26"
|
94
|
+
end
|
95
|
+
Time.at(at).utc
|
96
|
+
end
|
97
|
+
|
98
|
+
def datetime_pack_deprecated(value)
|
99
|
+
sec = value.sec + value.sec_fraction
|
100
|
+
offset = value.offset
|
101
|
+
|
102
|
+
if sec.numerator > MAX_INT64 || sec.denominator > MAX_UINT32
|
103
|
+
raise PackError, "DateTime#sec_fraction out of bounds (#{sec.inspect}), see: https://github.com/Shopify/paquito/issues/26"
|
104
|
+
end
|
105
|
+
|
106
|
+
if offset.numerator > MAX_INT64 || offset.denominator > MAX_UINT32
|
107
|
+
raise PackError, "DateTime#offset out of bounds (#{offset.inspect}), see: https://github.com/Shopify/paquito/issues/26"
|
108
|
+
end
|
109
|
+
|
110
|
+
[
|
111
|
+
value.year,
|
112
|
+
value.month,
|
113
|
+
value.day,
|
114
|
+
value.hour,
|
115
|
+
value.minute,
|
116
|
+
sec.numerator,
|
117
|
+
sec.denominator,
|
118
|
+
offset.numerator,
|
119
|
+
offset.denominator,
|
120
|
+
].pack(DATE_TIME_FORMAT)
|
121
|
+
end
|
122
|
+
|
123
|
+
def datetime_unpack_deprecated(payload)
|
124
|
+
(
|
125
|
+
year,
|
126
|
+
month,
|
127
|
+
day,
|
128
|
+
hour,
|
129
|
+
minute,
|
130
|
+
sec_numerator,
|
131
|
+
sec_denominator,
|
132
|
+
offset_numerator,
|
133
|
+
offset_denominator,
|
134
|
+
) = payload.unpack(DATE_TIME_FORMAT)
|
135
|
+
|
136
|
+
begin
|
137
|
+
::DateTime.new(
|
138
|
+
year,
|
139
|
+
month,
|
140
|
+
day,
|
141
|
+
hour,
|
142
|
+
minute,
|
143
|
+
Rational(sec_numerator, sec_denominator),
|
144
|
+
Rational(offset_numerator, offset_denominator),
|
145
|
+
)
|
146
|
+
rescue ZeroDivisionError
|
147
|
+
raise UnpackError, "Corrupted DateTime object, see: https://github.com/Shopify/paquito/issues/26"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def date_pack(value)
|
152
|
+
[value.year, value.month, value.day].pack(DATE_FORMAT)
|
153
|
+
end
|
154
|
+
|
155
|
+
def date_unpack(payload)
|
156
|
+
year, month, day = payload.unpack(DATE_FORMAT)
|
157
|
+
::Date.new(year, month, day)
|
158
|
+
end
|
159
|
+
|
160
|
+
def hash_with_indifferent_access_pack(value, packer)
|
161
|
+
unless value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
|
162
|
+
raise PackError.new("cannot pack HashWithIndifferentClass subclass", value)
|
163
|
+
end
|
164
|
+
|
165
|
+
packer.write(value.to_h)
|
166
|
+
end
|
167
|
+
|
168
|
+
def hash_with_indifferent_access_unpack(unpacker)
|
169
|
+
ActiveSupport::HashWithIndifferentAccess.new(unpacker.read)
|
170
|
+
end
|
171
|
+
|
172
|
+
def time_with_zone_deprecated_pack(value)
|
173
|
+
[
|
174
|
+
value.utc.to_i,
|
175
|
+
(value.time.sec_fraction * 1_000_000_000).to_i,
|
176
|
+
value.time_zone.name,
|
177
|
+
].pack(TIME_WITH_ZONE_FORMAT)
|
178
|
+
end
|
179
|
+
|
180
|
+
def time_with_zone_deprecated_unpack(payload)
|
181
|
+
sec, nsec, time_zone_name = payload.unpack(TIME_WITH_ZONE_FORMAT)
|
182
|
+
time = Time.at(sec, nsec, :nsec, in: 0).utc
|
183
|
+
time_zone = ::Time.find_zone(time_zone_name)
|
184
|
+
ActiveSupport::TimeWithZone.new(time, time_zone)
|
185
|
+
end
|
186
|
+
|
187
|
+
def time_pack(value, packer)
|
188
|
+
packer.write(value.tv_sec)
|
189
|
+
packer.write(value.tv_nsec)
|
190
|
+
packer.write(value.utc_offset)
|
191
|
+
end
|
192
|
+
|
193
|
+
if ::Time.respond_to?(:at_without_coercion) # Ref: https://github.com/rails/rails/pull/50268
|
194
|
+
def time_unpack(unpacker)
|
195
|
+
::Time.at_without_coercion(unpacker.read, unpacker.read, :nanosecond, in: unpacker.read)
|
196
|
+
end
|
197
|
+
else
|
198
|
+
def time_unpack(unpacker)
|
199
|
+
::Time.at(unpacker.read, unpacker.read, :nanosecond, in: unpacker.read)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def datetime_pack(value, packer)
|
204
|
+
packer.write(value.year)
|
205
|
+
packer.write(value.month)
|
206
|
+
packer.write(value.day)
|
207
|
+
packer.write(value.hour)
|
208
|
+
packer.write(value.minute)
|
209
|
+
|
210
|
+
sec = value.sec + value.sec_fraction
|
211
|
+
packer.write(sec.numerator)
|
212
|
+
packer.write(sec.denominator)
|
213
|
+
|
214
|
+
offset = value.offset
|
215
|
+
packer.write(offset.numerator)
|
216
|
+
packer.write(offset.denominator)
|
217
|
+
end
|
218
|
+
|
219
|
+
def datetime_unpack(unpacker)
|
220
|
+
::DateTime.new(
|
221
|
+
unpacker.read, # year
|
222
|
+
unpacker.read, # month
|
223
|
+
unpacker.read, # day
|
224
|
+
unpacker.read, # hour
|
225
|
+
unpacker.read, # minute
|
226
|
+
Rational(unpacker.read, unpacker.read), # sec fraction
|
227
|
+
Rational(unpacker.read, unpacker.read), # offset fraction
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
231
|
+
def time_with_zone_pack(value, packer)
|
232
|
+
time = value.utc
|
233
|
+
packer.write(time.tv_sec)
|
234
|
+
packer.write(time.tv_nsec)
|
235
|
+
packer.write(value.time_zone.name)
|
236
|
+
end
|
237
|
+
|
238
|
+
if ::Time.respond_to?(:at_without_coercion) # Ref: https://github.com/rails/rails/pull/50268
|
239
|
+
def time_with_zone_unpack(unpacker)
|
240
|
+
utc = ::Time.at_without_coercion(unpacker.read, unpacker.read, :nanosecond, in: "UTC")
|
241
|
+
time_zone = ::Time.find_zone(unpacker.read)
|
242
|
+
ActiveSupport::TimeWithZone.new(utc, time_zone)
|
243
|
+
end
|
244
|
+
else
|
245
|
+
def time_with_zone_unpack(unpacker)
|
246
|
+
utc = ::Time.at(unpacker.read, unpacker.read, :nanosecond, in: "UTC")
|
247
|
+
time_zone = ::Time.find_zone(unpacker.read)
|
248
|
+
ActiveSupport::TimeWithZone.new(utc, time_zone)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
78
253
|
TYPES = [
|
79
254
|
{
|
80
255
|
code: 0,
|
@@ -88,91 +263,22 @@ module Paquito
|
|
88
263
|
code: 1,
|
89
264
|
class: "Time",
|
90
265
|
version: 0,
|
91
|
-
packer:
|
92
|
-
|
93
|
-
if rational.numerator > MAX_INT64 || rational.denominator > MAX_UINT32
|
94
|
-
raise PackError, "Time instance out of bounds (#{rational.inspect}), see: https://github.com/Shopify/paquito/issues/26"
|
95
|
-
end
|
96
|
-
|
97
|
-
[rational.numerator, rational.denominator].pack(TIME_FORMAT)
|
98
|
-
end,
|
99
|
-
unpacker: ->(value) do
|
100
|
-
numerator, denominator = value.unpack(TIME_FORMAT)
|
101
|
-
at = begin
|
102
|
-
Rational(numerator, denominator)
|
103
|
-
rescue ZeroDivisionError
|
104
|
-
raise UnpackError, "Corrupted Time object, see: https://github.com/Shopify/paquito/issues/26"
|
105
|
-
end
|
106
|
-
Time.at(at).utc
|
107
|
-
end,
|
266
|
+
packer: method(:time_pack_deprecated),
|
267
|
+
unpacker: method(:time_unpack_deprecated),
|
108
268
|
}.freeze,
|
109
269
|
{
|
110
270
|
code: 2,
|
111
271
|
class: "DateTime",
|
112
272
|
version: 0,
|
113
|
-
packer:
|
114
|
-
|
115
|
-
offset = value.offset
|
116
|
-
|
117
|
-
if sec.numerator > MAX_INT64 || sec.denominator > MAX_UINT32
|
118
|
-
raise PackError, "DateTime#sec_fraction out of bounds (#{sec.inspect}), see: https://github.com/Shopify/paquito/issues/26"
|
119
|
-
end
|
120
|
-
|
121
|
-
if offset.numerator > MAX_INT64 || offset.denominator > MAX_UINT32
|
122
|
-
raise PackError, "DateTime#offset out of bounds (#{offset.inspect}), see: https://github.com/Shopify/paquito/issues/26"
|
123
|
-
end
|
124
|
-
|
125
|
-
[
|
126
|
-
value.year,
|
127
|
-
value.month,
|
128
|
-
value.day,
|
129
|
-
value.hour,
|
130
|
-
value.minute,
|
131
|
-
sec.numerator,
|
132
|
-
sec.denominator,
|
133
|
-
offset.numerator,
|
134
|
-
offset.denominator,
|
135
|
-
].pack(DATE_TIME_FORMAT)
|
136
|
-
end,
|
137
|
-
unpacker: ->(value) do
|
138
|
-
(
|
139
|
-
year,
|
140
|
-
month,
|
141
|
-
day,
|
142
|
-
hour,
|
143
|
-
minute,
|
144
|
-
sec_numerator,
|
145
|
-
sec_denominator,
|
146
|
-
offset_numerator,
|
147
|
-
offset_denominator,
|
148
|
-
) = value.unpack(DATE_TIME_FORMAT)
|
149
|
-
|
150
|
-
begin
|
151
|
-
::DateTime.new(
|
152
|
-
year,
|
153
|
-
month,
|
154
|
-
day,
|
155
|
-
hour,
|
156
|
-
minute,
|
157
|
-
Rational(sec_numerator, sec_denominator),
|
158
|
-
Rational(offset_numerator, offset_denominator),
|
159
|
-
)
|
160
|
-
rescue ZeroDivisionError
|
161
|
-
raise UnpackError, "Corrupted DateTime object, see: https://github.com/Shopify/paquito/issues/26"
|
162
|
-
end
|
163
|
-
end,
|
273
|
+
packer: method(:datetime_pack_deprecated),
|
274
|
+
unpacker: method(:datetime_unpack_deprecated),
|
164
275
|
}.freeze,
|
165
276
|
{
|
166
277
|
code: 3,
|
167
278
|
class: "Date",
|
168
279
|
version: 0,
|
169
|
-
packer:
|
170
|
-
|
171
|
-
end,
|
172
|
-
unpacker: ->(value) do
|
173
|
-
year, month, day = value.unpack(DATE_FORMAT)
|
174
|
-
::Date.new(year, month, day)
|
175
|
-
end,
|
280
|
+
packer: method(:date_pack),
|
281
|
+
unpacker: method(:date_unpack),
|
176
282
|
}.freeze,
|
177
283
|
{
|
178
284
|
code: 4,
|
@@ -193,33 +299,16 @@ module Paquito
|
|
193
299
|
code: 7,
|
194
300
|
class: "ActiveSupport::HashWithIndifferentAccess",
|
195
301
|
version: 0,
|
196
|
-
packer:
|
197
|
-
|
198
|
-
raise PackError.new("cannot pack HashWithIndifferentClass subclass", value)
|
199
|
-
end
|
200
|
-
|
201
|
-
packer.write(value.to_h)
|
202
|
-
end,
|
203
|
-
unpacker: ->(unpacker) { ActiveSupport::HashWithIndifferentAccess.new(unpacker.read) },
|
302
|
+
packer: method(:hash_with_indifferent_access_pack),
|
303
|
+
unpacker: method(:hash_with_indifferent_access_unpack),
|
204
304
|
recursive: true,
|
205
305
|
}.freeze,
|
206
306
|
{
|
207
307
|
code: 8,
|
208
308
|
class: "ActiveSupport::TimeWithZone",
|
209
309
|
version: 0,
|
210
|
-
packer:
|
211
|
-
|
212
|
-
value.utc.to_i,
|
213
|
-
(value.time.sec_fraction * 1_000_000_000).to_i,
|
214
|
-
value.time_zone.name,
|
215
|
-
].pack(TIME_WITH_ZONE_FORMAT)
|
216
|
-
end,
|
217
|
-
unpacker: ->(value) do
|
218
|
-
sec, nsec, time_zone_name = value.unpack(TIME_WITH_ZONE_FORMAT)
|
219
|
-
time = Time.at(sec, nsec, :nsec, in: 0).utc
|
220
|
-
time_zone = ::Time.find_zone(time_zone_name)
|
221
|
-
ActiveSupport::TimeWithZone.new(time, time_zone)
|
222
|
-
end,
|
310
|
+
packer: method(:time_with_zone_deprecated_pack),
|
311
|
+
unpacker: method(:time_with_zone_deprecated_unpack),
|
223
312
|
}.freeze,
|
224
313
|
{
|
225
314
|
code: 9,
|
@@ -235,63 +324,24 @@ module Paquito
|
|
235
324
|
class: "Time",
|
236
325
|
version: 1,
|
237
326
|
recursive: true,
|
238
|
-
packer:
|
239
|
-
|
240
|
-
packer.write(value.tv_nsec)
|
241
|
-
packer.write(value.utc_offset)
|
242
|
-
end,
|
243
|
-
unpacker: ->(unpacker) do
|
244
|
-
::Time.at(unpacker.read, unpacker.read, :nanosecond, in: unpacker.read)
|
245
|
-
end,
|
327
|
+
packer: method(:time_pack),
|
328
|
+
unpacker: method(:time_unpack),
|
246
329
|
}.freeze,
|
247
330
|
{
|
248
331
|
code: 12,
|
249
332
|
class: "DateTime",
|
250
333
|
version: 1,
|
251
334
|
recursive: true,
|
252
|
-
packer:
|
253
|
-
|
254
|
-
packer.write(value.month)
|
255
|
-
packer.write(value.day)
|
256
|
-
packer.write(value.hour)
|
257
|
-
packer.write(value.minute)
|
258
|
-
|
259
|
-
sec = value.sec + value.sec_fraction
|
260
|
-
packer.write(sec.numerator)
|
261
|
-
packer.write(sec.denominator)
|
262
|
-
|
263
|
-
offset = value.offset
|
264
|
-
packer.write(offset.numerator)
|
265
|
-
packer.write(offset.denominator)
|
266
|
-
end,
|
267
|
-
unpacker: ->(unpacker) do
|
268
|
-
::DateTime.new(
|
269
|
-
unpacker.read, # year
|
270
|
-
unpacker.read, # month
|
271
|
-
unpacker.read, # day
|
272
|
-
unpacker.read, # hour
|
273
|
-
unpacker.read, # minute
|
274
|
-
Rational(unpacker.read, unpacker.read), # sec fraction
|
275
|
-
Rational(unpacker.read, unpacker.read), # offset fraction
|
276
|
-
)
|
277
|
-
end,
|
335
|
+
packer: method(:datetime_pack),
|
336
|
+
unpacker: method(:datetime_unpack),
|
278
337
|
}.freeze,
|
279
338
|
{
|
280
339
|
code: 13,
|
281
340
|
class: "ActiveSupport::TimeWithZone",
|
282
341
|
version: 1,
|
283
342
|
recursive: true,
|
284
|
-
packer:
|
285
|
-
|
286
|
-
packer.write(time.tv_sec)
|
287
|
-
packer.write(time.tv_nsec)
|
288
|
-
packer.write(value.time_zone.name)
|
289
|
-
end,
|
290
|
-
unpacker: ->(unpacker) do
|
291
|
-
utc = ::Time.at(unpacker.read, unpacker.read, :nanosecond, in: "UTC")
|
292
|
-
time_zone = ::Time.find_zone(unpacker.read)
|
293
|
-
ActiveSupport::TimeWithZone.new(utc, time_zone)
|
294
|
-
end,
|
343
|
+
packer: method(:time_with_zone_pack),
|
344
|
+
unpacker: method(:time_with_zone_unpack),
|
295
345
|
}.freeze,
|
296
346
|
# { code: 127, class: "Object" }, reserved for serializable Object type
|
297
347
|
]
|
data/lib/paquito/version.rb
CHANGED
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -32,6 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".github/workflows/ci.yml"
|
35
|
+
- ".github/workflows/cla.yml"
|
35
36
|
- ".gitignore"
|
36
37
|
- ".rubocop.yml"
|
37
38
|
- CHANGELOG.md
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.4.22
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Framework for defining efficient and extendable serializers
|