Class: Flux::Loader
- Inherits:
-
Object
- Object
- Flux::Loader
- Defined in:
- lib/superinstance/flux-runtime/loader.rb
Overview
Binary loader for FLUX bytecode files
Constant Summary collapse
- FLUX_MAGIC =
'FLUX'.b
Instance Method Summary collapse
-
#has_header?(path) ⇒ Boolean
Check if file has FLUX header.
-
#load_file(path) ⇒ Object
Load a FLUX bytecode file Returns raw bytecode, stripping the FLUX header if present.
-
#parse_header(path) ⇒ Object
Parse header information.
Instance Method Details
#has_header?(path) ⇒ Boolean
Check if file has FLUX header
21 22 23 24 |
# File 'lib/superinstance/flux-runtime/loader.rb', line 21 def has_header?(path) data = File.binread(path, 4) data == FLUX_MAGIC end |
#load_file(path) ⇒ Object
Load a FLUX bytecode file Returns raw bytecode, stripping the FLUX header if present
10 11 12 13 14 15 16 17 18 |
# File 'lib/superinstance/flux-runtime/loader.rb', line 10 def load_file(path) data = File.binread(path) if data.start_with?(FLUX_MAGIC) strip_header(data) else data end end |
#parse_header(path) ⇒ Object
Parse header information
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/superinstance/flux-runtime/loader.rb', line 27 def parse_header(path) data = File.binread(path) unless data.start_with?(FLUX_MAGIC) return nil end { magic: data[0..3], version_major: data.getbyte(4) | (data.getbyte(5) << 8), version_minor: data.getbyte(6) | (data.getbyte(7) << 8), flags: data.getbyte(8) | (data.getbyte(9) << 8), entry_point: data.getbyte(10) | (data.getbyte(11) << 8) | (data.getbyte(12) << 16) | (data.getbyte(13) << 24), reserved: data[14..17] } end |