libbin 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fdf975677061cebffe202e1d86030fd8c84d32f28c90c6907abd964d854e0cf
4
- data.tar.gz: e54ea09722e208c8eb1368a73dbb9aa452e324e2b18dc59b007a826cb23c680a
3
+ metadata.gz: 230be2238c11ec4505d14cea8a43181b6b006cd3db0eccc4d40d1fb117912681
4
+ data.tar.gz: c21f1a9ab288be527d14eeea80f248f9332d98d3dc8351dd811536aaa24850f0
5
5
  SHA512:
6
- metadata.gz: 8490ee9cdec4a7268aeb19d2cd6bd37fa5af61930f1a3b3c1134e10768c211c2c67030054eb00bbd4c85ff6beff7c8b290ff4927ba86b45312168e49894695a3
7
- data.tar.gz: 95a9b0b79b0bca2f9c7f8eef6154788ce2838ac436b23f958b67af3485bee706dfee7f3720a6bb29e88746a4ba04967479347f9fde9250160ad9a0f57a0b0a61
6
+ metadata.gz: a8fbca741eb24035f80751e3eaf49a3b1b89ac1dbb8f4ae9cec3b58c77ddaf2e8b93c74af781cde5756e07d4a4fd115d07e703a8b5f8ba537da104c82f4a845d
7
+ data.tar.gz: 307b2a33d3d6d3357bc8c59079dfa0bbdb62a9e189894abde7d9b32bcf180c42b5614dcdb4ccdcebdc593c40e32afe59c3ad018db50a3ecff8568c833034778e
data/LICENSE CHANGED
File without changes
File without changes
data/ext/libbin/half.c CHANGED
File without changes
data/ext/libbin/half.h CHANGED
File without changes
File without changes
data/ext/libbin/pghalf.c CHANGED
File without changes
data/ext/libbin/pghalf.h CHANGED
File without changes
data/lib/libbin.rb CHANGED
@@ -117,10 +117,11 @@ module LibBin
117
117
  end
118
118
  end
119
119
 
120
- def __decode_seek_offset(offset)
120
+ def __decode_seek_offset(offset, relative_offset)
121
121
  return nil unless offset
122
122
  offset = __decode_expression(offset)
123
123
  return false if offset == 0x0
124
+ offset += @__position if relative_offset
124
125
  @__cur_position = offset
125
126
  @__input.seek(offset) if @__input
126
127
  @__output.seek(offset) if @__output
@@ -141,31 +142,31 @@ module LibBin
141
142
  return __decode_expression(type)
142
143
  end
143
144
 
144
- def __decode_static_conditions(type, count, offset, sequence, condition)
145
+ def __decode_static_conditions(field)
145
146
  @__offset = nil
146
147
  @__condition = nil
147
148
  @__type = nil
148
149
  @__count = nil
149
- unless sequence
150
- @__offset = __decode_seek_offset(offset)
150
+ unless field.sequence?
151
+ @__offset = __decode_seek_offset(field.offset, field.relative_offset?)
151
152
  throw :ignored, nil if @__offset == false
152
- @__condition = __decode_condition(condition)
153
+ @__condition = __decode_condition(field.condition)
153
154
  throw :ignored, nil unless @__condition
154
- @__type = __decode_type(type)
155
+ @__type = __decode_type(field.type)
155
156
  end
156
- @__count = __decode_count(count)
157
+ @__count = __decode_count(field.count)
157
158
  end
158
159
 
159
- def __decode_dynamic_conditions(type, offset, sequence, condition)
160
- return true unless sequence
160
+ def __decode_dynamic_conditions(field)
161
+ return true unless field.sequence?
161
162
  @__offset = nil
162
163
  @__condition = nil
163
164
  @__type = nil
164
- @__offset = __decode_seek_offset(offset)
165
+ @__offset = __decode_seek_offset(field.offset, field.relative_offset?)
165
166
  return false if @__offset == false
166
- @__condition = __decode_condition(condition)
167
+ @__condition = __decode_condition(field.condition)
167
168
  return false unless @__condition
168
- @__type = __decode_type(type)
169
+ @__type = __decode_type(field.type)
169
170
  return true
170
171
  end
171
172
 
@@ -177,61 +178,61 @@ module LibBin
177
178
  @__condition = nil
178
179
  end
179
180
 
180
- def __convert_field(field, type, count, offset, sequence, condition)
181
- __decode_static_conditions(type, count, offset, sequence, condition)
181
+ def __convert_field(field)
182
+ __decode_static_conditions(field)
182
183
  vs = @__count.times.collect do |it|
183
184
  @__iterator = it
