Class: GwtRpc::Response::Reader
- Inherits:
-
Object
- Object
- GwtRpc::Response::Reader
- Defined in:
- lib/gwt_rpc/response/reader.rb
Constant Summary collapse
- DEBUG =
false
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#string_table ⇒ Object
readonly
Returns the value of attribute string_table.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #debug ⇒ Object
- #demangle_json_body(faux_json) ⇒ Object
-
#initialize(client, json_body) ⇒ Reader
constructor
A new instance of Reader.
- #read_int ⇒ Object
- #read_object ⇒ Object
- #read_string(position = read_int) ⇒ Object
Constructor Details
#initialize(client, json_body) ⇒ Reader
Returns a new instance of Reader.
5 6 7 8 9 10 11 |
# File 'lib/gwt_rpc/response/reader.rb', line 5 def initialize(client, json_body) @client = client true_json = demangle_json_body(json_body) (@version, placeholder, @string_table, *@data) = JSON.parse(true_json).reverse @max_prior_string_location = 0 @objects = [] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/gwt_rpc/response/reader.rb', line 4 def data @data end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
4 5 6 |
# File 'lib/gwt_rpc/response/reader.rb', line 4 def objects @objects end |
#string_table ⇒ Object (readonly)
Returns the value of attribute string_table.
4 5 6 |
# File 'lib/gwt_rpc/response/reader.rb', line 4 def string_table @string_table end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/gwt_rpc/response/reader.rb', line 4 def version @version end |
Instance Method Details
#debug ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/gwt_rpc/response/reader.rb', line 69 def debug html = "<table>\n" html << @data.map{|i| [i, @string_table[i-1]].map{|val| "<td>#{val}</td>"}}.map{|row| "<tr>#{row}</tr>"}.join("\n") html << "</table><table>\n" @string_table.each_with_index{|str,i| html << "<tr><td>#{i+1}</td><td>#{str}</td></tr>\n"} html << "</table>" html end |
#demangle_json_body(faux_json) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gwt_rpc/response/reader.rb', line 79 def demangle_json_body(faux_json) if faux_json.match(/^\[(.+),\[(.+)\],0,7\]$/) data = $1 string_table = $2 data.gsub!(/'/,'"') "[#{data},[#{string_table}],0,7]" else raise "can't demangle" end end |
#read_int ⇒ Object
13 14 15 16 17 |
# File 'lib/gwt_rpc/response/reader.rb', line 13 def read_int int = @data.shift puts "read int #{int}" if DEBUG int end |
#read_object ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gwt_rpc/response/reader.rb', line 34 def read_object int = read_int if int < 0 puts "reading obj reference (#{int})" if DEBUG obj = @objects[-1 - int] # if int == -11 # puts obj.inspect # @objects.each_with_index do |doc, i| # puts "#{i} => #{doc.inspect}" # end # exit # end elsif int > 0 java_class = read_string(int) java_class.sub!(/\/\d+$/,'') puts "reading obj #{java_class}" if DEBUG ruby_class = @client.class.java_class_to_ruby(java_class) if ruby_class placeholder_position = @objects.count @objects << "PLACEHOLDER of type #{java_class}" obj = ruby_class.constantize.gwt_deserialize(self) @objects[placeholder_position] = obj else raise "unknown java class '#{java_class}'" end elsif int == 0 puts "reading obj nil (0)" if DEBUG obj = nil end obj end |
#read_string(position = read_int) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gwt_rpc/response/reader.rb', line 19 def read_string(position=read_int) if position > (@max_prior_string_location + 1) raise "trying to read #{position}, which is too far ahead; max seen thus far is #{@max_prior_string_location}!" end if position > @max_prior_string_location @max_prior_string_location += 1 end val = @string_table[position-1] puts "read str #{val} (@#{position})" if DEBUG val end |