Class: LibBin::DataConverter::Scalar

Inherits:
Object
  • Object
show all
Defined in:
lib/libbin/data_types.rb

Direct Known Subclasses

Str

Class Method Summary collapse

Class Method Details

.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big,, _ = nil, _ = nil) ⇒ Object



308
309
310
311
312
313
314
# File 'lib/libbin/data_types.rb', line 308

def self.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big, _ = nil, _ = nil)
  str = input.read(@size)
  value = (input_big ? @rl_be[str] : @rl_le[str])
  str = (output_big ? @sl_be[value] : @sl_le[value])
  output.write(str)
  value
end

.dump(value, output, output_big = LibBin::default_big?, _ = nil, _ = nil) ⇒ Object



303
304
305
306
# File 'lib/libbin/data_types.rb', line 303

def self.dump(value, output, output_big = LibBin::default_big?, _ = nil, _ = nil)
  str = (output_big ? @sl_be[value] : @sl_le[value])
  output.write(str)
end

.init(symbol) ⇒ Object



291
292
293
294
295
296
# File 'lib/libbin/data_types.rb', line 291

def self.init(symbol)
  @symbol = symbol
  @size = DATA_SIZES[symbol]
  @rl_be, @sl_be = DATA_ENDIAN[true][symbol]
  @rl_le, @sl_le = DATA_ENDIAN[false][symbol]
end

.load(input, input_big = LibBin::default_big?, _ = nil, _ = nil) ⇒ Object



298
299
300
301
# File 'lib/libbin/data_types.rb', line 298

def self.load(input, input_big = LibBin::default_big?, _ = nil, _ = nil)
  str = input.read(@size)
  input_big ? @rl_be[str] : @rl_le[str]
end

.shape(value, previous_offset = 0, _ = nil, _ = nil, kind = DataShape) ⇒ Object



287
288
289
# File 'lib/libbin/data_types.rb', line 287

def self.shape(value, previous_offset = 0, _ = nil, _ = nil, kind = DataShape)
  kind::new(previous_offset, previous_offset + @size - 1)
end

.size(*args) ⇒ Object



283
284
285
# File 'lib/libbin/data_types.rb', line 283

def self.size(*args)
  @size
end