Class: PacketGen::Types::String
- Inherits:
-
Object
- Object
- PacketGen::Types::String
- Extended by:
- Forwardable
- Includes:
- Fieldable, LengthFrom
- Defined in:
- lib/packetgen/types/string.rb
Overview
This class mimics regular String, but it is Fieldable.
Constant Summary
Constants included from LengthFrom
Instance Attribute Summary collapse
- #static_length ⇒ Integer readonly
- #string ⇒ ::String readonly
Instance Method Summary collapse
-
#<<(str) ⇒ self
Append the given string to String.
- #format_inspect ⇒ Object
-
#initialize(options = {}) ⇒ String
constructor
A new instance of String.
- #initialize_copy(_orig) ⇒ Object
-
#read(str) ⇒ String
(also: #from_human)
Self.
-
#static_length? ⇒ Boolean
Say if a static length is defined.
-
#sz_to_read ⇒ Integer
Size to read.
Methods included from LengthFrom
#initialize_length_from, #read_with_length_from
Methods included from Fieldable
Constructor Details
#initialize(options = {}) ⇒ String
Returns a new instance of String.
35 36 37 38 39 |
# File 'lib/packetgen/types/string.rb', line 35 def initialize(={}) register_internal_string(+'') initialize_length_from() @static_length = [:static_length] end |
Instance Attribute Details
#static_length ⇒ Integer (readonly)
29 30 31 |
# File 'lib/packetgen/types/string.rb', line 29 def static_length @static_length end |
#string ⇒ ::String (readonly)
27 28 29 |
# File 'lib/packetgen/types/string.rb', line 27 def string @string end |
Instance Method Details
#<<(str) ⇒ self
Append the given string to String
80 81 82 83 |
# File 'lib/packetgen/types/string.rb', line 80 def <<(str) @string << str.to_s self end |
#format_inspect ⇒ Object
73 74 75 |
# File 'lib/packetgen/types/string.rb', line 73 def format_inspect inspect end |
#initialize_copy(_orig) ⇒ Object
41 42 43 |
# File 'lib/packetgen/types/string.rb', line 41 def initialize_copy(_orig) @string = @string.dup end |
#read(str) ⇒ String Also known as: from_human
Returns self.
47 48 49 50 51 |
# File 'lib/packetgen/types/string.rb', line 47 def read(str) s = read_with_length_from(str) register_internal_string s self end |
#static_length? ⇒ Boolean
Say if a static length is defined
69 70 71 |
# File 'lib/packetgen/types/string.rb', line 69 def static_length? !static_length.nil? end |
#sz_to_read ⇒ Integer
Size to read. Computed from static_length or length_from, if defined.
60 61 62 63 64 |
# File 'lib/packetgen/types/string.rb', line 60 def sz_to_read return static_length if static_length? old_sz_to_read end |