futurocube 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0db85c1e614f4be0889f66a3d31a57bcdcac83a7
4
+ data.tar.gz: 848407ce6ed8c34a287692de074ac4177ab4a38d
5
+ SHA512:
6
+ metadata.gz: 770c7d4393e7462ae84d745f25a3f01d002251256c34f6d8ab33838eaa7094eb74892848d7ae923e90fd817f4d0a5e0adca37cc6222b91968482163d6f7f543b
7
+ data.tar.gz: 56228bdd075aadb06a92a344d491efab75e40dd660a3355455f617fe57bb37a952343e08f282d04d8074e4d52388261a36e2bfc795c4c8ff15362d0bd5c98242
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Trejkaz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ futurocube (0.1.0)
5
+ bindata
6
+ progressbar
7
+ wavefile
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ bindata (1.6.0)
13
+ diff-lcs (1.2.4)
14
+ multi_json (1.8.1)
15
+ progressbar (0.21.0)
16
+ rake (0.9.6)
17
+ rspec (2.14.1)
18
+ rspec-core (~> 2.14.0)
19
+ rspec-expectations (~> 2.14.0)
20
+ rspec-mocks (~> 2.14.0)
21
+ rspec-core (2.14.5)
22
+ rspec-expectations (2.14.3)
23
+ diff-lcs (>= 1.1.3, < 2.0)
24
+ rspec-mocks (2.14.3)
25
+ simplecov (0.7.1)
26
+ multi_json (~> 1.0)
27
+ simplecov-html (~> 0.7.1)
28
+ simplecov-html (0.7.1)
29
+ wavefile (0.5.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.3)
36
+ futurocube!
37
+ rake
38
+ rspec
39
+ simplecov
@@ -0,0 +1,26 @@
1
+ # FuturoCube
2
+
3
+ [Rubik's Futuro Cube][1] is a neat toy made by Princip Interactive which basically embeds a
4
+ microprocessor in a cube covered with LEDs.
5
+
6
+ I started this project to mess with files which the SDK doesn't yet let you customise.
7
+
8
+ [1]: http://www.futurocube.com/
9
+
10
+ ## Installation
11
+
12
+ Install the gem:
13
+
14
+ $ gem install futurocube
15
+
16
+ ## Usage
17
+
18
+ TODO: Write usage instructions here
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'futurocube'
4
+
5
+ FuturoCube::ResourceTool.new.main(ARGV)
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'futurocube/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'futurocube'
8
+ spec.version = FuturoCube::VERSION
9
+ spec.authors = ['Trejkaz']
10
+ spec.email = ['trejkaz@trypticon.org']
11
+ spec.description = %q{Tools for messing with FuturoCube data}
12
+ spec.summary = %q{Contains tools and parsers for messing with data for the Rubik's FuturoCube.}
13
+ spec.homepage = 'https://github.com/trejkaz/futurocube'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = [ "COPYING.txt", "Gemfile", "Gemfile.lock", "README.md",
17
+ "Rakefile", "#{spec.name}.gemspec" ] +
18
+ Dir.glob("bin/*") +
19
+ Dir.glob("lib/**/*.rb") +
20
+ Dir.glob("spec/**/*.rb")
21
+
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'simplecov'
30
+
31
+ spec.add_runtime_dependency 'bindata'
32
+ spec.add_runtime_dependency 'wavefile'
33
+ spec.add_runtime_dependency 'progressbar'
34
+ end
@@ -0,0 +1,2 @@
1
+ require 'futurocube/version'
2
+ require 'futurocube/resource_tool'
@@ -0,0 +1,14 @@
1
+ require 'progressbar'
2
+
3
+ module FuturoCube
4
+ module CommandHelper
5
+ def with_progress(title, total, &block)
6
+ progress = ProgressBar.new(title, total)
7
+ begin
8
+ block.call(progress)
9
+ ensure
10
+ progress.finish
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ class CRC
2
+ def initialize
3
+ @table = make_table(0x04C11DB7)
4
+ reset
5
+ end
6
+
7
+ def reset
8
+ @crc = 0xFFFFFFFF
9
+ end
10
+
11
+ def update(input)
12
+ crc = @crc
13
+ table = @table
14
+
15
+ # Original algorithm does it little-endian then iterates from the high byte.
16
+ # I read it big-endian and then iterate from the low byte, saving some bit maths.
17
+ input.unpack('N*').each do |data|
18
+ 4.times do
19
+ table_index = (data & 0xFF) ^ (crc >> 24)
20
+ crc = (crc << 8) & 0xFFFFFFFF
21
+ crc = crc ^ table[table_index]
22
+ data >>= 8
23
+ end
24
+ end
25
+
26
+ @crc = crc
27
+ end
28
+
29
+ def crc
30
+ @crc
31
+ end
32
+
33
+ private
34
+
35
+ def make_table(poly)
36
+ (0..255).map do |n|
37
+ crc = n << 24
38
+ 8.times do
39
+ if crc & 0x80000000 != 0
40
+ crc = ((crc << 1) ^ poly) & 0xFFFFFFFF
41
+ else
42
+ crc <<= 1
43
+ end
44
+ end
45
+ (crc & 0xFFFFFFFF)
46
+ end
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,39 @@
1
+ require 'wavefile'
2
+
3
+ require_relative 'resource_file'
4
+ require_relative 'command_helper'
5
+
6
+ module FuturoCube
7
+ class DumpCommand
8
+ include CommandHelper
9
+
10
+ def exec(file, dir)
11
+ ResourceFile.open(file) do |rf|
12
+ with_progress('Dumping', rf.records.size) do |progress|
13
+ rf.records.each do |rec|
14
+ data = rf.data(rec)
15
+
16
+ f = File.join(dir, "#{rec.name}.wav")
17
+ format = WaveFile::Format.new(:mono, :pcm_16, 22050)
18
+ WaveFile::Writer.new(f, format) do |writer|
19
+ #TODO: is there a way to write a buffer directly?
20
+ samples = data.unpack("S<*")
21
+ buffer = WaveFile::Buffer.new(samples, format)
22
+ writer.write(buffer)
23
+ end
24
+
25
+ progress.inc
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def args_valid?(args)
32
+ args.length == 2
33
+ end
34
+
35
+ def usage
36
+ "filename directory"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'resource_file'
2
+
3
+ module FuturoCube
4
+ class ListCommand
5
+ def exec(file)
6
+ ResourceFile.open(file) do |rf|
7
+ rf.records.each do |rec|
8
+ puts "#{rec.name.ljust(20)} #{rec.data_length.to_s.rjust(10)}"
9
+ end
10
+ end
11
+ end
12
+
13
+ def args_valid?(args)
14
+ args.length == 1
15
+ end
16
+
17
+ def usage
18
+ "filename"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,103 @@
1
+ require 'bindata'
2
+
3
+ require_relative 'crc'
4
+
5
+ module FuturoCube
6
+ class ResourceFile
7
+ class FileHeader < BinData::Record
8
+ endian :little
9
+ uint32 :magic
10
+ uint32 :checksum
11
+ uint32 :version
12
+ uint32 :created
13
+ string :name, :length => 20, :trim_padding => true
14
+ uint32 :record_count
15
+ uint32 :file_size
16
+ end
17
+
18
+ class ResourceRecord < BinData::Record
19
+ endian :little
20
+ string :name, :length => 20, :trim_padding => true
21
+ uint32 :format
22
+ uint32 :data_offset
23
+ uint32 :data_length
24
+ end
25
+
26
+ attr_reader :header, :records
27
+
28
+ def initialize(io)
29
+ @io = io
30
+ end
31
+
32
+ # Reads the header from the resource file.
33
+ def header
34
+ if !@header
35
+ @io.seek(0, IO::SEEK_SET)
36
+ @header = FileHeader.read(@io)
37
+ end
38
+ @header
39
+ end
40
+
41
+ # Reads the list of records from the resource file.
42
+ def records
43
+ if !@records
44
+ @io.seek(44, IO::SEEK_SET)
45
+ records = []
46
+ header.record_count.times do
47
+ records << ResourceRecord.read(@io)
48
+ end
49
+ @records = records
50
+ end
51
+ @records
52
+ end
53
+
54
+ # Reads the data for a given record.
55
+ #
56
+ # @param rec [ResourceRecord] the record to read the data for.
57
+ def data(rec)
58
+ @io.seek(rec.data_offset, IO::SEEK_SET)
59
+ @io.read(rec.data_length)
60
+ end
61
+
62
+ # Computes the checksum for the resource file.
63
+ #
64
+ # @yield [done] Provides feedback about the progress of the operation.
65
+ def compute_checksum(&block)
66
+ crc = CRC.new
67
+ # Have to read this first because it might change the seek position.
68
+ file_size = header.file_size
69
+ @io.seek(8, IO::SEEK_SET)
70
+ pos = 8
71
+ length = 4096-8
72
+ buf = nil
73
+ while true
74
+ buf = @io.read(length, buf)
75
+ break if !buf
76
+ crc.update(buf)
77
+ pos += buf.size
78
+ block.call(pos) if block
79
+ length = 4096
80
+ end
81
+ crc.crc
82
+ end
83
+
84
+ def self.open(file, &block)
85
+ if block
86
+ File.open(file, File::RDONLY) do |io|
87
+ rf = ResourceFile.new(io)
88
+ begin
89
+ block.call(rf)
90
+ ensure
91
+ rf.close
92
+ end
93
+ end
94
+ else
95
+ ResourceFile.new(File.open(file, File::RDONLY))
96
+ end
97
+ end
98
+
99
+ def close
100
+ @io.close
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,38 @@
1
+
2
+ require_relative 'list_command'
3
+ require_relative 'verify_command'
4
+ require_relative 'dump_command'
5
+
6
+ module FuturoCube
7
+ class ResourceTool
8
+ COMMANDS = {
9
+ 'list' => ListCommand.new,
10
+ 'verify' => VerifyCommand.new,
11
+ 'dump' => DumpCommand.new
12
+ }
13
+
14
+ def usage(exit_code = 1)
15
+ $stderr.puts("Usage:")
16
+ COMMANDS.each_pair do |name, command|
17
+ $stderr.puts(" #{$0} #{name} #{command.usage}")
18
+ end
19
+ exit exit_code
20
+ end
21
+
22
+ def main(args)
23
+ usage if args.length < 1
24
+ usage(0) if args[0] == '--help'
25
+
26
+ command = COMMANDS[args[0]]
27
+ usage if !command
28
+
29
+ command_args = args.slice(1..-1)
30
+ usage if !command.args_valid?(command_args)
31
+ begin
32
+ command.exec(*command_args)
33
+ rescue Interrupt => e
34
+ $stderr.puts("Interrupted")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'resource_file'
2
+ require_relative 'command_helper'
3
+
4
+ module FuturoCube
5
+ class VerifyCommand
6
+ include CommandHelper
7
+
8
+ def exec(file)
9
+ ResourceFile.open(file) do |rf|
10
+ expected = rf.header.checksum
11
+ actual = with_progress('Checking', rf.header.file_size) do |progress|
12
+ rf.compute_checksum do |done|
13
+ progress.set(done)
14
+ end
15
+ end
16
+
17
+ if actual == expected
18
+ puts " Checksum %08X OK" % [actual]
19
+ else
20
+ puts " Checksum %08X NG (expected %08X)" % [actual, expected]
21
+ end
22
+ end
23
+ end
24
+
25
+ def args_valid?(args)
26
+ args.length == 1
27
+ end
28
+
29
+ def usage
30
+ "filename"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module FuturoCube
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,107 @@
1
+ require_relative '../spec_helper'
2
+ require 'futurocube/resource_file'
3
+
4
+ describe FuturoCube::ResourceFile do
5
+ before do
6
+ @rf = FuturoCube::ResourceFile.open('FutRes031212.bin')
7
+ end
8
+
9
+ after do
10
+ @rf.close
11
+ end
12
+
13
+ describe '::open' do
14
+ it 'yields the ResourceFile to the block' do
15
+ FuturoCube::ResourceFile.open('FutRes031212.bin') do |rf|
16
+ rf.should be_a FuturoCube::ResourceFile
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#header' do
22
+ describe '#magic' do
23
+ it 'returns the magic number' do
24
+ @rf.header.magic.should == 0xAA987745
25
+ end
26
+ end
27
+
28
+ describe '#checksum' do
29
+ it 'returns the file checksum' do
30
+ @rf.header.checksum.should == 0x35D806F6
31
+ end
32
+ end
33
+
34
+ describe '#version' do
35
+ it 'returns the file format version' do
36
+ @rf.header.version.should == 2
37
+ end
38
+ end
39
+
40
+ describe '#created' do
41
+ it 'returns the file creation date' do
42
+ @rf.header.created.should == 1354536121
43
+ end
44
+ end
45
+
46
+ describe '#name' do
47
+ it 'returns the resource bundle name' do
48
+ @rf.header.name.should == 'FutRes031212'
49
+ end
50
+ end
51
+
52
+ describe '#record_count' do
53
+ it 'returns the record count' do
54
+ @rf.header.record_count.should == 274
55
+ end
56
+ end
57
+
58
+ describe '#file_size' do
59
+ it 'returns the file size' do
60
+ @rf.header.file_size.should == 98828288
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#records' do
66
+ it 'returns one element for each record in the file' do
67
+ @rf.records.size.should == 274
68
+ end
69
+
70
+ describe '#name' do
71
+ it 'returns the name of the record' do
72
+ @rf.records[0].name.should == '1'
73
+ end
74
+ end
75
+
76
+ describe '#format' do
77
+ it 'returns a format version number' do
78
+ @rf.records[0].format.should == 1
79
+ end
80
+ end
81
+
82
+ describe '#data_offset' do
83
+ it 'returns the data offset' do
84
+ @rf.records[0].data_offset.should == 10240
85
+ end
86
+ end
87
+
88
+ describe '#data_length' do
89
+ it 'returns the data length' do
90
+ @rf.records[0].data_length.should == 29184
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#data' do
96
+ it 'returns the data for the record' do
97
+ @rf.data(@rf.records[0]).size.should == 29184
98
+ end
99
+ end
100
+
101
+ describe '#compute_checksum' do
102
+ it 'computes the checksum for the file' do
103
+ @rf.compute_checksum.should == @rf.header.checksum
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.setup
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: futurocube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Trejkaz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bindata
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: wavefile
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: progressbar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Tools for messing with FuturoCube data
112
+ email:
113
+ - trejkaz@trypticon.org
114
+ executables:
115
+ - fcrestool
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - COPYING.txt
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - README.md
123
+ - Rakefile
124
+ - futurocube.gemspec
125
+ - bin/fcrestool
126
+ - lib/futurocube/command_helper.rb
127
+ - lib/futurocube/crc.rb
128
+ - lib/futurocube/dump_command.rb
129
+ - lib/futurocube/list_command.rb
130
+ - lib/futurocube/resource_file.rb
131
+ - lib/futurocube/resource_tool.rb
132
+ - lib/futurocube/verify_command.rb
133
+ - lib/futurocube/version.rb
134
+ - lib/futurocube.rb
135
+ - spec/futurocube/resource_file_spec.rb
136
+ - spec/spec_helper.rb
137
+ homepage: https://github.com/trejkaz/futurocube
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.0.3
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Contains tools and parsers for messing with data for the Rubik's FuturoCube.
161
+ test_files:
162
+ - spec/futurocube/resource_file_spec.rb
163
+ - spec/spec_helper.rb