Class: PacketGen::Types::String
- Inherits:
-
String
- Object
- String
- PacketGen::Types::String
- Defined in:
- lib/packetgen/types/string.rb
Overview
This class is just like regular String. It only adds #read and #sz methods to be compatible with others PacketGen::Types.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ String
constructor
A new instance of String.
-
#read(str) ⇒ String
Self.
Constructor Details
#initialize(options = {}) ⇒ String
Returns a new instance of String.
19 20 21 22 23 |
# File 'lib/packetgen/types/string.rb', line 19 def initialize(={}) super() @length_from = [:length_from] @static_length = [:static_length] end |
Instance Method Details
#read(str) ⇒ String
Returns self.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/packetgen/types/string.rb', line 27 def read(str) s = str.to_s str_end = case @length_from when Types::Int @length_from.to_i when Proc @length_from.call else if @static_length.is_a? Integer @static_length else s.size end end str_end = 0 if str_end < 0 self.replace(s[0, str_end]) self end |