Class: AMT::Service::HardwareAsset::Asset
- Inherits:
-
Object
- Object
- AMT::Service::HardwareAsset::Asset
- Defined in:
- lib/amt/service/hardware_asset/asset.rb
Overview
Utility base class which provides methods for easily unpacking the byte stream returned by AMT::Service::HardwareAsset#get_asset_data.
Each asset class is derived from this class.
Direct Known Subclasses
AmtInformationTable, Baseboard, Bios, ComputerSystem, FRU, MediaDevice, MemoryModule, PortableBattery, Processor, VproVerificationTable
Instance Attribute Summary collapse
-
#structure_version ⇒ Object
readonly
The version of the asset structure.
Class Method Summary collapse
-
.set_unpack_data(code, size, repr = nil) ⇒ Object
Set the
code
that is used to unpack the byte stream data. -
.unpack_code ⇒ Object
Return the byte stream unpack code for the specific asset class.
-
.unpack_repr ⇒ Object
Return the byte stream representation data if set.
-
.unpack_size ⇒ Object
Return the predetermined size of the byte stream for the specific asset class.
Instance Method Summary collapse
-
#initialize(stream) ⇒ Asset
constructor
Use the data from the byte stream
stream
to set all needed values.
Constructor Details
#initialize(stream) ⇒ Asset
Use the data from the byte stream stream
to set all needed values.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/amt/service/hardware_asset/asset.rb', line 50 def initialize(stream) if stream.size != self.class.unpack_size raise ArgumentError, "The given byte stream has invalid length (#{stream.size} != #{self.class.unpack_size})" end sv, *rest = *stream.unpack(self.class.unpack_code) @structure_version = as_structure_version(sv) if @structure_version != '1.0' raise ArgumentError, "Only Asset structures with version 1.0 are supported (got #{@structure_version})" end init_data(rest) end |
Instance Attribute Details
#structure_version ⇒ Object (readonly)
The version of the asset structure.
46 47 48 |
# File 'lib/amt/service/hardware_asset/asset.rb', line 46 def structure_version @structure_version end |
Class Method Details
.set_unpack_data(code, size, repr = nil) ⇒ Object
Set the code
that is used to unpack the byte stream data. size
is the expected (and fixed) size of the byte stream. repr
is an array of fields (or arrays when you also want to specify the field type and optionally field data) and should be matched to the order of the unpacked data.
If repr
is specified, an accessor method for each field is created.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/amt/service/hardware_asset/asset.rb', line 19 def self.set_unpack_data(code, size, repr = nil) @code = code @size = size @repr = repr if !repr.nil? repr.each do |field, repr, repr_data| define_method(repr == :boolean ? field.to_s + "?" : field) { instance_variable_get("@#{field}".intern) } end end end |
.unpack_code ⇒ Object
Return the byte stream unpack code for the specific asset class.
31 32 33 |
# File 'lib/amt/service/hardware_asset/asset.rb', line 31 def self.unpack_code @code end |
.unpack_repr ⇒ Object
Return the byte stream representation data if set.
41 42 43 |
# File 'lib/amt/service/hardware_asset/asset.rb', line 41 def self.unpack_repr @repr end |
.unpack_size ⇒ Object
Return the predetermined size of the byte stream for the specific asset class.
36 37 38 |
# File 'lib/amt/service/hardware_asset/asset.rb', line 36 def self.unpack_size @size end |