184
- if __decode_dynamic_conditions(type, offset, sequence, condition)
185
+ if __decode_dynamic_conditions(field)
185
186
  @__type::convert(@__input, @__output, @__input_big, @__output_big, self, it)
186
187
  else
187
188
  nil
188
189
  end
189
190
  end
190
191
  __restore_context
191
- vs = vs.first unless count
192
+ vs = vs.first unless field.count
192
193
  vs
193
194
  end
194
195
 
195
- def __load_field(field, type, count, offset, sequence, condition)
196
- __decode_static_conditions(type, count, offset, sequence, condition)
196
+ def __load_field(field)
197
+ __decode_static_conditions(field)
197
198
  vs = @__count.times.collect do |it|
198
199
  @__iterator = it
199
- if __decode_dynamic_conditions(type, offset, sequence, condition)
200
+ if __decode_dynamic_conditions(field)
200
201
  @__type::load(@__input, @__input_big, self, it)
201
202
  else
202
203
  nil
203
204
  end
204
205
  end
205
206
  __restore_context
206
- vs = vs.first unless count
207
+ vs = vs.first unless field.count
207
208
  vs
208
209
  end
209
210
 
210
- def __dump_field(vs, field, type, count, offset, sequence, condition)
211
- __decode_static_conditions(type, count, offset, sequence, condition)
212
- vs = [vs] unless count
211
+ def __dump_field(vs, field)
212
+ __decode_static_conditions(field)
213
+ vs = [vs] unless field.count
213
214
  vs.each_with_index do |v, it|
214
215
  @__iterator = it
215
- if __decode_dynamic_conditions(type, offset, sequence, condition)
216
+ if __decode_dynamic_conditions(field)
216
217
  @__type::dump(v, @__output, @__output_big, self, it)
217
218
  end
218
219
  end
219
220
  __restore_context
220
221
  end
221
222
 
222
- def __shape_field(vs, previous_offset, kind, field, type, count, offset, sequence, condition)
223
- __decode_static_conditions(type, count, offset, sequence, condition)
224
- vs = [vs] unless count
223
+ def __shape_field(vs, previous_offset, kind, field)
224
+ __decode_static_conditions(field)
225
+ vs = [vs] unless field.count
225
226
  vs = vs.each_with_index.collect do |v, it|
226
227
  @__iterator = it
227
- if __decode_dynamic_conditions(type, offset, sequence, condition)
228
+ if __decode_dynamic_conditions(field)
228
229
  sh = @__type::shape(v, @__cur_position, self, it, kind)
229
230
  @__cur_position = sh.last + 1 if sh.last && sh.last >= 0
230
231
  sh
231
232
  end
232
233
  end
233
234
  __restore_context
234
- vs = vs.first unless count
235
+ vs = vs.first unless field.count
235
236
  vs
236
237
  end
237
238
 
@@ -242,15 +243,15 @@ module LibBin
242
243
  def __shape(previous_offset = 0, parent = nil, index = nil, kind = DataShape)
243
244
  __set_size_type(previous_offset, parent, index)
244
245
  members = {}
245
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
246
+ self.class.instance_variable_get(:@fields).each { |field|
246
247
  begin
247
- vs = send(name)
248
+ vs = send(field.name)
248
249
  member = catch(:ignored) do
249
- __shape_field(vs, previous_offset, kind, name, type, *args)
250
+ __shape_field(vs, previous_offset, kind, field)
250
251
  end
251
- members[name] = member
252
+ members[field.name] = member
252
253
  rescue
253
- STDERR.puts "#{self.class}: #{name}(#{type})"
254
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
254
255
  raise
255
256
  end
256
257
  }
@@ -260,14 +261,14 @@ module LibBin
260
261
  end
261
262
 
262
263
  def __convert_fields
263
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
264
+ self.class.instance_variable_get(:@fields).each { |field|
264
265
  begin
265
266
  vs = catch(:ignored) do
266
- __convert_field(name, type, *args)
267
+ __convert_field(field)
267
268
  end
268
- send("#{name}=", vs)
269
+ send("#{field.name}=", vs)
269
270
  rescue
270
- STDERR.puts "#{self.class}: #{name}(#{type})"
271
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
271
272
  raise
272
273
  end
273
274
  }
@@ -275,14 +276,14 @@ module LibBin
275
276
  end
276
277
 
277
278
  def __load_fields
278
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
279
+ self.class.instance_variable_get(:@fields).each { |field|
279
280
  begin
280
281
  vs = catch(:ignored) do
281
- __load_field(name, type, *args)
282
+ __load_field(field)
282
283
  end
283
- send("#{name}=", vs)
284
+ send("#{field.name}=", vs)
284
285
  rescue
285
- STDERR.puts "#{self.class}: #{name}(#{type})"
286
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
286
287
  raise
287
288
  end
288
289
  }
