Class: Moc::Protocol::String

Inherits:
String
  • Object
show all
Extended by:
Type
Defined in:
lib/moc/protocol/string.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Type

read, unpack

Class Method Details

.read(io) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/moc/protocol/string.rb', line 16

def self.read (io)
	length = Integer.read(io)
	string = io.read(length)

	%w[UTF-8 ISO-8859-1].each {|encoding|
		if string.force_encoding(encoding).valid_encoding?
			return new(string)
		end
	}

	new(string.force_encoding('BINARY'))
end

Instance Method Details

#packObject



29
30
31
# File 'lib/moc/protocol/string.rb', line 29

def pack
	Integer.new(bytesize).pack << self.dup.force_encoding('BINARY')
end