Class: BinData::Stringz
- Inherits:
-
BasePrimitive
- Object
- BasePrimitive
- BinData::Stringz
- Defined in:
- lib/bindata/stringz.rb
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.num_bytes #=> 5
obj.to_binary_s #=> "abcd\000"
Parameters
Stringz objects accept all the params that BinData::BasePrimitive does, as well as the following:
:max_length:: The maximum length of the string including the zero byte.
Instance Method Summary collapse
Instance Method Details
#assign(val) ⇒ Object
30 31 32 |
# File 'lib/bindata/stringz.rb', line 30 def assign(val) super(binary_string(val)) end |
#snapshot ⇒ Object
34 35 36 37 38 |
# File 'lib/bindata/stringz.rb', line 34 def snapshot # override to always remove trailing zero bytes result = super trim_and_zero_terminate(result).chomp("\0") end |