Class: BinData::PascalString
- Inherits:
-
BasePrimitive
- Object
- BasePrimitive
- BinData::PascalString
- Includes:
- ClassParametersPlugin
- Defined in:
- lib/binproxy/bd_util.rb
Overview
Like the Pascal String class shown in the docs, but with a variable type of length specifier.
Instance Method Summary collapse
-
#do_num_bytes ⇒ Object
again, override for proper bit handling.
-
#do_write(io) ⇒ Object
override this instead of using value_to_binary_string, so that we don’t have to start out byte aligned (the string portion will still be aligned, though).
- #initialize_instance ⇒ Object
- #read_and_return_value(io) ⇒ Object
- #sensible_default ⇒ Object
-
#value_to_binary_string(v) ⇒ Object
only called by do_write and do_num_bytes, which we’ve overridden, so shouldn’t ever be called.
Methods included from ClassParametersPlugin
Methods inherited from BasePrimitive
Instance Method Details
#do_num_bytes ⇒ Object
again, override for proper bit handling
150 151 152 |
# File 'lib/binproxy/bd_util.rb', line 150 def do_num_bytes @len_obj.num_bytes + _value.bytes.count end |
#do_write(io) ⇒ Object
override this instead of using value_to_binary_string, so that we don’t have to start out byte aligned (the string portion will still be aligned, though).
143 144 145 146 147 |
# File 'lib/binproxy/bd_util.rb', line 143 def do_write(io) @len_obj.assign(_value.bytes.count) @len_obj.write(io) io.writebytes(_value) end |
#initialize_instance ⇒ Object
136 137 138 |
# File 'lib/binproxy/bd_util.rb', line 136 def initialize_instance @len_obj = get_parameter(:size_type).instantiate(nil,self) end |
#read_and_return_value(io) ⇒ Object
160 161 162 163 164 |
# File 'lib/binproxy/bd_util.rb', line 160 def read_and_return_value(io) @len_obj.read(io) s = BinData::String.new(read_length: @len_obj).read(io) s.snapshot end |
#sensible_default ⇒ Object
166 167 168 |
# File 'lib/binproxy/bd_util.rb', line 166 def sensible_default "" end |
#value_to_binary_string(v) ⇒ Object
only called by do_write and do_num_bytes, which we’ve overridden, so shouldn’t ever be called.
156 157 158 |
# File 'lib/binproxy/bd_util.rb', line 156 def value_to_binary_string(v) raise RuntimeError.new "this should never be called" end |