Skip to content

Commit

Permalink
1.8.7/1.9 string encoding capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Collin Miller committed May 27, 2010
1 parent d62ff88 commit 7b59521
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
8 changes: 6 additions & 2 deletions lib/rocketamf/pure/io_helpers.rb
Expand Up @@ -86,11 +86,15 @@ def pack_integer(integer)
[integer & 0xff].pack('c')
end

packed.force_encoding("UTF-8")

packed.force_encoding("UTF-8") if packed.respond_to?(:force_encoding)
packed
end

def pack_double(double)
[double].pack('G').force_encoding("UTF-8")
packed = [double].pack('G')
packed.force_encoding("UTF-8") if packed.respond_to?(:force_encoding)
packed
end

def pack_int8(val)
Expand Down
18 changes: 13 additions & 5 deletions lib/rocketamf/pure/remoting.rb
Expand Up @@ -50,7 +50,8 @@ def populate_from_stream stream
# RocketAMF::Response for deserializing the given stream.
module Response
def serialize
stream = "".encode("UTF-8")
stream = ""
stream.encode("UTF-8") if stream.respond_to?(:encode)

# Write version
stream << pack_int16_network(@amf_version)
Expand All @@ -69,15 +70,22 @@ def serialize
stream << pack_int16_network(@messages.length) # Message count
@messages.each do |m|
# # Rails.logger.info("Packing message")
stream << pack_int16_network(m.target_uri.length).force_encoding("UTF-8")
packed_target_uri = pack_int16_network(m.target_uri.length)
packed_target_uri.force_encoding("UTF-8") if packed_target_uri.respond_to?(:force_encoding)

stream << packed_target_uri
stream << m.target_uri

stream << pack_int16_network(m.response_uri.length)
response_uri_length = pack_int16_network(m.response_uri.length)
response_uri_length.force_encoding("UTF-8") if packed_target_uri.respond_to?(:force_encoding)
stream << response_uri_length
stream << m.response_uri

stream << pack_word32_network(-1).force_encoding("UTF-8")
packed_neg_one = pack_word32_network(-1)
packed_neg_one.force_encoding("UTF-8") if packed_neg_one.respond_to?(:force_encoding)
stream << packed_neg_one
stream << AMF0_AMF3_MARKER if @amf_version == 3
stream.encode("UTF-8")
stream.encode("UTF-8") if stream.respond_to?(:encode)
# # Rails.logger.info("stream #{stream.encoding} serialized #{RocketAMF.serialize(m.data, @amf_version).encoding}")
stream << RocketAMF.serialize(m.data, @amf_version)
# # Rails.logger.info("Packed message #{m}")
Expand Down
14 changes: 6 additions & 8 deletions lib/rocketamf/pure/serializer.rb
Expand Up @@ -3,12 +3,9 @@
module RocketAMF
module Pure
class EncodedStream < String
def << str
# # Rails.logger.info("stream #{encoding}")
# # Rails.logger.info(">> write_utf8_vr #{str.to_s} #{str.to_s.encoding}")
super(str)
# # Rails.logger.info("stream #{encoding}")
# # Rails.logger.info("---------------------------------------")
def initialize(*)
super
encode("UTF-8") if respond_to?(:encode)
end
end
# AMF0 implementation of serializer
Expand Down Expand Up @@ -149,7 +146,7 @@ def version
3
end

def serialize obj, stream = EncodedStream.new.encode("UTF-8")
def serialize obj, stream = EncodedStream.new
if obj.respond_to?(:to_amf)
stream << obj.to_amf(self)
elsif obj.is_a?(NilClass)
Expand Down Expand Up @@ -313,7 +310,8 @@ def write_utf8_vr str, stream
# "can't force encoding of frozen object"
# Hence the dup. But we still don't know why str is frozen
# TODO: Determine why str is frozen.
stream << str.dup.force_encoding("UTF-8")
str = str.dup.force_encoding("UTF-8") if str.respond_to?("force_encoding")
stream << str
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/amf/do_not_publish_fp_amf_requests.rb
@@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../spec_helper.rb'

describe RocketAMF::Request do
it "should handle a set of challeng rules (contains dict)" do
req = create_request("challengeRules")
message = req.messages[0].data
require 'pp'
raise message.body.pretty_inspect
end
end
Binary file added spec/fixtures/request/challengeRules
Binary file not shown.

0 comments on commit 7b59521

Please sign in to comment.