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"
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.
# File lib/bindata/stringz.rb, line 31 def assign(val) super(binary_string(val)) end
# File lib/bindata/stringz.rb, line 35 def snapshot # override to always remove trailing zero bytes result = super trim_and_zero_terminate(result).chomp("\00"") end