Class: Takumi::Packet::String

Inherits:
Object
  • Object
show all
Defined in:
lib/takumi/packet/string.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ String

Returns a new instance of String.



11
12
13
# File 'lib/takumi/packet/string.rb', line 11

def initialize(str)
  @str = str
end

Class Method Details

.decode(source) ⇒ Object



5
6
7
8
# File 'lib/takumi/packet/string.rb', line 5

def decode(source)
  size, read = ::Takumi::Packet::Varint.decode(source)
  return source[read, size], (size + read)
end

Instance Method Details

#to_sObject



15
16
17
18
19
# File 'lib/takumi/packet/string.rb', line 15

def to_s
  packet = "".encode(Encoding::BINARY)
  packet << ::Takumi::Packet::Varint.new(@str.bytesize).to_s
  packet << @str.dup.force_encoding(Encoding::BINARY)
end