libbin 1.0.0 → 1.0.5

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.
@@ -0,0 +1,9 @@
1
+ #ifndef PGHALF_H
2
+ #define PGHALF_H
3
+
4
+ #include <stdint.h>
5
+
6
+ uint32_t pghalf_to_float( uint16_t h );
7
+ uint16_t pghalf_from_float( uint32_t f );
8
+
9
+ #endif /* PGHALF_H */
@@ -1,10 +1,6 @@
1
- warn_level = $VERBOSE
2
- $VERBOSE = nil
3
- require 'float-formats'
4
- $VERBOSE = warn_level
5
-
6
- Flt::IEEE.binary :IEEE_binary16_pg, significand: 9, exponent: 6, bias: 47
7
- Flt::IEEE.binary :IEEE_binary16_pg_BE, significand: 9, exponent: 6, bias: 47, endianness: :big_endian
1
+ module LibBin
2
+ end
3
+ require "libbin_c.so"
8
4
 
9
5
  require_relative 'libbin/alignment'
10
6
  require_relative 'libbin/data_types'
@@ -121,10 +117,11 @@ module LibBin
121
117
  end
122
118
  end
123
119
 
124
- def __decode_seek_offset(offset)
120
+ def __decode_seek_offset(offset, relative_offset)
125
121
  return nil unless offset
126
122
  offset = __decode_expression(offset)
127
123
  return false if offset == 0x0
124
+ offset += @__position if relative_offset
128
125
  @__cur_position = offset
129
126
  @__input.seek(offset) if @__input
130
127
  @__output.seek(offset) if @__output
@@ -145,97 +142,106 @@ module LibBin
145
142
  return __decode_expression(type)
146
143
  end
147
144
 
148
- def __decode_static_conditions(type, count, offset, sequence, condition)
145
+ def __decode_length(length)
146
+ __decode_expression(length)
147
+ end
148
+
149
+ def __decode_static_conditions(field)
149
150
  @__offset = nil
150
151
  @__condition = nil
151
152
  @__type = nil
153
+ @__length = nil
152
154
  @__count = nil
153
- unless sequence
154
- @__offset = __decode_seek_offset(offset)
155
+ unless field.sequence?
156
+ @__offset = __decode_seek_offset(field.offset, field.relative_offset?)
155
157
  throw :ignored, nil if @__offset == false
156
- @__condition = __decode_condition(condition)
158
+ @__condition = __decode_condition(field.condition)
157
159
  throw :ignored, nil unless @__condition
158
- @__type = __decode_type(type)
160
+ @__type = __decode_type(field.type)
161
+ @__length = __decode_length(field.length)
159
162
  end
160
- @__count = __decode_count(count)
163
+ @__count = __decode_count(field.count)
161
164
  end
162
165
 
163
- def __decode_dynamic_conditions(type, offset, sequence, condition)
164
- return true unless sequence
166
+ def __decode_dynamic_conditions(field)
167
+ return true unless field.sequence?
165
168
  @__offset = nil
166
169
  @__condition = nil
167
170
  @__type = nil
168
- @__offset = __decode_seek_offset(offset)
171
+ @__length = nil
172
+ @__offset = __decode_seek_offset(field.offset, field.relative_offset?)
169
173
  return false if @__offset == false
170
- @__condition = __decode_condition(condition)
174
+ @__condition = __decode_condition(field.condition)
171
175
  return false unless @__condition
172
- @__type = __decode_type(type)
176
+ @__type = __decode_type(field.type)
177
+ @__length = __decode_length(field.length)
173
178
  return true
174
179
  end
175
180
 
176
181
  def __restore_context
177
182
  @__iterator = nil
178
183
  @__type = nil
184
+ @__length = nil
179
185
  @__count = nil
180
186
  @__offset = nil
181
187
  @__condition = nil
182
188
  end
183
189
 
