class BareTypes::String
Public Instance Methods
decode(msg)
click to toggle source
# File lib/types.rb, line 86 def decode(msg) strLen, rest = Uint.new.decode(msg) string = rest[0..strLen - 1] return string.force_encoding("utf-8"), rest[strLen..rest.size] end
encode(msg)
click to toggle source
# File lib/types.rb, line 74 def encode(msg) encodedString = nil begin encodedString = msg.encode("UTF-8").b rescue Encoding::UndefinedConversionError => error raise error.class, "Unable to convert string to UTF-8=, BARE strings are encoded as UTF8. If you can't convert your string to UTF-8 you can encode it with binary data" end bytes = Uint.new.encode(encodedString.size) bytes << encodedString return bytes end