Class: BinData::Stringz
Overview
A BinData::Stringz object is a container for a zero (“0”) terminated string.
For convenience, the zero terminator is not necessary when setting the value. Likewise, the returned value will not be zero terminated.
require 'bindata'
data = "abcd\x00efgh"
obj = BinData::Stringz.new
obj.read(data)
obj.snapshot #=> "abcd"
obj.value #=> "abcd"
obj.num_bytes #=> 5
obj.to_s #=> "abcd\000"
Parameters
Stringz objects accept all the params that BinData::Single does, as well as the following:
:max_length
-
The maximum length of the string including the zero byte.
Instance Method Summary collapse
-
#value ⇒ Object
Overrides value to return the value of this data excluding the trailing zero byte.
Methods inherited from Single
#_do_read, #_num_bytes, #_write, all_possible_field_names, #clear, #clear?, #done_read, #field_names, #initialize, #single_value?, #snapshot, #value=
Methods inherited from Base
accepted_parameters, #clear, default_parameters, #do_read, #done_read, #field_names, #initialize, #inspect, lookup, mandatory_parameters, mutually_exclusive_parameters, #num_bytes, optional_parameters, #read, read, register, sanitize_parameters, #single_value?, #snapshot, #to_s, #write
Constructor Details
This class inherits a constructor from BinData::Single
Instance Method Details
#value ⇒ Object
Overrides value to return the value of this data excluding the trailing zero byte.
38 39 40 41 |
# File 'lib/bindata/stringz.rb', line 38 def value v = super val_to_str(v).chomp("\0") end |