184
- def __convert_field(field, type, count, offset, sequence, condition)
185
- __decode_static_conditions(type, count, offset, sequence, condition)
190
+ def __convert_field(field)
191
+ __decode_static_conditions(field)
186
192
  vs = @__count.times.collect do |it|
187
193
  @__iterator = it
188
- if __decode_dynamic_conditions(type, offset, sequence, condition)
189
- @__type::convert(@__input, @__output, @__input_big, @__output_big, self, it)
194
+ if __decode_dynamic_conditions(field)
195
+ @__type::convert(@__input, @__output, @__input_big, @__output_big, self, it, @__length)
190
196
  else
191
197
  nil
192
198
  end
193
199
  end
194
200
  __restore_context
195
- vs = vs.first unless count
201
+ vs = vs.first unless field.count
196
202
  vs
197
203
  end
198
204
 
199
- def __load_field(field, type, count, offset, sequence, condition)
200
- __decode_static_conditions(type, count, offset, sequence, condition)
205
+ def __load_field(field)
206
+ __decode_static_conditions(field)
201
207
  vs = @__count.times.collect do |it|
202
208
  @__iterator = it
203
- if __decode_dynamic_conditions(type, offset, sequence, condition)
204
- @__type::load(@__input, @__input_big, self, it)
209
+ if __decode_dynamic_conditions(field)
210
+ @__type::load(@__input, @__input_big, self, it, @__length)
205
211
  else
206
212
  nil
207
213
  end
208
214
  end
209
215
  __restore_context
210
- vs = vs.first unless count
216
+ vs = vs.first unless field.count
211
217
  vs
212
218
  end
213
219
 
214
- def __dump_field(vs, field, type, count, offset, sequence, condition)
215
- __decode_static_conditions(type, count, offset, sequence, condition)
216
- vs = [vs] unless count
220
+ def __dump_field(vs, field)
221
+ __decode_static_conditions(field)
222
+ vs = [vs] unless field.count
217
223
  vs.each_with_index do |v, it|
218
224
  @__iterator = it
219
- if __decode_dynamic_conditions(type, offset, sequence, condition)
220
- @__type::dump(v, @__output, @__output_big, self, it)
225
+ if __decode_dynamic_conditions(field)
226
+ @__type::dump(v, @__output, @__output_big, self, it, @__length)
221
227
  end
222
228
  end
223
229
  __restore_context
224
230
  end
225
231
 
226
- def __shape_field(vs, previous_offset, kind, field, type, count, offset, sequence, condition)
227
- __decode_static_conditions(type, count, offset, sequence, condition)
228
- vs = [vs] unless count
232
+ def __shape_field(vs, previous_offset, kind, field)
233
+ __decode_static_conditions(field)
234
+ vs = [vs] unless field.count
229
235
  vs = vs.each_with_index.collect do |v, it|
230
236
  @__iterator = it
231
- if __decode_dynamic_conditions(type, offset, sequence, condition)
232
- sh = @__type::shape(v, @__cur_position, self, it, kind)
237
+ if __decode_dynamic_conditions(field)
238
+ sh = @__type::shape(v, @__cur_position, self, it, kind, @__length)
233
239
  @__cur_position = sh.last + 1 if sh.last && sh.last >= 0
234
240
  sh
235
241
  end
236
242
  end
237
243
  __restore_context
238
- vs = vs.first unless count
244
+ vs = vs.first unless field.count
239
245
  vs
240
246
  end
241
247
 
@@ -246,15 +252,15 @@ module LibBin
246
252
  def __shape(previous_offset = 0, parent = nil, index = nil, kind = DataShape)
247
253
  __set_size_type(previous_offset, parent, index)
248
254
  members = {}
