class PacketGen::Types::String
This class mimics regular String
, but it is {Fieldable}. @author Sylvain Daubert @since 3.1.6 no more a subclass or regular String
Attributes
static_length[R]
@return [Integer]
string[R]
@return [::String]
Public Class Methods
new(options={})
click to toggle source
@param [Hash] options @option options [Types::Int,Proc] :length_from object or proc from which
takes length when reading
@option options [Integer] :static_length set a static length for this string
# File lib/packetgen/types/string.rb, line 34 def initialize(options={}) register_internal_string(+'') initialize_length_from(options) @static_length = options[:static_length] end
Public Instance Methods
<<(str)
click to toggle source
Append the given string to String
@param [#to_s] str @return [self]
# File lib/packetgen/types/string.rb, line 79 def <<(str) @string << str.to_s self end
format_inspect()
click to toggle source
# File lib/packetgen/types/string.rb, line 72 def format_inspect inspect end
initialize_copy(_orig)
click to toggle source
# File lib/packetgen/types/string.rb, line 40 def initialize_copy(_orig) @string = @string.dup end
read(str)
click to toggle source
@param [::String] str @return [String] self
# File lib/packetgen/types/string.rb, line 46 def read(str) s = read_with_length_from(str) register_internal_string s self end
Also aliased as: from_human
static_length?()
click to toggle source
Say if a static length is defined @return [Boolean] @since 3.1.6
# File lib/packetgen/types/string.rb, line 68 def static_length? !static_length.nil? end
sz_to_read()
click to toggle source
Size to read. Computed from static_length
or length_from, if defined. @return [Integer] @since 3.1.6
# File lib/packetgen/types/string.rb, line 59 def sz_to_read return static_length if static_length? old_sz_to_read end
Also aliased as: old_sz_to_read
Private Instance Methods
register_internal_string(str)
click to toggle source
# File lib/packetgen/types/string.rb, line 90 def register_internal_string(str) @string = str PacketGen.force_binary(@string) end