summaryrefslogtreecommitdiff
path: root/cpp/bindings/qmf/ruby
diff options
context:
space:
mode:
authorKim van der Riet <kpvdr@apache.org>2012-05-04 15:39:19 +0000
committerKim van der Riet <kpvdr@apache.org>2012-05-04 15:39:19 +0000
commit633c33f224f3196f3f9bd80bd2e418d8143fea06 (patch)
tree1391da89470593209466df68c0b40b89c14963b1 /cpp/bindings/qmf/ruby
parentc73f9286ebff93a6c8dbc29cf05e258c4b55c976 (diff)
downloadqpid-python-633c33f224f3196f3f9bd80bd2e418d8143fea06.tar.gz
QPID-3858: Updated branch - merged from trunk r.1333987
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/asyncstore@1334037 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/bindings/qmf/ruby')
-rw-r--r--cpp/bindings/qmf/ruby/qmf.rb26
1 files changed, 20 insertions, 6 deletions
diff --git a/cpp/bindings/qmf/ruby/qmf.rb b/cpp/bindings/qmf/ruby/qmf.rb
index 34d3255d8d..9fbd50cbf6 100644
--- a/cpp/bindings/qmf/ruby/qmf.rb
+++ b/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