249
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
255
+ self.class.instance_variable_get(:@fields).each { |field|
250
256
  begin
251
- vs = send(name)
257
+ vs = send(field.name)
252
258
  member = catch(:ignored) do
253
- __shape_field(vs, previous_offset, kind, name, type, *args)
259
+ __shape_field(vs, previous_offset, kind, field)
254
260
  end
255
- members[name] = member
261
+ members[field.name] = member
256
262
  rescue
257
- STDERR.puts "#{self.class}: #{name}(#{type})"
263
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
258
264
  raise
259
265
  end
260
266
  }
@@ -264,14 +270,14 @@ module LibBin
264
270
  end
265
271
 
266
272
  def __convert_fields
267
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
273
+ self.class.instance_variable_get(:@fields).each { |field|
268
274
  begin
269
275
  vs = catch(:ignored) do
270
- __convert_field(name, type, *args)
276
+ __convert_field(field)
271
277
  end
272
- send("#{name}=", vs)
278
+ send("#{field.name}=", vs)
273
279
  rescue
274
- STDERR.puts "#{self.class}: #{name}(#{type})"
280
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
275
281
  raise
276
282
  end
277
283
  }
@@ -279,14 +285,14 @@ module LibBin
279
285
  end
280
286
 
281
287
  def __load_fields
282
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
288
+ self.class.instance_variable_get(:@fields).each { |field|
283
289
  begin
284
290
  vs = catch(:ignored) do
285
- __load_field(name, type, *args)
291
+ __load_field(field)
286
292
  end
287
- send("#{name}=", vs)
293
+ send("#{field.name}=", vs)
288
294
  rescue
289
- STDERR.puts "#{self.class}: #{name}(#{type})"
295
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
290
296
  raise
291
297
  end
292
298
  }
@@ -294,14 +300,14 @@ module LibBin
294
300
  end
295
301
 
296
302
  def __dump_fields
297
- self.class.instance_variable_get(:@fields).each { |name, type, *args|
303
+ self.class.instance_variable_get(:@fields).each { |field|
298
304
  begin
299
- vs = send(name)
305
+ vs = send(field.name)
300
306
  catch(:ignored) do
301
- __dump_field(vs, name, type, *args)
307
+ __dump_field(vs, field)
302
308
  end
303
309
  rescue
304
- STDERR.puts "#{self.class}: #{name}(#{type})"
310
+ STDERR.puts "#{self.class}: #{field.name}(#{field.type})"
305
311
  raise
306
312
  end
307
313
  }
@@ -329,28 +335,57 @@ module LibBin
329
335
  self
330
336
  end
331
337
 
332
- def self.convert(input, output, input_big = LibBin::default_big?, output_big = !LibBin::default_big?, parent = nil, index = nil)
333
- h = self::new
334
- h.__convert(input, output, input_big, output_big, parent, index)
335
- h
338
+ def self.convert(input, output, input_big = LibBin::default_big?, output_big = !LibBin::default_big?, parent = nil, index = nil, length = nil)
339
+ if length
340
+ length.times.collect {
341
+ h = self::new
342
+ h.__load(input, input_big, parent, index)
343
+ }
344
+ else
345
+ h = self::new
346
+ h.__convert(input, output, input_big, output_big, parent, index)
347
+ end
336
348
  end
337
349
 
338
- def self.load(input, input_big = LibBin::default_big?, parent = nil, index = nil)
339
- h = self::new
340
- h.__load(input, input_big, parent, index)
341
- h
350
+ def self.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil)
351
+ if length
352
+ length.times.collect {
353
+ h = self::new
354
+ h.__load(input, input_big, parent, index)
355
+ }
356
+ else
357
+ h = self::new
358
+ h.__load(input, input_big, parent, index)
359
+ end
342
360
  end
343
361
 
344
- def self.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil)
345
- value.__dump(output, output_big, parent, index)
362
+ def self.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil)
363
+ if length
364
+ length.times.collect { |i|
365
+ value[i].__dump(output, output_big, parent, index)
366
+ }
367
+ value
368
+ else
369
+ value.__dump(output, output_big, parent, index)
370
+ end
346
371
  end
347
372
 
