Module: IOStruct::ClassMethods
- Defined in:
- lib/iostruct.rb
Instance Method Summary collapse
- #name ⇒ Object
-
#read(src, size = nil) ⇒ Object
src can be IO or String, or anything that responds to :read or :unpack.
- #size ⇒ Object
Instance Method Details
#name ⇒ Object
119 120 121 |
# File 'lib/iostruct.rb', line 119 def name self.to_s end |
#read(src, size = nil) ⇒ Object
src can be IO or String, or anything that responds to :read or :unpack
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/iostruct.rb', line 97 def read src, size = nil pos = nil size ||= const_get 'SIZE' data = if src.respond_to?(:read) pos = src.tell src.read(size).to_s elsif src.respond_to?(:unpack) src else raise "[?] don't know how to read from #{src.inspect}" end # if data.size < size # $stderr.puts "[!] #{self.to_s} want #{size} bytes, got #{data.size}" # end new(*data.unpack(const_get('FORMAT'))).tap{ |x| x.__offset = pos } end |
#size ⇒ Object
115 116 117 |
# File 'lib/iostruct.rb', line 115 def size self::SIZE end |