Class: LibBin::Structure::Enum Abstract
- Inherits:
-
Object
- Object
- LibBin::Structure::Enum
- Defined in:
- lib/libbin/data_types.rb
Overview
A parent class representing an enumeration that is loading integers as symbols.
Useer should inherit this base class.
Scalars collapse
-
.map ⇒ Object
get the enum map.
-
.type ⇒ Object
Get the underlying type.
Scalars collapse
-
.align ⇒ Object
Returns the underlying type
align
property. -
.always_align ⇒ Object
Returns the underlying type
always_align
property. -
.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big,, parent = nil, index = nil, length = nil) ⇒ Symbol, ...
Convert a field of class Enum by loading it from
input
and dumping it tooutput
. -
.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ nil
Dump a field of class Enum to
output
. -
.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ Symbol, ...
Load a field of type Enum from
input
, and return it. -
.shape(value = nil, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil) ⇒ Object
Forwards the call to the underlying type.
-
.size(value = nil, previous_offset = 0, parent = nil, index = nil, length = nil) ⇒ Object
Forwards the call to the underlying type.
-
.type_size ⇒ Object
Get the underlying type size in bits.
-
.type_size=(sz) ⇒ Object
(also: set_type_size)
Specify the size of the underlying type.
Class Attribute Details
.map ⇒ Object
get the enum map
339 340 341 |
# File 'lib/libbin/data_types.rb', line 339 def map @map end |
.type ⇒ Object
Get the underlying type
341 342 343 |
# File 'lib/libbin/data_types.rb', line 341 def type @type end |
Class Method Details
.align ⇒ Object
Returns the underlying type align
property
377 378 379 |
# File 'lib/libbin/data_types.rb', line 377 def self.align @type.align end |
.always_align ⇒ Object
Returns the underlying type always_align
property
372 373 374 |
# File 'lib/libbin/data_types.rb', line 372 def self.always_align @type.always_align end |
.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big,, parent = nil, index = nil, length = nil) ⇒ Symbol, ...
Convert a field of class LibBin::Structure::Enum by loading it from input
and dumping it to output
. Returns the loaded field.
429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/libbin/data_types.rb', line 429 def self.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big, parent = nil, index = nil, length = nil) v = @type.convert(input, output, input_big, output_big, parent, index, length) if length v.collect { |val| n = @map_to[val] n = val unless n n } else n = @map_to[v] n = v unless n n end end |
.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ nil
Dump a field of class LibBin::Structure::Enum to output
.
455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/libbin/data_types.rb', line 455 def self.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil) if length v = length.times.collect { |i| val = @map_from[value[i]] val = value[i] unless val val } else v = @map_from[value] v = value unless v end @type.dump(v, output, output_big, parent, index, length) end |
.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ Symbol, ...
Load a field of type LibBin::Structure::Enum from input
, and return it.
401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/libbin/data_types.rb', line 401 def self.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil) v = @type.load(input, input_big, parent, index, length) if length v.collect { |val| n = @map_to[val] n = val unless n n } else n = @map_to[v] n = v unless n n end end |
.shape(value = nil, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil) ⇒ Object
Forwards the call to the underlying type
387 388 389 |
# File 'lib/libbin/data_types.rb', line 387 def self.shape(value = nil, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil) @type.shape(value, previous_offset, parent, index, kind, length) end |
.size(value = nil, previous_offset = 0, parent = nil, index = nil, length = nil) ⇒ Object
Forwards the call to the underlying type
382 383 384 |
# File 'lib/libbin/data_types.rb', line 382 def self.size(value = nil, previous_offset = 0, parent = nil, index = nil, length = nil) @type.size(value, previous_offset, parent, index, length) end |
.type_size ⇒ Object
Get the underlying type size in bits
353 354 355 |
# File 'lib/libbin/data_types.rb', line 353 def type_size @type.size end |
.type_size=(sz) ⇒ Object Also known as: set_type_size
Specify the size of the underlying type
344 345 346 347 348 349 |
# File 'lib/libbin/data_types.rb', line 344 def type_size=(sz) t = eval "Int#{sz}" raise "unsupported enum size #{sz}" unless t @type = t return sz end |