348
- def self.size(value, previous_offset = 0, parent = nil, index = nil)
349
- value.__shape(previous_offset, parent, index).size
373
+ def self.size(value, previous_offset = 0, parent = nil, index = nil, length = nil)
374
+ if length
375
+ shape(value, previous_offset, parent, index, length).size
376
+ else
377
+ value.__shape(previous_offset, parent, index).size
378
+ end
350
379
  end
351
380
 
352
- def self.shape(value, previous_offset = 0, parent = nil, index = nil, kind = DataShape)
353
- value.__shape(previous_offset, parent, index, kind = DataShape)
381
+ def self.shape(value, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil)
382
+ if length
383
+ kind::new(length.times.collect { |i|
384
+ value[i].__shape(previous_offset, parent, index, kind)
385
+ })
386
+ else
387
+ value.__shape(previous_offset, parent, index, kind)
388
+ end
354
389
  end
355
390
 
356
391
  end
File without changes
@@ -70,14 +70,52 @@ module LibBin
70
70
 
71
71
  end
72
72
 
73
+ class Field
74
+ attr_reader :name,
75
+ :type,
76
+ :length,
77
+ :count,
78
+ :offset,
79
+ :sequence,
80
+ :condition
81
+
82
+ def sequence?
83
+ @sequence
84
+ end
85
+
86
+ def relative_offset?
87
+ @relative_offset
88
+ end
89
+
90
+ def initialize(name, type, length, count, offset, sequence, condition, relative_offset)
91
+ @name = name
92
+ @type = type
93
+ @length = length
94
+ @count = count
95
+ @offset = offset
96
+ @sequence = sequence
97
+ @condition = condition
98
+ @relative_offset = relative_offset
99
+ end
100
+
101
+ end
102
+
73
103
  class DataConverter
74
104
 
