lwes_pure 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +67 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/lib/lwes/emitter.rb +36 -0
- data/lib/lwes/event.rb +81 -0
- data/lib/lwes/helpers.rb +9 -0
- data/lib/lwes/serialization.rb +197 -0
- data/lib/lwes/types.rb +33 -0
- data/lib/lwes.rb +2 -0
- data/lwes_pure.gemspec +84 -0
- data/spec/data/lwes.bin +0 -0
- data/spec/lwes_spec.rb +74 -0
- data/spec/serialiation_spec.rb +292 -0
- data/spec/spec_helper.rb +12 -0
- metadata +211 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'bindata'
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.3.0"
|
11
|
+
gem "yard", "~> 0.6.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.5.2"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
gem "reek", "~> 1.2.8"
|
16
|
+
gem "roodi", "~> 2.1.0"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
bindata (1.3.1)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rake (0.8.7)
|
12
|
+
rcov (0.9.9)
|
13
|
+
reek (1.2.8)
|
14
|
+
ruby2ruby (~> 1.2)
|
15
|
+
ruby_parser (~> 2.0)
|
16
|
+
sexp_processor (~> 3.0)
|
17
|
+
roodi (2.1.0)
|
18
|
+
ruby_parser
|
19
|
+
rspec (2.3.0)
|
20
|
+
rspec-core (~> 2.3.0)
|
21
|
+
rspec-expectations (~> 2.3.0)
|
22
|
+
rspec-mocks (~> 2.3.0)
|
23
|
+
rspec-core (2.3.1)
|
24
|
+
rspec-expectations (2.3.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.3.0)
|
27
|
+
ruby2ruby (1.2.5)
|
28
|
+
ruby_parser (~> 2.0)
|
29
|
+
sexp_processor (~> 3.0)
|
30
|
+
ruby_parser (2.0.6)
|
31
|
+
sexp_processor (~> 3.0)
|
32
|
+
sexp_processor (3.0.5)
|
33
|
+
yard (0.6.8)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bindata
|
40
|
+
bundler (~> 1.0.0)
|
41
|
+
jeweler (~> 1.5.2)
|
42
|
+
rcov
|
43
|
+
reek (~> 1.2.8)
|
44
|
+
roodi (~> 2.1.0)
|
45
|
+
rspec (~> 2.3.0)
|
46
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Aaron Qian
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= lwes_pure
|
2
|
+
|
3
|
+
LWES - Light Weight Event System protocol implemented in pure ruby. The original lwes gem is a thin wrapper around the c library, and does not handle data types for dynamic LWES events. This gem allows users to define the data type of attributes in an clear way, so that your LWES event listeners will be happy. This library includes the following components:
|
4
|
+
|
5
|
+
* Lwes::Event for reading from and writing to IO objects.
|
6
|
+
* Lwes::Emitter for emitting LWES events through UDP socket.
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
gem install lwes_pure
|
11
|
+
|
12
|
+
== Initialization
|
13
|
+
|
14
|
+
If only Lwes::Event is needed, require like this:
|
15
|
+
|
16
|
+
require 'lwes/event'
|
17
|
+
|
18
|
+
If both Lwes::Event and Lwes::Emitter are needed, require like this:
|
19
|
+
|
20
|
+
require 'lwes'
|
21
|
+
|
22
|
+
== Usage
|
23
|
+
|
24
|
+
Here is a short example to create an event and send it off using udp
|
25
|
+
|
26
|
+
# requiring lwes_pure gem
|
27
|
+
require 'lwes'
|
28
|
+
|
29
|
+
# create a LWES emitter
|
30
|
+
emitter = Lwes::Emitter.new({
|
31
|
+
:host => "127.0.0.1",
|
32
|
+
:port => "12345"
|
33
|
+
})
|
34
|
+
|
35
|
+
# create a LWES event with 3 attributes of type int16, string, and ip array
|
36
|
+
event = Lwes::Event.new({
|
37
|
+
:name => "Test::Event",
|
38
|
+
:attributes => {
|
39
|
+
'int_attribute' => [:int16, 123],
|
40
|
+
'string_attribute' => [:attr_str, "test string"],
|
41
|
+
'ip_attribute' => [:ip_v4_array, ["1.2.3.4", "5.6.7.8", "192.168.0.255"]]
|
42
|
+
}
|
43
|
+
})
|
44
|
+
|
45
|
+
# send it off with the emitter
|
46
|
+
emitter.emit event
|
47
|
+
|
48
|
+
== Future works
|
49
|
+
|
50
|
+
* Implement Listener
|
51
|
+
* Better error handling
|
52
|
+
|
53
|
+
== Contributing to lwes_pure
|
54
|
+
|
55
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
56
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
57
|
+
* Fork the project
|
58
|
+
* Start a feature/bugfix branch
|
59
|
+
* Commit and push until you are happy with your contribution
|
60
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
61
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
62
|
+
|
63
|
+
== Copyright
|
64
|
+
|
65
|
+
Copyright (c) 2011 Aaron Qian. See LICENSE.txt for
|
66
|
+
further details.
|
67
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "lwes_pure"
|
16
|
+
gem.homepage = "http://github.com/aq1018/lwes_pure"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{LWES - Light Weight Event System protocol implemented in pure ruby.}
|
19
|
+
gem.description = %Q{The original lwes gem is a thin wrapper around the c library, and does not handle data types for dynamic LWES events. This gem allows users to define the data type of attributes in an clear way, so that your LWES event listeners will be happy. This library includes the following components.}
|
20
|
+
gem.email = "aqian@attinteractive.com"
|
21
|
+
gem.authors = ["Aaron Qian"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
spec.rspec_opts = "--color --format progress"
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
spec.rcov_opts = "--exclude ~\/.rvm,spec"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'reek/rake/task'
|
44
|
+
Reek::Rake::Task.new do |t|
|
45
|
+
t.fail_on_error = true
|
46
|
+
t.verbose = false
|
47
|
+
t.source_files = 'lib/**/*.rb'
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'roodi'
|
51
|
+
require 'roodi_task'
|
52
|
+
RoodiTask.new do |t|
|
53
|
+
t.verbose = false
|
54
|
+
end
|
55
|
+
|
56
|
+
task :default => :spec
|
57
|
+
|
58
|
+
require 'yard'
|
59
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.3
|
data/lib/lwes/emitter.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Lwes
|
4
|
+
# Emit LWES events to a UDP endpoint
|
5
|
+
class Emitter
|
6
|
+
DEFAULT_SOCIKET_OPTIONS = {
|
7
|
+
:address_family => Socket::AF_INET,
|
8
|
+
:host => "127.0.0.1",
|
9
|
+
:port => 12345
|
10
|
+
}
|
11
|
+
|
12
|
+
attr_accessor :socket_options, :socket
|
13
|
+
|
14
|
+
# Creates a new {Lwes::Emitter}.
|
15
|
+
# @param [Hash] options
|
16
|
+
# @option options [String] :host UDP host address, defaults to 127.0.0.1
|
17
|
+
# @option options [String, Number] :port UDP port, defaults to 12345
|
18
|
+
# @option options [Number] :address_family, Address family of the socket, defaults to Socket::AF_INET
|
19
|
+
def initialize(options={})
|
20
|
+
self.socket_options = DEFAULT_SOCIKET_OPTIONS.merge(options)
|
21
|
+
self.socket = UDPSocket.new(@socket_options[:address_family])
|
22
|
+
socket.connect(@socket_options[:host], @socket_options[:port])
|
23
|
+
end
|
24
|
+
|
25
|
+
# Emits specified event
|
26
|
+
# @param [Lwes::Event] event The event to send
|
27
|
+
# @return [Number] the number of bytes sent
|
28
|
+
def emit(event)
|
29
|
+
buffer = StringIO.new
|
30
|
+
event.write(buffer)
|
31
|
+
buffer.rewind
|
32
|
+
socket.write(buffer.read)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/lwes/event.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'bindata'
|
2
|
+
require 'lwes/types'
|
3
|
+
require 'lwes/helpers'
|
4
|
+
require 'lwes/serialization'
|
5
|
+
|
6
|
+
module Lwes
|
7
|
+
# Represent a LWES event, can read from and write to IO objects
|
8
|
+
class Event
|
9
|
+
attr_accessor :name, :attributes
|
10
|
+
|
11
|
+
# Creates a new {Lwes::Emitter}.
|
12
|
+
# @param [Hash] hash
|
13
|
+
# @option hash [String] :name The event name
|
14
|
+
# @option hash [Hash] :attributes Attributes of the event.
|
15
|
+
# The hash key is the attribute name, the hash value should be an Array of two elements.
|
16
|
+
# The first element is the type see {Lwes::TYPE_TO_BYTE} for all available types.
|
17
|
+
# The second element is the actual value of the attribute.
|
18
|
+
# @option hash [Number] :address_family, Address family of the socket, defaults to Socket::AF_INET.
|
19
|
+
def initialize(hash={})
|
20
|
+
self.name = hash[:name] || ""
|
21
|
+
self.attributes = hash[:attributes] || {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Writes the event to an IO object
|
25
|
+
# @param [IO] io The IO object to write to.
|
26
|
+
# @return [Number] Number of bytes written to IO
|
27
|
+
def write(io)
|
28
|
+
serializer.write(io)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Read from an IO object
|
32
|
+
# @param [IO] io The IO object to read from.
|
33
|
+
def read(io)
|
34
|
+
serializer = Lwes::Serialization::Event.read(io)
|
35
|
+
set_attributes_from_serializer(serializer)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Read from an IO object
|
39
|
+
# @param [IO] io The IO object to read from.
|
40
|
+
# @return [Lwes::Event] a new {Lwes::Event} instance with data filled from the IO.
|
41
|
+
def self.read(io)
|
42
|
+
event = new
|
43
|
+
event.read(io)
|
44
|
+
event
|
45
|
+
end
|
46
|
+
|
47
|
+
# Converts the event to a hash representation
|
48
|
+
# @return [Hash] the hash representation of the instance.
|
49
|
+
def to_hash
|
50
|
+
{
|
51
|
+
:name => name,
|
52
|
+
:attributes => attributes
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def serializer
|
58
|
+
Lwes::Serialization::Event.new(:name => name, :attributes => attributes_to_serializer)
|
59
|
+
end
|
60
|
+
|
61
|
+
def attributes_to_serializer
|
62
|
+
attributes.collect do |key, value|
|
63
|
+
[ key, value[0], value[1] ]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_attributes_from_serializer(serializer)
|
68
|
+
@name = serializer.name
|
69
|
+
@attributes = serializer.attributes.inject({}) do |hash, attribute|
|
70
|
+
key, vtype, value = *attribute
|
71
|
+
# convert to real string
|
72
|
+
key = key.to_s
|
73
|
+
# convert BinData types to actual types
|
74
|
+
value = value.value
|
75
|
+
|
76
|
+
hash[key] = [vtype, value]
|
77
|
+
hash
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/lwes/helpers.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
module Lwes
|
2
|
+
module Serialization
|
3
|
+
extend Lwes::Helpers
|
4
|
+
|
5
|
+
class Boolean < BinData::BasePrimitive
|
6
|
+
register_self
|
7
|
+
|
8
|
+
def value_to_binary_string(value)
|
9
|
+
value ? 1.chr : 0.chr
|
10
|
+
end
|
11
|
+
|
12
|
+
def read_and_return_value(io)
|
13
|
+
byte = read_uint8(io)
|
14
|
+
byte != 0 # 0 is false, everything else is true
|
15
|
+
end
|
16
|
+
|
17
|
+
def sensible_default
|
18
|
+
false
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_uint8(io)
|
22
|
+
io.readbytes(1).unpack("C").at(0)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class NameStr < BinData::Primitive
|
27
|
+
endian :big
|
28
|
+
uint8 :len, :initial_value => lambda { data.length }
|
29
|
+
string :data, :initial_value => lambda { value }, :read_length => :len
|
30
|
+
|
31
|
+
def get
|
32
|
+
self.data
|
33
|
+
end
|
34
|
+
|
35
|
+
def set(val)
|
36
|
+
self.data = val
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class AttrStr < BinData::Primitive
|
41
|
+
endian :big
|
42
|
+
uint16 :len, :initial_value => lambda { data.length }
|
43
|
+
string :data, :initial_value => lambda { value }, :read_length => :len
|
44
|
+
|
45
|
+
def get; self.data; end
|
46
|
+
def set(val) self.data = val; end
|
47
|
+
end
|
48
|
+
|
49
|
+
class IpAddr < BinData::Primitive
|
50
|
+
endian :little
|
51
|
+
uint32 :data, :initial_value => lambda { ip_to_int32(value) }
|
52
|
+
|
53
|
+
def ip_to_int32(str)
|
54
|
+
ary = str.to_s.split(".").collect{ |byte| byte.to_i }.slice(0,4)
|
55
|
+
((ary[3] & 0xff) << 24) + ((ary[2] & 0xff) << 16) + ((ary[1] & 0xff) << 8) + (ary[0] & 0xff)
|
56
|
+
end
|
57
|
+
|
58
|
+
def int32_to_ip(num)
|
59
|
+
ary = []
|
60
|
+
|
61
|
+
4.times do
|
62
|
+
ary << (num & 0xff)
|
63
|
+
num = num >> 8
|
64
|
+
end
|
65
|
+
|
66
|
+
ary.join(".")
|
67
|
+
end
|
68
|
+
|
69
|
+
def get
|
70
|
+
self.int32_to_ip(self.data)
|
71
|
+
end
|
72
|
+
|
73
|
+
def set(val)
|
74
|
+
self.data = ip_to_int32(val)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class IpV4 < BinData::Primitive
|
79
|
+
endian :big
|
80
|
+
uint32 :data, :initial_value => lambda { ip_to_int32(value) }
|
81
|
+
|
82
|
+
def ip_to_int32(str)
|
83
|
+
ary = str.to_s.split(".").collect{ |byte| byte.to_i }.slice(0,4)
|
84
|
+
((ary[3] & 0xff) << 24) + ((ary[2] & 0xff) << 16) + ((ary[1] & 0xff) << 8) + (ary[0] & 0xff)
|
85
|
+
end
|
86
|
+
|
87
|
+
def int32_to_ip(num)
|
88
|
+
ary = []
|
89
|
+
|
90
|
+
4.times do
|
91
|
+
ary << (num & 0xff)
|
92
|
+
num = num >> 8
|
93
|
+
end
|
94
|
+
|
95
|
+
ary.join(".")
|
96
|
+
end
|
97
|
+
|
98
|
+
def get
|
99
|
+
self.int32_to_ip(self.data)
|
100
|
+
end
|
101
|
+
|
102
|
+
def set(val)
|
103
|
+
self.data = ip_to_int32(val)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
Lwes::TYPE_TO_BYTE.keys.select{|key| key.to_s =~ /_array/}.each do |key|
|
108
|
+
key = key.to_s
|
109
|
+
klass_name = camelcase(key.to_s)
|
110
|
+
type = key.gsub(/_array/, '')
|
111
|
+
|
112
|
+
class_eval <<-END
|
113
|
+
class #{klass_name} < BinData::Primitive
|
114
|
+
endian :big
|
115
|
+
uint16 :len, :initial_value => lambda{ data.length }
|
116
|
+
array :data, :type => :'#{type}', :initial_length => :len
|
117
|
+
|
118
|
+
def assign(val)
|
119
|
+
super
|
120
|
+
self.data = value
|
121
|
+
end
|
122
|
+
|
123
|
+
def get; self.data; end
|
124
|
+
def set(val) self.data = val; end
|
125
|
+
end
|
126
|
+
END
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
class Attribute < BinData::Primitive
|
132
|
+
endian :big
|
133
|
+
name_str :key, :initial_value => lambda { extract_key(value) }
|
134
|
+
uint8 :vtype, :initial_value => lambda { extract_type(value) }
|
135
|
+
choice :val, :selection => :vtype, :choices => Lwes::BYTE_TO_TYPE
|
136
|
+
|
137
|
+
def assign(val)
|
138
|
+
super
|
139
|
+
self.val = extract_value(val)
|
140
|
+
end
|
141
|
+
|
142
|
+
def extract_key(val)
|
143
|
+
val[0]
|
144
|
+
end
|
145
|
+
|
146
|
+
def extract_type(val)
|
147
|
+
Lwes::TYPE_TO_BYTE[val[1]]
|
148
|
+
end
|
149
|
+
|
150
|
+
def extract_value(val)
|
151
|
+
val[2]
|
152
|
+
end
|
153
|
+
|
154
|
+
def get
|
155
|
+
[self.key, BYTE_TO_TYPE[self.vtype], self.val]
|
156
|
+
end
|
157
|
+
|
158
|
+
def set(val)
|
159
|
+
self.key = extract_key(val)
|
160
|
+
self.vtype = extract_type(val)
|
161
|
+
self.val = extract_value(val)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
class AttributeArray < BinData::Primitive
|
167
|
+
endian :big
|
168
|
+
uint16 :len, :value => lambda{ data.length }
|
169
|
+
array :data, :type => :attribute, :initial_length => :len
|
170
|
+
|
171
|
+
def assign(val)
|
172
|
+
super
|
173
|
+
self.data = []
|
174
|
+
value.each do |attribute|
|
175
|
+
self.data << attribute
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def get
|
180
|
+
self.data
|
181
|
+
end
|
182
|
+
|
183
|
+
def set(val)
|
184
|
+
self.data = []
|
185
|
+
val.each do |attribute|
|
186
|
+
self.data << attribute
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class Event < BinData::Record
|
192
|
+
endian :big
|
193
|
+
name_str :name
|
194
|
+
attribute_array :attributes
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
data/lib/lwes/types.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Lwes
|
2
|
+
TYPE_TO_BYTE = {
|
3
|
+
:uint16 => 1,
|
4
|
+
:int16 => 2,
|
5
|
+
:uint32 => 3,
|
6
|
+
:int32 => 4,
|
7
|
+
:attr_str => 5,
|
8
|
+
:ip_addr => 6,
|
9
|
+
:int64 => 7,
|
10
|
+
:uint64 => 8,
|
11
|
+
:boolean => 9,
|
12
|
+
:uint8 => 10,
|
13
|
+
:float => 11,
|
14
|
+
:double => 12,
|
15
|
+
:ip_v4 => 13,
|
16
|
+
|
17
|
+
:uint16_array => 129,
|
18
|
+
:int16_array => 130,
|
19
|
+
:uint32_array => 131,
|
20
|
+
:int32_array => 132,
|
21
|
+
:attr_str_array => 133,
|
22
|
+
:ip_addr_array => 134,
|
23
|
+
:int64_array => 135,
|
24
|
+
:uint64_array => 136,
|
25
|
+
:boolean_array => 137,
|
26
|
+
:uint8_array => 138,
|
27
|
+
:float_array => 139,
|
28
|
+
:double_array => 140,
|
29
|
+
:ip_v4_array => 141
|
30
|
+
}
|
31
|
+
|
32
|
+
BYTE_TO_TYPE = TYPE_TO_BYTE.invert
|
33
|
+
end
|
data/lib/lwes.rb
ADDED
data/lwes_pure.gemspec
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{lwes_pure}
|
8
|
+
s.version = "0.1.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aaron Qian"]
|
12
|
+
s.date = %q{2011-04-21}
|
13
|
+
s.description = %q{The original lwes gem is a thin wrapper around the c library, and does not handle data types for dynamic LWES events. This gem allows users to define the data type of attributes in an clear way, so that your LWES event listeners will be happy. This library includes the following components.}
|
14
|
+
s.email = %q{aqian@attinteractive.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/lwes.rb",
|
29
|
+
"lib/lwes/emitter.rb",
|
30
|
+
"lib/lwes/event.rb",
|
31
|
+
"lib/lwes/helpers.rb",
|
32
|
+
"lib/lwes/serialization.rb",
|
33
|
+
"lib/lwes/types.rb",
|
34
|
+
"lwes_pure.gemspec",
|
35
|
+
"spec/data/lwes.bin",
|
36
|
+
"spec/lwes_spec.rb",
|
37
|
+
"spec/serialiation_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/aq1018/lwes_pure}
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.6.2}
|
44
|
+
s.summary = %q{LWES - Light Weight Event System protocol implemented in pure ruby.}
|
45
|
+
s.test_files = [
|
46
|
+
"spec/lwes_spec.rb",
|
47
|
+
"spec/serialiation_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<bindata>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
57
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
58
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
|
62
|
+
s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<bindata>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
66
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
71
|
+
s.add_dependency(%q<roodi>, ["~> 2.1.0"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<bindata>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
76
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
77
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
79
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
80
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
81
|
+
s.add_dependency(%q<roodi>, ["~> 2.1.0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
data/spec/data/lwes.bin
ADDED
Binary file
|
data/spec/lwes_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Lwes do
|
4
|
+
describe "Helpers" do
|
5
|
+
include Lwes::Helpers
|
6
|
+
it "should camelcase" do
|
7
|
+
camelcase("camel_case_it").should == "CamelCaseIt"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Event" do
|
12
|
+
before :each do
|
13
|
+
@event_attr = {:name =>"event1", :attributes => {
|
14
|
+
"att0" => [:attr_str, "test123"],
|
15
|
+
"att1" => [:uint16, 1],
|
16
|
+
"att2" => [:ip_v4_array, ["1.2.3.4", "0.0.0.0", "1.0.0.255"]]
|
17
|
+
}}
|
18
|
+
@binary = "\006event1\000\003\004att0\005\000\atest123\004att1\001\000\001\004att2\215\000\003\004\003\002\001\000\000\000\000\377\000\000\001"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should write to io" do
|
22
|
+
io = StringIO.new
|
23
|
+
event = Lwes::Event.new(@event_attr)
|
24
|
+
event.write(io)
|
25
|
+
io.rewind
|
26
|
+
io.read.should == @binary
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should read from io" do
|
30
|
+
io = StringIO.new(@binary)
|
31
|
+
event = Lwes::Event.read(io)
|
32
|
+
event.name.should == @event_attr[:name]
|
33
|
+
event.attributes.should == @event_attr[:attributes]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should convert to hash" do
|
37
|
+
event = Lwes::Event.new(@event_attr)
|
38
|
+
event.to_hash.should == @event_attr
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "Emitter" do
|
43
|
+
before :each do
|
44
|
+
@emitter_options = {
|
45
|
+
:address_family => "fake address family",
|
46
|
+
:host => "fake address",
|
47
|
+
:port => "fake port"
|
48
|
+
}
|
49
|
+
@mock_socket = mock("socket")
|
50
|
+
UDPSocket.should_receive(:new).with("fake address family").and_return(@mock_socket)
|
51
|
+
@mock_socket.should_receive(:connect).with("fake address", "fake port")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should initialize udp socket on instanitation" do
|
55
|
+
Lwes::Emitter.new @emitter_options
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should write to udp socket when emitting event" do
|
59
|
+
binary = "\006event1\000\003\004att0\005\000\atest123\004att1\001\000\001\004att2\215\000\003\004\003\002\001\000\000\000\000\377\000\000\001"
|
60
|
+
@mock_socket.should_receive(:write).with(binary)
|
61
|
+
|
62
|
+
emitter = Lwes::Emitter.new @emitter_options
|
63
|
+
event = Lwes::Event.new({:name =>"event1", :attributes => {
|
64
|
+
"att0" => [:attr_str, "test123"],
|
65
|
+
"att1" => [:uint16, 1],
|
66
|
+
"att2" => [:ip_v4_array, ["1.2.3.4", "0.0.0.0", "1.0.0.255"]]
|
67
|
+
}})
|
68
|
+
|
69
|
+
emitter.emit event
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'Lwes' do
|
4
|
+
describe'Serialization' do
|
5
|
+
shared_examples_for 'all serializers' do
|
6
|
+
it "should parse" do
|
7
|
+
@bin_strs.each_with_index do |io, i|
|
8
|
+
@klass.read(io).should == @values[i]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should serialize" do
|
13
|
+
@values.each_with_index do |v, i|
|
14
|
+
@klass.new(v).to_binary_s.should == @bin_strs[i]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Boolean' do
|
20
|
+
before :each do
|
21
|
+
@klass = Lwes::Serialization::Boolean
|
22
|
+
@values = [true, false]
|
23
|
+
@bin_strs = ["\001", "\000"]
|
24
|
+
end
|
25
|
+
it_should_behave_like "all serializers"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'NameStr' do
|
29
|
+
before :each do
|
30
|
+
@klass = Lwes::Serialization::NameStr
|
31
|
+
@values = ["test", "test2", "another test", ""]
|
32
|
+
@bin_strs = ["\004test", "\005test2", "\014another test", "\000"]
|
33
|
+
end
|
34
|
+
it_should_behave_like "all serializers"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'AttrStr' do
|
38
|
+
before :each do
|
39
|
+
@klass = Lwes::Serialization::AttrStr
|
40
|
+
@values = ["test", "test2", "another test", ""]
|
41
|
+
@bin_strs = ["\000\004test", "\000\005test2", "\000\014another test", "\000\000"]
|
42
|
+
end
|
43
|
+
it_should_behave_like "all serializers"
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'IpAddr' do
|
47
|
+
before :each do
|
48
|
+
@klass = Lwes::Serialization::IpAddr
|
49
|
+
@values = ["1.2.3.4", "0.0.0.0", "1.0.0.255"]
|
50
|
+
@bin_strs = ["\001\002\003\004", "\000\000\000\000", "\001\000\000\377"]
|
51
|
+
end
|
52
|
+
it_should_behave_like "all serializers"
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'IpV4' do
|
56
|
+
before :each do
|
57
|
+
@klass = Lwes::Serialization::IpV4
|
58
|
+
@values = ["1.2.3.4", "0.0.0.0", "1.0.0.255"]
|
59
|
+
@bin_strs = ["\004\003\002\001", "\000\000\000\000", "\377\000\000\001"]
|
60
|
+
end
|
61
|
+
it_should_behave_like "all serializers"
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'IpV4' do
|
65
|
+
before :each do
|
66
|
+
@klass = Lwes::Serialization::IpV4
|
67
|
+
@values = ["1.2.3.4", "0.0.0.0", "1.0.0.255"]
|
68
|
+
@bin_strs = ["\004\003\002\001", "\000\000\000\000", "\377\000\000\001"]
|
69
|
+
end
|
70
|
+
it_should_behave_like "all serializers"
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'Uint16Array' do
|
74
|
+
before :each do
|
75
|
+
@klass = Lwes::Serialization::Uint16Array
|
76
|
+
@values = [[1,2,3], [2,2,2,2], [1], []]
|
77
|
+
@bin_strs = [
|
78
|
+
"\000\003\000\001\000\002\000\003",
|
79
|
+
"\000\004\000\002\000\002\000\002\000\002",
|
80
|
+
"\000\001\000\001",
|
81
|
+
"\000\000"
|
82
|
+
]
|
83
|
+
end
|
84
|
+
it_should_behave_like "all serializers"
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'Int16Array' do
|
88
|
+
before :each do
|
89
|
+
@klass = Lwes::Serialization::Int16Array
|
90
|
+
@values = [[-1,2,3], [2,2,-2,2], [1], []]
|
91
|
+
@bin_strs = [
|
92
|
+
"\000\003\377\377\000\002\000\003",
|
93
|
+
"\000\004\000\002\000\002\377\376\000\002",
|
94
|
+
"\000\001\000\001",
|
95
|
+
"\000\000"
|
96
|
+
]
|
97
|
+
end
|
98
|
+
it_should_behave_like "all serializers"
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'Uint32Array' do
|
102
|
+
before :each do
|
103
|
+
@klass = Lwes::Serialization::Uint32Array
|
104
|
+
@values = [[1,2,3], [2,2,2,2], [1], []]
|
105
|
+
@bin_strs = [
|
106
|
+
"\000\003\000\000\000\001\000\000\000\002\000\000\000\003",
|
107
|
+
"\000\004\000\000\000\002\000\000\000\002\000\000\000\002\000\000\000\002",
|
108
|
+
"\000\001\000\000\000\001",
|
109
|
+
"\000\000"
|
110
|
+
]
|
111
|
+
end
|
112
|
+
it_should_behave_like "all serializers"
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'Int32Array' do
|
116
|
+
before :each do
|
117
|
+
@klass = Lwes::Serialization::Int32Array
|
118
|
+
@values = [[1,-2,3], [2,2,2,-2], [-1], []]
|
119
|
+
@bin_strs = [
|
120
|
+
"\000\003\000\000\000\001\377\377\377\376\000\000\000\003",
|
121
|
+
"\000\004\000\000\000\002\000\000\000\002\000\000\000\002\377\377\377\376",
|
122
|
+
"\000\001\377\377\377\377",
|
123
|
+
"\000\000"
|
124
|
+
]
|
125
|
+
end
|
126
|
+
it_should_behave_like "all serializers"
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'AttrStrArray' do
|
130
|
+
before :each do
|
131
|
+
@klass = Lwes::Serialization::AttrStrArray
|
132
|
+
@values = [["test", "test2", "test3"], ["", "", ""], []]
|
133
|
+
@bin_strs = [
|
134
|
+
"\000\003\000\004test\000\005test2\000\005test3",
|
135
|
+
"\000\003\000\000\000\000\000\000",
|
136
|
+
"\000\000"
|
137
|
+
]
|
138
|
+
end
|
139
|
+
it_should_behave_like "all serializers"
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'IpAddrArray' do
|
143
|
+
before :each do
|
144
|
+
@klass = Lwes::Serialization::IpAddrArray
|
145
|
+
@values = [["1.2.3.4", "0.0.0.0", "1.0.0.255"], []]
|
146
|
+
@bin_strs = [
|
147
|
+
"\000\003\001\002\003\004\000\000\000\000\001\000\000\377",
|
148
|
+
"\000\000"
|
149
|
+
]
|
150
|
+
end
|
151
|
+
it_should_behave_like "all serializers"
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'Int64Array' do
|
155
|
+
before :each do
|
156
|
+
@klass = Lwes::Serialization::Int64Array
|
157
|
+
@values = [[1,2,-3,4],[]]
|
158
|
+
@bin_strs = [
|
159
|
+
"\000\004\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\002\377\377\377\377\377\377\377\375\000\000\000\000\000\000\000\004",
|
160
|
+
"\000\000"
|
161
|
+
]
|
162
|
+
end
|
163
|
+
it_should_behave_like "all serializers"
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'Uint64Array' do
|
167
|
+
before :each do
|
168
|
+
@klass = Lwes::Serialization::Int64Array
|
169
|
+
@values = [[1,2,3,4],[]]
|
170
|
+
@bin_strs = [
|
171
|
+
"\000\004\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000\004",
|
172
|
+
"\000\000"
|
173
|
+
]
|
174
|
+
end
|
175
|
+
it_should_behave_like "all serializers"
|
176
|
+
end
|
177
|
+
|
178
|
+
describe 'BooleanArray' do
|
179
|
+
before :each do
|
180
|
+
@klass = Lwes::Serialization::BooleanArray
|
181
|
+
@values = [[false],[]]
|
182
|
+
@bin_strs = [
|
183
|
+
"\000\001\000",
|
184
|
+
"\000\000"
|
185
|
+
]
|
186
|
+
end
|
187
|
+
it_should_behave_like "all serializers"
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'Uint8Array' do
|
191
|
+
before :each do
|
192
|
+
@klass = Lwes::Serialization::Uint8Array
|
193
|
+
@values = [[1,2, 255],[]]
|
194
|
+
@bin_strs = [
|
195
|
+
"\000\003\001\002\377",
|
196
|
+
"\000\000"
|
197
|
+
]
|
198
|
+
end
|
199
|
+
it_should_behave_like "all serializers"
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'FloatArray' do
|
203
|
+
before :each do
|
204
|
+
@klass = Lwes::Serialization::FloatArray
|
205
|
+
@values = [[2.0, 1.0],[]]
|
206
|
+
@bin_strs = [
|
207
|
+
"\000\002\100\000\000\000\077\200\000\000",
|
208
|
+
"\000\000"
|
209
|
+
]
|
210
|
+
end
|
211
|
+
it_should_behave_like "all serializers"
|
212
|
+
end
|
213
|
+
|
214
|
+
describe 'DoubleArray' do
|
215
|
+
before :each do
|
216
|
+
@klass = Lwes::Serialization::DoubleArray
|
217
|
+
@values = [[0.1, 1.0],[]]
|
218
|
+
@bin_strs = [
|
219
|
+
"\000\002\077\271\231\231\231\231\231\232\077\360\000\000\000\000\000\000",
|
220
|
+
"\000\000"
|
221
|
+
]
|
222
|
+
end
|
223
|
+
it_should_behave_like "all serializers"
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'IpV4Array' do
|
227
|
+
before :each do
|
228
|
+
@klass = Lwes::Serialization::IpV4Array
|
229
|
+
@values = [["1.2.3.4", "0.0.0.0", "1.0.0.255"], []]
|
230
|
+
@bin_strs = [
|
231
|
+
"\000\003\004\003\002\001\000\000\000\000\377\000\000\001",
|
232
|
+
"\000\000"
|
233
|
+
]
|
234
|
+
end
|
235
|
+
it_should_behave_like "all serializers"
|
236
|
+
end
|
237
|
+
|
238
|
+
describe 'Attribute' do
|
239
|
+
before :each do
|
240
|
+
@klass = Lwes::Serialization::Attribute
|
241
|
+
@values = [
|
242
|
+
["att0", :attr_str, "test123"],
|
243
|
+
["att1", :uint16, 1],
|
244
|
+
["att2", :ip_v4_array, ["1.2.3.4", "0.0.0.0", "1.0.0.255"]]
|
245
|
+
]
|
246
|
+
@bin_strs = [
|
247
|
+
"\004att0\005\000\007test123",
|
248
|
+
"\004att1\001\000\001",
|
249
|
+
"\004att2\215\000\003\004\003\002\001\000\000\000\000\377\000\000\001"
|
250
|
+
]
|
251
|
+
end
|
252
|
+
it_should_behave_like "all serializers"
|
253
|
+
end
|
254
|
+
|
255
|
+
describe 'AttributeArray' do
|
256
|
+
before :each do
|
257
|
+
@klass = Lwes::Serialization::AttributeArray
|
258
|
+
@values = [
|
259
|
+
[
|
260
|
+
["att0", :attr_str, "test123"],
|
261
|
+
["att1", :uint16, 1],
|
262
|
+
["att2", :ip_v4_array, ["1.2.3.4", "0.0.0.0", "1.0.0.255"]]
|
263
|
+
],
|
264
|
+
[
|
265
|
+
]
|
266
|
+
]
|
267
|
+
@bin_strs = [
|
268
|
+
"\000\003\004att0\005\000\007test123\004att1\001\000\001\004att2\215\000\003\004\003\002\001\000\000\000\000\377\000\000\001",
|
269
|
+
"\000\000"
|
270
|
+
]
|
271
|
+
end
|
272
|
+
it_should_behave_like "all serializers"
|
273
|
+
end
|
274
|
+
|
275
|
+
describe 'Event' do
|
276
|
+
before :each do
|
277
|
+
@klass = Lwes::Serialization::Event
|
278
|
+
@values = [
|
279
|
+
{'name' =>"event1", 'attributes' => [
|
280
|
+
["att0", :attr_str, "test123"],
|
281
|
+
["att1", :uint16, 1],
|
282
|
+
["att2", :ip_v4_array, ["1.2.3.4", "0.0.0.0", "1.0.0.255"]]
|
283
|
+
]}
|
284
|
+
]
|
285
|
+
@bin_strs = [
|
286
|
+
"\006event1\000\003\004att0\005\000\007test123\004att1\001\000\001\004att2\215\000\003\004\003\002\001\000\000\000\000\377\000\000\001"
|
287
|
+
]
|
288
|
+
end
|
289
|
+
it_should_behave_like "all serializers"
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'lwes'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lwes_pure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Aaron Qian
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-21 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
name: bindata
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
type: :development
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 3
|
47
|
+
- 0
|
48
|
+
version: 2.3.0
|
49
|
+
name: rspec
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
prerelease: false
|
53
|
+
type: :development
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 6
|
63
|
+
- 0
|
64
|
+
version: 0.6.0
|
65
|
+
name: yard
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 23
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 0
|
79
|
+
- 0
|
80
|
+
version: 1.0.0
|
81
|
+
name: bundler
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 7
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 5
|
95
|
+
- 2
|
96
|
+
version: 1.5.2
|
97
|
+
name: jeweler
|
98
|
+
version_requirements: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
prerelease: false
|
101
|
+
type: :development
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
name: rcov
|
112
|
+
version_requirements: *id006
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
prerelease: false
|
115
|
+
type: :development
|
116
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 15
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 2
|
125
|
+
- 8
|
126
|
+
version: 1.2.8
|
127
|
+
name: reek
|
128
|
+
version_requirements: *id007
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
prerelease: false
|
131
|
+
type: :development
|
132
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ~>
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 11
|
138
|
+
segments:
|
139
|
+
- 2
|
140
|
+
- 1
|
141
|
+
- 0
|
142
|
+
version: 2.1.0
|
143
|
+
name: roodi
|
144
|
+
version_requirements: *id008
|
145
|
+
description: The original lwes gem is a thin wrapper around the c library, and does not handle data types for dynamic LWES events. This gem allows users to define the data type of attributes in an clear way, so that your LWES event listeners will be happy. This library includes the following components.
|
146
|
+
email: aqian@attinteractive.com
|
147
|
+
executables: []
|
148
|
+
|
149
|
+
extensions: []
|
150
|
+
|
151
|
+
extra_rdoc_files:
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.rdoc
|
154
|
+
files:
|
155
|
+
- .document
|
156
|
+
- .rspec
|
157
|
+
- Gemfile
|
158
|
+
- Gemfile.lock
|
159
|
+
- LICENSE.txt
|
160
|
+
- README.rdoc
|
161
|
+
- Rakefile
|
162
|
+
- VERSION
|
163
|
+
- lib/lwes.rb
|
164
|
+
- lib/lwes/emitter.rb
|
165
|
+
- lib/lwes/event.rb
|
166
|
+
- lib/lwes/helpers.rb
|
167
|
+
- lib/lwes/serialization.rb
|
168
|
+
- lib/lwes/types.rb
|
169
|
+
- lwes_pure.gemspec
|
170
|
+
- spec/data/lwes.bin
|
171
|
+
- spec/lwes_spec.rb
|
172
|
+
- spec/serialiation_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
174
|
+
has_rdoc: true
|
175
|
+
homepage: http://github.com/aq1018/lwes_pure
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
hash: 3
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
version: "0"
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
hash: 3
|
198
|
+
segments:
|
199
|
+
- 0
|
200
|
+
version: "0"
|
201
|
+
requirements: []
|
202
|
+
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 1.6.2
|
205
|
+
signing_key:
|
206
|
+
specification_version: 3
|
207
|
+
summary: LWES - Light Weight Event System protocol implemented in pure ruby.
|
208
|
+
test_files:
|
209
|
+
- spec/lwes_spec.rb
|
210
|
+
- spec/serialiation_spec.rb
|
211
|
+
- spec/spec_helper.rb
|