Class: BareTypes::String

Inherits:
BarePrimitive show all
Defined in:
lib/types.rb

Instance Method Summary collapse

Methods inherited from BarePrimitive

#==, #finalize_references, #to_schema

Methods inherited from BaseType

#cycle_search, #initialize

Constructor Details

This class inherits a constructor from BareTypes::BaseType

Instance Method Details

#decode(msg) ⇒ Object



210
211
212
213
214
# File 'lib/types.rb', line 210

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, buffer) ⇒ Object



200
201
202
203
204
205
206
207
208
# File 'lib/types.rb', line 200

def encode(msg, buffer)
  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
  Uint.new.encode(encodedString.size, buffer)
  buffer << encodedString
end