75
- rl = lambda { |type, str|
76
- str.unpack(type.to_s).first
105
+ rl = lambda { |type, str, number = nil|
106
+ if number
107
+ str.unpack(type.to_s+number.to_s)
108
+ else
109
+ str.unpack(type.to_s).first
110
+ end
77
111
  }
78
112
 
79
- sl = lambda { |type, value|
80
- [value].pack(type.to_s)
113
+ sl = lambda { |type, value, number = nil|
114
+ if number
115
+ value.pack(type.to_s+number.to_s)
116
+ else
117
+ [value].pack(type.to_s)
118
+ end
81
119
  }
82
120
 
83
121
  l = lambda { |type|
@@ -161,6 +199,7 @@ module LibBin
161
199
  :D => 8,
162
200
  :E => 8,
163
201
  :G => 8,
202
+ :a => 1,
164
203
  :"a*" => -1,
165
204
  :half => 2,
166
205
  :half_le => 2,
@@ -186,6 +225,50 @@ module LibBin
186
225
  }
187
226
  }
188
227
 
228
+ rhl = lambda { |type, str, number = nil|
229
+ if number
230
+ number.times.collect { |i| LibBin::half_from_string(str[i*2,2], type) }
231
+ else
232
+ LibBin::half_from_string(str, type)
233
+ end
234
+ }
235
+
236
+ shl = lambda { |type, value, number = nil|
237
+ if number
238
+ str = ""
239
+ number.times { |i| str << LibBin::half_to_string(value[i], type) }
240
+ str
241
+ else
242
+ LibBin::half_to_string(value, type)
243
+ end
244
+ }
245
+
246
+ hl = lambda { |type|
247
+ [rhl.curry[type], shl.curry[type]]
248
+ }
249
+
250
+ rpghl = lambda { |type, str, number = nil|
251
+ if number
252
+ number.times.collect { |i| LibBin::pghalf_from_string(str[i*2,2], type) }
253
+ else
254
+ LibBin::pghalf_from_string(str, type)
255
+ end
256
+ }
257
+
258
+ spghl = lambda { |type, value, number = nil|
259
+ if number
260
+ str = ""
261
+ number.times { |i| str << LibBin::pghalf_to_string(value[i], type) }
262
+ str
263
+ else
264
+ LibBin::pghalf_to_string(value, type)
265
+ end
266
+ }
267
+
268
+ pghl = lambda { |type|
269
+ [rpghl.curry[type], spghl.curry[type]]
270
+ }
271
+
189
272
  DATA_ENDIAN[true].merge!( {
190
273
  :c => l["c"],
191
274
  :C => l["C"],
@@ -217,19 +300,12 @@ module LibBin
217
300
  :D => l["G"],
218
301
  :E => l["E"],
219
302
  :G => l["G"],
220
- :"a*" => l["a*"],
221
- :half => [ lambda { |str| Flt::IEEE_binary16_BE::from_bytes(str).to(Float) },
222
- lambda { |v| Flt::IEEE_binary16_BE::new(v).to_bytes } ],
223
- :half_le => [ lambda { |str| Flt::IEEE_binary16_LE::from_bytes(str).to(Float) },
224
- lambda { |v| Flt::IEEE_binary16_LE::new(v).to_bytes } ],
225
- :half_be => [ lambda { |str| Flt::IEEE_binary16_BE::from_bytes(str).to(Float) },
226
- lambda { |v| Flt::IEEE_binary16_BE::new(v).to_bytes } ],
227
- :pghalf => [ lambda { |str| Flt::IEEE_binary16_pg_BE::from_bytes(str).to(Float) },
228
- lambda { |v| Flt::IEEE_binary16_pg_BE::new(v).to_bytes } ],
229
- :pghalf_le => [ lambda { |str| Flt::IEEE_binary16_pg_LE::from_bytes(str).to(Float) },
230
- lambda { |v| Flt::IEEE_binary16_pg_LE::new(v).to_bytes } ],
231
- :pghalf_be => [ lambda { |str| Flt::IEEE_binary16_pg_BE::from_bytes(str).to(Float) },
232
- lambda { |v| Flt::IEEE_binary16_pg_BE::new(v).to_bytes } ]
303
+ :half => hl["S>"],
304
+ :half_le => hl["S<"],
305
+ :half_be => hl["S>"],
306
+ :pghalf => pghl["S>"],
307
+ :pghalf_le => pghl["S<"],
308
+ :pghalf_be => pghl["S>"]
233
309
  } )
234
310
  DATA_ENDIAN[false].merge!( {
235
311
  :c => l["c"],
@@ -262,19 +338,12 @@ module LibBin
262
338
  :D => l["E"],
263
339
  :E => l["E"],
264
340
  :G => l["G"],
265
- :"a*" => l["a*"],
266
- :half => [ lambda { |str| Flt::IEEE_binary16::from_bytes(str).to(Float) },
267
- lambda { |v| Flt::IEEE_binary16::new(v).to_bytes } ],
268
- :half_le => [ lambda { |str| Flt::IEEE_binary16_LE::from_bytes(str).to(Float) },
269
- lambda { |v| Flt::IEEE_binary16_LE::new(v).to_bytes } ],
270
- :half_be => [ lambda { |str| Flt::IEEE_binary16_BE::from_bytes(str).to(Float) },
271
- lambda { |v| Flt::IEEE_binary16_BE::new(v).to_bytes } ],
272
- :pghalf => [ lambda { |str| Flt::IEEE_binary16_pg::from_bytes(str).to(Float) },
273
- lambda { |v| Flt::IEEE_binary16_pg::new(v).to_bytes } ],
274
- :pghalf_le => [ lambda { |str| Flt::IEEE_binary16_pg_LE::from_bytes(str).to(Float) },
275
- lambda { |v| Flt::IEEE_binary16_pg_LE::new(v).to_bytes } ],
276
- :pghalf_be => [ lambda { |str| Flt::IEEE_binary16_pg_BE::from_bytes(str).to(Float) },
277
- lambda { |v| Flt::IEEE_binary16_pg_BE::new(v).to_bytes } ]
341
+ :half => hl["S<"],
342
+ :half_le => hl["S<"],
343
+ :half_be => hl["S>"],
344
+ :pghalf => pghl["S<"],
345
+ :pghalf_le => pghl["S<"],
346
+ :pghalf_be => pghl["S>"]
278
347
  } )
279
348
 
280
349
 
@@ -284,31 +353,34 @@ module LibBin
284
353
  @size
285
354
  end
286
355
 
287
- def self.shape(value, previous_offset = 0, _ = nil, _ = nil, kind = DataShape)
288
- kind::new(previous_offset, previous_offset + @size - 1)
356
+ def self.shape(value, previous_offset = 0, _ = nil, _ = nil, kind = DataShape, length = nil)
357
+ length = 1 unless length
358
+ kind::new(previous_offset, previous_offset - 1 + length * @size)
289
359
  end
290
360
 
291
361
  def self.init(symbol)
292
362
  @symbol = symbol
293
363
  @size = DATA_SIZES[symbol]
294
364
  @rl_be, @sl_be = DATA_ENDIAN[true][symbol]
295
- @rl_le, @sl_be = DATA_ENDIAN[false][symbol]
365
+ @rl_le, @sl_le = DATA_ENDIAN[false][symbol]
296
366
  end
297
367
 
298
- def self.load(input, input_big = LibBin::default_big?, _ = nil, _ = nil)
299
- str = input.read(@size)
300
- input_big ? @rl_be[str] : @rl_le[str]
368
+ def self.load(input, input_big = LibBin::default_big?, _ = nil, _ = nil, length = nil)
369
+ l = (length ? length : 1)
370
+ str = input.read(@size*l)
371
+ input_big ? @rl_be[str, length] : @rl_le[str, length]
301
372
  end
302
373
 
303
- def self.dump(value, output, output_big = LibBin::default_big?, _ = nil, _ = nil)
304
- str = (output_big ? @sl_be[value] : @sl_le[value])
374
+ def self.dump(value, output, output_big = LibBin::default_big?, _ = nil, _ = nil, length = nil)
375
+ str = (output_big ? @sl_be[value, length] : @sl_le[value, length])
305
376
  output.write(str)
306
377
  end
307
378
 
308
- def self.convert(input, output, input_big = LibBin::default_big?, output_big = !LibBin::default_big, _ = nil, _ = nil)
309
- str = input.read(@size)
310
- value = (input_big ? @rl_be[str] : @rl_le[str])
311
- str = (output_big ? @sl_be[value] : @sl_le[value])
379
+ def self.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big, _ = nil, _ = nil, length = nil)
380
+ l = (length ? length : 1)
381
+ str = input.read(@size*l)
382
+ value = (input_big ? @rl_be[str, length] : @rl_le[str, length])
383
+ str = (output_big ? @sl_be[value, length] : @sl_le[value, length])
312
384
  output.write(str)
