Class: Mfp::Proto::Reader
- Inherits:
-
Object
- Object
- Mfp::Proto::Reader
- Defined in:
- lib/mfp/proto/reader.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io) ⇒ Reader
constructor
A new instance of Reader.
- #read_byte ⇒ Object
- #read_n(n) ⇒ Object
- #read_u16 ⇒ Object
- #read_u16_string ⇒ Object
- #read_u32 ⇒ Object
- #read_u64 ⇒ Object
Constructor Details
#initialize(io) ⇒ Reader
Returns a new instance of Reader.
8 9 10 |
# File 'lib/mfp/proto/reader.rb', line 8 def initialize(io) @io = io end |
Class Method Details
.from_bytes(value) ⇒ Object
6 |
# File 'lib/mfp/proto/reader.rb', line 6 def self.from_bytes(value) = new(StringIO.new(value)) |
Instance Method Details
#read_byte ⇒ Object
16 |
# File 'lib/mfp/proto/reader.rb', line 16 def read_byte = @io.read(1).unpack1("C") |
#read_n(n) ⇒ Object
12 |
# File 'lib/mfp/proto/reader.rb', line 12 def read_n(n) = @io.read(n) |
#read_u16 ⇒ Object
13 |
# File 'lib/mfp/proto/reader.rb', line 13 def read_u16 = @io.read(2).unpack1("S>") |
#read_u16_string ⇒ Object
18 19 20 21 22 23 |
# File 'lib/mfp/proto/reader.rb', line 18 def read_u16_string size = read_u16 return "" if size.zero? read_n(size).encode("utf-8") end |
#read_u32 ⇒ Object
14 |
# File 'lib/mfp/proto/reader.rb', line 14 def read_u32 = @io.read(4).unpack1("L>") |
#read_u64 ⇒ Object
15 |
# File 'lib/mfp/proto/reader.rb', line 15 def read_u64 = @io.read(8).unpack1("Q>") |