Class: String

Inherits:
Object show all
Defined in:
lib/rumai/ixp/message.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_9p(stream) ⇒ Object

Creates a new instance of this class from the given 9P2000 byte stream and returns the instance.



694
695
696
# File 'lib/rumai/ixp/message.rb', line 694

def self.from_9p stream
  stream.read stream.read_9p(2)
end

Instance Method Details

#byteslice(*args) ⇒ Object

Does the same thing as String#slice but operates on bytes instead of characters.



703
704
705
# File 'lib/rumai/ixp/message.rb', line 703

def byteslice(*args)
  unpack('C*').slice(*args).pack('C*')
end

#to_9pObject

Transforms this object into a string of 9P2000 bytes.



685
686
687
688
# File 'lib/rumai/ixp/message.rb', line 685

def to_9p
  count = [bytesize, Rumai::IXP::BYTE2_MASK].min
  count.to_9p(2) << byteslice(0, count)
end