313
385
  value
314
386
  end
@@ -317,40 +389,44 @@ module LibBin
317
389
 
318
390
  class Str < Scalar
319
391
 
320
- def self.load(input, input_big = LibBin::default_big?, _ = nil, _ = nil)
321
- str = (@size < 0 ? input.readline("\x00") : input.read(@size))
322
- input_big ? @rl_be[str] : @rl_le[str]
392
+ def self.size(value, previous_offset = 0, parent = nil, index = nil, length = nil)
393
+ length ? length : value.size
323
394
  end
324
395
 
325
- def self.convert(input, output, input_big = LibBin::default_big?, output_big = !LibBin::default_big, _ = nil, _ = nil)
326
- str = (@size < 0 ? input.readline("\x00") : input.read(@size))
327
- value = (input_big ? @rl_be[str] : @rl_le[str])
328
- str = (output_big ? @sl_be[value] : @sl_le[value])
396
+ def self.load(input, input_big = LibBin::default_big?, _ = nil, _ = nil, length = nil)
397
+ str = (length ? input.read(length) : input.readline("\x00"))
398
+ end
399
+
400
+ def self.convert(input, output, input_big = LibBin::default_big?, output_big = !LibBin::default_big, _ = nil, _ = nil, length = nil)
401
+ str = (length ? input.read(length) : input.readline("\x00"))
329
402
  output.write(str)
