summaryrefslogtreecommitdiff
path: root/qpid/cpp/bindings/qmf/ruby/qmf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/bindings/qmf/ruby/qmf.rb')
-rw-r--r--qpid/cpp/bindings/qmf/ruby/qmf.rb26
1 files changed, 20 insertions, 6 deletions
diff --git a/qpid/cpp/bindings/qmf/ruby/qmf.rb b/qpid/cpp/bindings/qmf/ruby/qmf.rb
index 34d3255d8d..9fbd50cbf6 100644
--- a/qpid/cpp/bindings/qmf/ruby/qmf.rb
+++ b/qpid/cpp/bindings/qmf/ruby/qmf.rb
@@ -26,18 +26,28 @@ module Qmf
# Pull all the TYPE_* constants into Qmf namespace. Maybe there's an easier way?
Qmfengine.constants.each do |c|
+ c = c.to_s
if c.index('TYPE_') == 0 or c.index('ACCESS_') == 0 or c.index('DIR_') == 0 or
c.index('CLASS_') == 0 or c.index('SEV_') == 0
const_set(c, Qmfengine.const_get(c))
end
end
+ module StringHelpers
+ def ensure_encoding(str)
+ enc = (Encoding.default_external.name || "UTF-8" rescue "UTF-8")
+ str.respond_to?(:force_encoding) ? str.force_encoding(enc) : str
+ end
+ end
+
class Util
+ include StringHelpers
+
def qmf_to_native(val)
case val.getType
when TYPE_UINT8, TYPE_UINT16, TYPE_UINT32 then val.asUint
when TYPE_UINT64 then val.asUint64
- when TYPE_SSTR, TYPE_LSTR then val.asString
+ when TYPE_SSTR, TYPE_LSTR then ensure_encoding(val.asString)
when TYPE_ABSTIME then val.asInt64
when TYPE_DELTATIME then val.asUint64
when TYPE_REF then ObjectId.new(val.asObjectId)
@@ -161,6 +171,7 @@ module Qmf
##==============================================================================
class ConnectionSettings
+ include StringHelpers
attr_reader :impl
def initialize(url = nil)
@@ -192,7 +203,7 @@ module Qmf
def get_attr(key)
_v = @impl.getAttr(key)
if _v.isString()
- return _v.asString()
+ return ensure_encoding(_v.asString())
elsif _v.isUint()
return _v.asUint()
elsif _v.isBool()
@@ -348,7 +359,7 @@ module Qmf
@broker = kwargs[:broker] if kwargs.include?(:broker)
@allow_sets = :true
- if cls:
+ if cls
@event_class = cls
@impl = Qmfengine::Event.new(@event_class.impl)
elsif kwargs.include?(:impl)
@@ -434,7 +445,7 @@ module Qmf
@allow_sets = :false
@broker = kwargs[:broker] if kwargs.include?(:broker)
- if cls:
+ if cls
@object_class = cls
@impl = Qmfengine::Object.new(@object_class.impl)
elsif kwargs.include?(:impl)
@@ -707,6 +718,8 @@ module Qmf
end
class MethodResponse
+ include StringHelpers
+
def initialize(impl)
@impl = Qmfengine::MethodResponse.new(impl)
end
@@ -720,7 +733,7 @@ module Qmf
end
def text
- exception.asString
+ ensure_encoding(exception.asString)
end
def args
@@ -885,6 +898,7 @@ module Qmf
end
class SchemaClassKey
+ include StringHelpers
attr_reader :impl
def initialize(i)
@impl = Qmfengine::SchemaClassKey.new(i)
@@ -899,7 +913,7 @@ module Qmf
end
def to_s
- @impl.asString
+ ensure_encoding(@impl.asString)
end
end