Class: BinData::Record
- Includes:
- DSLMixin
- Defined in:
- lib/bindata/record.rb
Overview
A Record is a declarative wrapper around Struct.
require 'bindata'
class SomeDataType < BinData::Record
hide 'a'
int32le :a
int16le :b
struct :s do
int8 :x
int8 :y
int8 :z
end
end
obj = SomeDataType.new
obj.field_names =># ["b", "s"]
obj.s.field_names =># ["x", "y", "z"]
Parameters
Parameters may be provided at initialisation to control the behaviour of an object. These params are:
:fields
-
An array specifying the fields for this struct. Each element of the array is of the form [type, name, params]. Type is a symbol representing a registered type. Name is the name of this field. Params is an optional hash of parameters to pass to this field when instantiating it.
:hide
-
A list of the names of fields that are to be hidden from the outside world. Hidden fields don’t appear in #snapshot or #field_names but are still accessible by name.
:endian
-
Either :little or :big. This specifies the default endian of any numerics in this struct, or in any nested data objects.
Direct Known Subclasses
Constant Summary
Constants included from DSLMixin
Constants inherited from Struct
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Methods included from DSLMixin
Methods inherited from Struct
#clear, #clear?, #debug_name_of, #field_names, #initialize, #method_missing, #offset_of, #respond_to?
Methods inherited from Base
#==, #assign, #clear, #clear?, #debug_name, #debug_name_of, #eval_parameter, #get_parameter, #has_parameter?, #initialize, #inspect, #num_bytes, #offset, #offset_of, #pretty_print, read, #read, register, register_class, register_self, register_subclasses, #rel_offset, #snapshot, #to_binary_s, #to_s, #write
Methods included from AcceptedParametersMixin
Constructor Details
This class inherits a constructor from BinData::Struct
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BinData::Struct
Class Method Details
.sanitize_parameters!(params, sanitizer) ⇒ Object
:nodoc:
52 53 54 55 56 57 58 |
# File 'lib/bindata/record.rb', line 52 def sanitize_parameters!(params, sanitizer) #:nodoc: params[:fields] = fields params[:endian] = endian unless endian.nil? params[:hide] = hide unless hide.empty? super(params, sanitizer) end |