330
- value
403
+ str
331
404
  end
332
405
 
333
- def self.shape(value, previous_offset = 0, _ = nil, _ = nil, kind = DataShape)
334
- if @size < 0
335
- kind::new(previous_offset, previous_offset + value.size - 1)
406
+ def self.shape(value, previous_offset = 0, _ = nil, _ = nil, kind = DataShape, length = nil)
407
+ if length
408
+ kind::new(previous_offset, previous_offset + length - 1)
336
409
  else
337
- kind::new(previous_offset, previous_offset + @size - 1)
410
+ kind::new(previous_offset, previous_offset + value.size - 1)
338
411
  end
339
412
  end
340
413
 
414
+ def self.dump(value, output, output_big = LibBin::default_big?, _ = nil, _ = nil, length = nil)
415
+ output.write(value)
416
+ end
341
417
  end
342
418
 
343
- def self.register_field(field, type, count: nil, offset: nil, sequence: false, condition: nil)
419
+ def self.register_field(field, type, length: nil, count: nil, offset: nil, sequence: false, condition: nil, relative_offset: false)
344
420
  if type.kind_of?(Symbol)
345
421
  if type[0] == 'a'
346
- c = Class::new(Str) do init(sym) end
347
- @fields.push([field, c, count, offset, sequence, condition])
422
+ real_type = Class::new(Str) do init(sym) end
348
423
  else
349
- @fields.push([field, const_get(SCALAR_TYPES[type][0]), count, offset, sequence, condition])
424
+ real_type = const_get(SCALAR_TYPES[type][0])
350
425
  end
351
426
  else
352
- @fields.push([field, type, count, offset, sequence, condition])
427
+ real_type = type
353
428
  end
429
+ @fields.push(Field::new(field, real_type, length, count, offset, sequence, condition, relative_offset))
354
430
  attr_accessor field
355
431
  end
356
432
 
@@ -361,8 +437,8 @@ module LibBin
361
437
  init(#{symbol.inspect})
362
438
  end
363
439
 
364
- def self.#{name}(field, count: nil, offset: nil, sequence: false, condition: nil)
365
- @fields.push([field, #{klassname}, count, offset, sequence, condition])
440
+ def self.#{name}(field, length: nil, count: nil, offset: nil, sequence: false, condition: nil, relative_offset: false)
441
+ @fields.push(Field::new(field, #{klassname}, length, count, offset, sequence, condition, relative_offset))
366
442
  attr_accessor field
367
443
  end
368
444
  EOF
@@ -401,16 +477,15 @@ EOF
401
477
  create_scalar_type(:pghalf_le)
402
478
  create_scalar_type(:pghalf_be)
403
479
 
404
- def self.string( field, length = nil, count: nil, offset: nil, sequence: false, condition: nil)
405
- sym = (length ? :"a#{length}" : :"a*")
480
+ def self.string( field, length = nil, count: nil, offset: nil, sequence: false, condition: nil, relative_offset: false)
481
+ sym = (length ? :"a" : :"a*")
406
482
  c = Class::new(Str) do
407
483
  init(sym)
408
484
  end
409
- @fields.push([field, c, count, offset, sequence, condition])
485
+ @fields.push(Field::new(field, c, length, count, offset, sequence, condition, relative_offset))
410
486
  attr_accessor field
411
487
  end
412
488
 
413
-
414
489
  end
415
490
 
416
491
  end