Class: Mfp::Proto::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/mfp/proto/reader.rb

Class Method Summary collapse

Instance Method Summary collapse

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_byteObject



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_u16Object



13
# File 'lib/mfp/proto/reader.rb', line 13

def read_u16 = @io.read(2).unpack1("S>")

#read_u16_stringObject



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_u32Object



14
# File 'lib/mfp/proto/reader.rb', line 14

def read_u32 = @io.read(4).unpack1("L>")

#read_u64Object



15
# File 'lib/mfp/proto/reader.rb', line 15

def read_u64 = @io.read(8).unpack1("Q>")