@@ -290,14 +291,14 @@ module LibBin
290
291
  end
291
292
 
292
293
  def __dump_fields
293
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
294
+ self.class.instance_variable_get(:@fields).each { |field|
294
295
  begin
295
- vs = send(name)
296
+ vs = send(field.name)
296
297
  catch(:ignored) do
297
- __dump_field(vs, name, type, *args)
298
+ __dump_field(vs, field)
298
299
  end
299
300
  rescue
300
- STDERR.puts "#{self.class}: #{name}(#{type})"
301
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
301
302
  raise
302
303
  end
303
304
  }
@@ -346,7 +347,7 @@ module LibBin
346
347
  end
347
348
 
348
349
  def self.shape(value, previous_offset = 0, parent = nil, index = nil, kind = DataShape)
349
- value.__shape(previous_offset, parent, index, kind = DataShape)
350
+ value.__shape(previous_offset, parent, index, kind)
350
351
  end
351
352
 
352
353
  end
File without changes
@@ -70,6 +70,34 @@ module LibBin
70
70
 
71
71
  end
72
72
 
73
+ class Field
74
+ attr_reader :name,
75
+ :type,
76
+ :count,
77
+ :offset,
78
+ :sequence,
79
+ :condition
80
+
81
+ def sequence?
82
+ @sequence
83
+ end
84
+
85
+ def relative_offset?
86
+ @relative_offset
87
+ end
88
+
89
+ def initialize(name, type, count, offset, sequence, condition, relative_offset)
90
+ @name = name
91
+ @type = type
92
+ @count = count
93
+ @offset = offset
94
+ @sequence = sequence
95
+ @condition = condition
96
+ @relative_offset = relative_offset
97
+ end
98
+
99
+ end
100
+
73
101
  class DataConverter
74
102
 
75
103
  rl = lambda { |type, str|
@@ -340,17 +368,17 @@ module LibBin
340
368
 
341
369
  end
342
370
 
343
- def self.register_field(field, type, count: nil, offset: nil, sequence: false, condition: nil)
371
+ def self.register_field(field, type, count: nil, offset: nil, sequence: false, condition: nil, relative_offset: false)
344
372
  if type.kind_of?(Symbol)
345
373
  if type[0] == 'a'
346
- c = Class::new(Str) do init(sym) end
347
- @fields.push([field, c, count, offset, sequence, condition])
374
+ real_type = Class::new(Str) do init(sym) end
348
375
  else
349
- @fields.push([field, const_get(SCALAR_TYPES[type][0]), count, offset, sequence, condition])
376
+ real_type = const_get(SCALAR_TYPES[type][0])
350
377
  end
351
378
  else
352
- @fields.push([field, type, count, offset, sequence, condition])
379
+ real_type = type
353
380
  end
381
+ @fields.push(Field::new(field, real_type, count, offset, sequence, condition, relative_offset))
354
382
  attr_accessor field
355
383
  end
356
384
 
@@ -361,8 +389,8 @@ module LibBin
361
389
  init(#{symbol.inspect})
362
390
  end
363
391
 
364
- def self.#{name}(field, count: nil, offset: nil, sequence: false, condition: nil)
365
- @fields.push([field, #{klassname}, count, offset, sequence, condition])
392
+ def self.#{name}(field, count: nil, offset: nil, sequence: false, condition: nil, relative_offset: false)
393
+ @fields.push(Field::new(field, #{klassname}, count, offset, sequence, condition, relative_offset))
366
394
  attr_accessor field
367
395
  end
368
396
  EOF
@@ -401,12 +429,12 @@ EOF
401
429
  create_scalar_type(:pghalf_le)
402
430
  create_scalar_type(:pghalf_be)
403
431
 
404
- def self.string( field, length = nil, count: nil, offset: nil, sequence: false, condition: nil)
432
+ def self.string( field, length = nil, count: nil, offset: nil, sequence: false, condition: nil, relative_offset: false)
405
433
  sym = (length ? :"a#{length}" : :"a*")
406
434
  c = Class::new(Str) do
407
435
  init(sym)
408
436
  end
409
- @fields.push([field, c, count, offset, sequence, condition])
437
+ @fields.push(Field::new(field, c, count, offset, sequence, condition, relative_offset))
410
438
  attr_accessor field
411
439
  end
412
440
 
data/libbin.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'libbin'
3
- s.version = "1.0.3"
3
+ s.version = "1.0.4"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://github.com/kerilk/libbin"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libbin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Videau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-04 00:00:00.000000000 Z
11
+ date: 2019-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: float-formats