tinycode 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e5a75ffceb25e155db277a905e940cbf22a3f43a666113aede98b5457176aca
4
- data.tar.gz: f095520fdf8e46c939f7937957fb831951118d11ebef414a8d08bbee86b1a331
3
+ metadata.gz: 51316c829b7f063d80f30633476e3ce048309063f617b1b5f52112d1fdd7290a
4
+ data.tar.gz: 3228c7273c4a169a652cf0c6274137ad1ffc34c2474e6f5663f3e1810967199f
5
5
  SHA512:
6
- metadata.gz: 5146523a4517a8effb28f426c6922cb0338ec6a66de0a545b75385551e9a2ed0158e5292f8af441f15c1888cff7deb99e6e9550e029f26e3e7e5a16519a80255
7
- data.tar.gz: 0ad1a83f8c3f5d2a3ddbe5639d23e618a3dc4988825740d52ded2077188b5c373ce644b75b829be49fa0128fdad705fa690cc6b1107e4b0a0427361c3691bfa8
6
+ metadata.gz: f68d1910cfe364715c33008630506a9bc80145a9dee610032133c99ef7b608f2c95990ec5191e2b5098e0c2085efb357cfe82c65194f755a6a1286df675fbc0f
7
+ data.tar.gz: adfafe7da5332d5ebcbb264979095dcae55b67494778c0eb54ee5e81d2f225c8ea3059b1f8cb786228c6184a7e050dccfc13c0a691a3078b3b8b788f2803b5b5
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tinycode (0.2.0)
4
+ tinycode (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- diff-lcs (1.4.4)
10
+ diff-lcs (1.5.0)
11
11
  docile (1.4.0)
12
12
  ffi (1.15.4)
13
13
  listen (3.7.0)
14
14
  rb-fsevent (~> 0.10, >= 0.10.3)
15
15
  rb-inotify (~> 0.9, >= 0.9.10)
16
16
  parallel (1.21.0)
17
- parser (3.0.3.1)
17
+ parser (3.0.3.2)
18
18
  ast (~> 2.4.1)
19
19
  rainbow (3.0.0)
20
20
  rake (13.0.6)
@@ -38,20 +38,20 @@ GEM
38
38
  diff-lcs (>= 1.2.0, < 2.0)
39
39
  rspec-support (~> 3.10.0)
40
40
  rspec-support (3.10.3)
41
- rubocop (1.23.0)
41
+ rubocop (1.24.0)
42
42
  parallel (~> 1.10)
43
43
  parser (>= 3.0.0.0)
44
44
  rainbow (>= 2.2.2, < 4.0)
45
45
  regexp_parser (>= 1.8, < 3.0)
46
46
  rexml
47
- rubocop-ast (>= 1.12.0, < 2.0)
47
+ rubocop-ast (>= 1.15.0, < 2.0)
48
48
  ruby-progressbar (~> 1.7)
49
49
  unicode-display_width (>= 1.4.0, < 3.0)
50
- rubocop-ast (1.14.0)
50
+ rubocop-ast (1.15.1)
51
51
  parser (>= 3.0.1.1)
52
52
  rubocop-rake (0.6.0)
53
53
  rubocop (~> 1.0)
54
- rubocop-rspec (2.6.0)
54
+ rubocop-rspec (2.7.0)
55
55
  rubocop (~> 1.19)
56
56
  ruby-progressbar (1.11.0)
57
57
  simplecov (0.21.2)
@@ -81,4 +81,4 @@ DEPENDENCIES
81
81
  yard (~> 0.9)
82
82
 
83
83
  BUNDLED WITH
84
- 2.2.31
84
+ 2.2.32
@@ -52,6 +52,7 @@ module Tinycode
52
52
  when /[\w \t\n]/ then load_id(tinycode)
53
53
  when '[' then load_array(tinycode)
54
54
  when '{' then load_hash(tinycode)
55
+ when '@' then load_binary_string(tinycode)
55
56
  when "'" then load_string(tinycode)
56
57
  when ':' then load_symbol(tinycode)
57
58
  when '-', '+' then load_integer(tinycode)
@@ -101,7 +102,14 @@ module Tinycode
101
102
  end
102
103
 
103
104
  def dump_string(str, code: "'")
104
- str = str.encode('UTF-8').b unless str.encoding == Encoding::ASCII_8BIT
105
+ if str.encoding == Encoding::BINARY
106
+ raise if code != "'"
107
+
108
+ code = '@'
109
+ else
110
+ str = str.encode('UTF-8').b
111
+ end
112
+
105
113
  if str =~ /\A[\w \t\n][^':]*\z/
106
114
  [str, code].pack('a*a')
107
115
  else
@@ -110,32 +118,53 @@ module Tinycode
110
118
  end
111
119
 
112
120
  def load_id(tinycode)
113
- length = tinycode.index(/[':]/)
121
+ length = tinycode.index(/['@:]/)
114
122
  raise ParseError, 'Unexpected end of stream' if !length
115
123
 
116
- value = tinycode[0...length].force_encoding('UTF-8')
117
- raise ParseError, 'invalid byte sequence in UTF-8 string' if !value.valid_encoding?
124
+ value = tinycode[0...length]
125
+
126
+ case tinycode[length]
127
+ when "'"
128
+ value.force_encoding('UTF-8')
129
+ raise ParseError, 'invalid byte sequence in UTF-8 string' if !value.valid_encoding?
130
+ when '@'
131
+ # value is already binary
132
+ when ':'
133
+ value.force_encoding('UTF-8')
134
+ raise ParseError, 'invalid byte sequence in UTF-8 string' if !value.valid_encoding?
135
+
136
+ value = value.to_sym
137
+ else raise
138
+ end
118
139
 
119
- value = value.to_sym if tinycode[length] == ':'
120
140
  [value, length + 1]
121
141
  end
122
142
 
123
- def load_string(tinycode)
143
+ def load_binary_string(tinycode)
124
144
  str_length, offset = load_varint(tinycode[1..])
125
145
  raise ParseError, 'Unexpected end of stream' if tinycode.length < 1 + offset + str_length
126
146
 
127
- str = tinycode[(1 + offset)...(1 + offset + str_length)].force_encoding('UTF-8')
128
- raise ParseError, 'invalid byte sequence in UTF-8 string' if !str.valid_encoding?
147
+ str = tinycode[(1 + offset)...(1 + offset + str_length)]
129
148
 
130
149
  [str, 1 + offset + str_length]
131
150
  end
132
151
 
152
+ def load_string(tinycode)
153
+ value, offset = load_binary_string(tinycode)
154
+ value.force_encoding('UTF-8')
155
+ raise ParseError, 'invalid byte sequence in UTF-8 string' if !value.valid_encoding?
156
+
157
+ [value, offset]
158
+ end
159
+
133
160
  def dump_symbol(sym)
161
+ raise ArgumentError, "Symbol #{sym.inspect} must not be binary encoded" if sym.encoding == Encoding::BINARY
162
+
134
163
  dump_string(sym.to_s, code: ':')
135
164
  end
136
165
 
137
- def load_symbol(sym)
138
- value, offset = load_string(sym)
166
+ def load_symbol(tinycode)
167
+ value, offset = load_string(tinycode)
139
168
  [value.to_sym, offset]
140
169
  end
141
170
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tinycode
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinycode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Gittemeier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-05 00:00:00.000000000 Z
11
+ date: 2021-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.2.22
174
+ rubygems_version: 3.2.32
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: An encoder and decoder for tinycode