revent 0.2.3 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/revent/Client.as CHANGED
@@ -12,23 +12,6 @@
12
12
  private var _socket:Socket;
13
13
  private var _bytes:ByteArray;
14
14
 
15
- public static function bytesToByteArray(bytes:Array):ByteArray {
16
- var ba:ByteArray = new ByteArray();
17
- ba.objectEncoding = ObjectEncoding.AMF3;
18
- for (var i:int = 0; i < bytes.length; i++) {
19
- ba.writeByte(bytes[i]);
20
- }
21
- return ba;
22
- }
23
-
24
- public static function bytesToObject(bytes:Array, compressed:Boolean = false):Object {
25
- var ba:ByteArray = bytesToByteArray(bytes);
26
- if (compressed) {
27
- ba.uncompress();
28
- }
29
- return ba.readObject();
30
- }
31
-
32
15
  public function Client():void {
33
16
  _socket = new Socket();
34
17
  _socket.objectEncoding = ObjectEncoding.AMF3;
@@ -3,6 +3,7 @@ module RubyAMF
3
3
  class AMFSerializer
4
4
 
5
5
  require "#{File.dirname(__FILE__)}/read_write"
6
+ require "#{File.dirname(__FILE__)}/byte_array"
6
7
 
7
8
  include RubyAMF::Configuration
8
9
  include RubyAMF::IO::BinaryWriter
@@ -43,7 +44,7 @@ module RubyAMF
43
44
  else
44
45
  write_amf3_number(value)
45
46
  end
46
- elsif(value.is_a?(Float))
47
+ elsif value.is_a?(Float)
47
48
  @stream << "\005" # represents an amf3 complex number
48
49
  write_double(value)
49
50
  elsif value.is_a?(BigDecimal) # Aryk: BigDecimal does not relate to Float, so keep it as a seperate check.
@@ -53,17 +54,20 @@ module RubyAMF
53
54
  write_double(value)
54
55
  end
55
56
 
56
- elsif(value.is_a?(String))
57
+ elsif value.is_a?(String)
57
58
  @stream << "\006" # represents an amf3 string
58
59
  write_amf3_string(value)
59
60
 
60
- elsif(value.is_a?(Array))
61
+ elsif value.is_a?(Array)
61
62
  write_amf3_array(value)
62
63
 
63
- elsif(value.is_a?(Hash))
64
+ elsif value.is_a?(ByteArray)
65
+ write_amf3_byte_array(value)
66
+
67
+ elsif value.is_a?(Hash)
64
68
  write_amf3_object(value)
65
69
 
66
- elsif (value.is_a?(Time)||value.is_a?(Date))
70
+ elsif value.is_a?(Time) || value.is_a?(Date)
67
71
  @stream << "\b" # represents an amf3 date
68
72
  write_amf3_date(value)
69
73
 
@@ -83,19 +87,19 @@ module RubyAMF
83
87
  def write_amf3_integer(int)
84
88
  @stream << (@write_amf3_integer_results[int] ||= (
85
89
  int = int & 0x1fffffff
86
- if(int < 0x80)
90
+ if int < 0x80
87
91
  [int].pack('c')
88
- elsif(int < 0x4000)
89
- [int >> 7 & 0x7f | 0x80].pack('c')+
92
+ elsif int < 0x4000
93
+ [int >> 7 & 0x7f | 0x80].pack('c') +
90
94
  [int & 0x7f].pack('c')
91
- elsif(int < 0x200000)
92
- [int >> 14 & 0x7f | 0x80].pack('c')+
93
- [int >> 7 & 0x7f | 0x80].pack('c')+
95
+ elsif int < 0x200000
96
+ [int >> 14 & 0x7f | 0x80].pack('c') +
97
+ [int >> 7 & 0x7f | 0x80].pack('c') +
94
98
  [int & 0x7f].pack('c')
95
99
  else
96
- [int >> 22 & 0x7f | 0x80].pack('c')+
97
- [int >> 15 & 0x7f | 0x80].pack('c')+
98
- [int >> 8 & 0x7f | 0x80].pack('c')+
100
+ [int >> 22 & 0x7f | 0x80].pack('c') +
101
+ [int >> 15 & 0x7f | 0x80].pack('c') +
102
+ [int >> 8 & 0x7f | 0x80].pack('c') +
99
103
  [int & 0xff].pack('c')
100
104
  end
101
105
  ))
@@ -167,7 +171,16 @@ module RubyAMF
167
171
  # datetime = Time.gm( datetime.year, datetime.month, datetime.day )
168
172
  # datetime = Time.gm( datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec )
169
173
  end
170
- write_double( (seconds*1000).to_i ) # used to be total_milliseconds = datetime.to_i * 1000 + ( datetime.usec/1000 )
174
+ write_double((seconds*1000).to_i) # used to be total_milliseconds = datetime.to_i * 1000 + ( datetime.usec/1000 )
175
+ end
176
+
177
+ def write_amf3_byte_array(byte_array)
178
+ write_word8(AMF3_BYTE_ARRAY)
179
+ bytes = byte_array.bytes
180
+ length = bytes.length << 1
181
+ length = length | 0x1
182
+ write_amf3_integer(length)
183
+ @stream << bytes
171
184
  end
172
185
 
173
186
  def write_amf3_xml(value)
@@ -0,0 +1,11 @@
1
+ module RubyAMF
2
+ module IO
3
+ class ByteArray
4
+ attr_reader :bytes
5
+
6
+ def initialize(string)
7
+ @bytes = string
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/revent/as_r.rb CHANGED
@@ -133,8 +133,7 @@ module Revent
133
133
  s = @enc.stream
134
134
  @enc.reset
135
135
 
136
- s = Zlib::Deflate.deflate(s)
137
- s.unpack('c*')
136
+ Zlib::Deflate.deflate(s)
138
137
  end
139
138
  end
140
139
 
@@ -57,8 +57,7 @@
57
57
  _status.text += "onResult";
58
58
  _status.text += "cmd:" + event.cmd;
59
59
 
60
- var b:Array = event.value as Array;
61
- //trace(b);
60
+ var b:ByteArray = event.value as ByteArray;
62
61
  _status.text += "Received bytes: " + b.length;
63
62
  _size += 1024;
64
63
  _status.text += "Testing byte array with size: " + _size;
data/test/as_r/client.swf CHANGED
Binary file
data/test/as_r/server.rb CHANGED
@@ -24,11 +24,9 @@ class Server
24
24
 
25
25
  def on_call(client, cmd, value)
26
26
  puts "on_call:", cmd, value
27
- a = []
28
- (0...value).each do |i|
29
- a << i
27
+ if cmd == CMD_TEST_BYTE_ARRAY
28
+ test_byte_array(client, value)
30
29
  end
31
- client.result(CMD_TEST_BYTE_ARRAY, a)
32
30
  end
33
31
 
34
32
  def on_result(client, cmd, value)
@@ -44,6 +42,17 @@ class Server
44
42
  puts cmd
45
43
  puts error
46
44
  end
45
+
46
+ # ----------------------------------------------------------------------------
47
+
48
+ def test_byte_array(client, length)
49
+ bytes = ''
50
+ length.times do
51
+ bytes << rand(256)
52
+ end
53
+ byte_array = RubyAMF::IO::ByteArray.new(bytes)
54
+ client.result(CMD_TEST_BYTE_ARRAY, byte_array)
55
+ end
47
56
  end
48
57
 
49
58
  EventMachine::run do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngoc DAO Thanh
@@ -45,6 +45,7 @@ files:
45
45
  - lib/revent/amf3/io/amf_deserializer.rb
46
46
  - lib/revent/amf3/io/read_write.rb
47
47
  - lib/revent/amf3/io/amf_serializer.rb
48
+ - lib/revent/amf3/io/byte_array.rb
48
49
  - lib/revent/amf3/util
49
50
  - lib/revent/amf3/util/vo_helper.rb
50
51
  - lib/revent/amf3/util/string.rb