Class: BinData::PascalString

Inherits:
BasePrimitive show all
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

Methods included from ClassParametersPlugin

included

Methods inherited from BasePrimitive

#annotated_snapshot

Instance Method Details

#do_num_bytesObject

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_instanceObject



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_defaultObject



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