rb: Create constants for field ids in generated structs [THRIFT-165]
Author: Bryan Duxbury
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@705330 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/benchmark/gen-rb/BenchmarkService.rb b/lib/rb/benchmark/gen-rb/BenchmarkService.rb
index 42c8aec..7d39882 100644
--- a/lib/rb/benchmark/gen-rb/BenchmarkService.rb
+++ b/lib/rb/benchmark/gen-rb/BenchmarkService.rb
@@ -46,17 +46,21 @@
class Fibonacci_args
include Thrift::Struct
+ N = 1
+
Thrift::Struct.field_accessor self, :n
FIELDS = {
- 1 => {:type => Thrift::Types::BYTE, :name => 'n'}
+ N => {:type => Thrift::Types::BYTE, :name => 'n'}
}
end
class Fibonacci_result
include Thrift::Struct
+ SUCCESS = 0
+
Thrift::Struct.field_accessor self, :success
FIELDS = {
- 0 => {:type => Thrift::Types::I32, :name => 'success'}
+ SUCCESS => {:type => Thrift::Types::I32, :name => 'success'}
}
end
diff --git a/lib/rb/spec/gen-rb/NonblockingService.rb b/lib/rb/spec/gen-rb/NonblockingService.rb
index 5893f74..ee5fae1 100644
--- a/lib/rb/spec/gen-rb/NonblockingService.rb
+++ b/lib/rb/spec/gen-rb/NonblockingService.rb
@@ -115,22 +115,27 @@
class Greeting_args
include Thrift::Struct
+ ENGLISH = 1
+
Thrift::Struct.field_accessor self, :english
FIELDS = {
- 1 => {:type => Thrift::Types::BOOL, :name => 'english'}
+ ENGLISH => {:type => Thrift::Types::BOOL, :name => 'english'}
}
end
class Greeting_result
include Thrift::Struct
+ SUCCESS = 0
+
Thrift::Struct.field_accessor self, :success
FIELDS = {
- 0 => {:type => Thrift::Types::STRUCT, :name => 'success', :class => Hello}
+ SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', :class => Hello}
}
end
class Block_args
include Thrift::Struct
+
FIELDS = {
}
@@ -138,22 +143,27 @@
class Block_result
include Thrift::Struct
+ SUCCESS = 0
+
Thrift::Struct.field_accessor self, :success
FIELDS = {
- 0 => {:type => Thrift::Types::BOOL, :name => 'success'}
+ SUCCESS => {:type => Thrift::Types::BOOL, :name => 'success'}
}
end
class Unblock_args
include Thrift::Struct
+ N = 1
+
Thrift::Struct.field_accessor self, :n
FIELDS = {
- 1 => {:type => Thrift::Types::I32, :name => 'n'}
+ N => {:type => Thrift::Types::I32, :name => 'n'}
}
end
class Unblock_result
include Thrift::Struct
+
FIELDS = {
}
@@ -161,6 +171,7 @@
class Shutdown_args
include Thrift::Struct
+
FIELDS = {
}
@@ -168,6 +179,7 @@
class Shutdown_result
include Thrift::Struct
+
FIELDS = {
}
@@ -175,14 +187,17 @@
class Sleep_args
include Thrift::Struct
+ SECONDS = 1
+
Thrift::Struct.field_accessor self, :seconds
FIELDS = {
- 1 => {:type => Thrift::Types::DOUBLE, :name => 'seconds'}
+ SECONDS => {:type => Thrift::Types::DOUBLE, :name => 'seconds'}
}
end
class Sleep_result
include Thrift::Struct
+
FIELDS = {
}
diff --git a/lib/rb/spec/gen-rb/ThriftSpec_types.rb b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
index d7ad600..0251524 100644
--- a/lib/rb/spec/gen-rb/ThriftSpec_types.rb
+++ b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
@@ -9,59 +9,83 @@
module SpecNamespace
class Hello
include Thrift::Struct
+ GREETING = 1
+
Thrift::Struct.field_accessor self, :greeting
FIELDS = {
- 1 => {:type => Thrift::Types::STRING, :name => 'greeting', :default => 'hello world'}
+ GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => 'hello world'}
}
end
class Foo
include Thrift::Struct
+ SIMPLE = 1
+ WORDS = 2
+ HELLO = 3
+ INTS = 4
+ COMPLEX = 5
+ SHORTS = 6
+ OPT_STRING = 7
+
Thrift::Struct.field_accessor self, :simple, :words, :hello, :ints, :complex, :shorts, :opt_string
FIELDS = {
- 1 => {:type => Thrift::Types::I32, :name => 'simple', :default => 53},
- 2 => {:type => Thrift::Types::STRING, :name => 'words', :default => 'words'},
- 3 => {:type => Thrift::Types::STRUCT, :name => 'hello', :default => Hello.new({
+ SIMPLE => {:type => Thrift::Types::I32, :name => 'simple', :default => 53},
+ WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default => 'words'},
+ HELLO => {:type => Thrift::Types::STRUCT, :name => 'hello', :default => Hello.new({
'greeting' => 'hello, world!',
}), :class => Hello},
- 4 => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
+ INTS => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
1,
2,
2,
3,
], :element => {:type => Thrift::Types::I32}},
- 5 => {:type => Thrift::Types::MAP, :name => 'complex', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::DOUBLE}}},
- 6 => {:type => Thrift::Types::SET, :name => 'shorts', :default => Set.new([ 5,
+ COMPLEX => {:type => Thrift::Types::MAP, :name => 'complex', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::DOUBLE}}},
+ SHORTS => {:type => Thrift::Types::SET, :name => 'shorts', :default => Set.new([ 5,
17,
239,
]), :element => {:type => Thrift::Types::I16}},
- 7 => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
+ OPT_STRING => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
}
end
class BoolStruct
include Thrift::Struct
+ YESNO = 1
+
Thrift::Struct.field_accessor self, :yesno
FIELDS = {
- 1 => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
+ YESNO => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
}
end
class SimpleList
include Thrift::Struct
+ BOOLS = 1
+ BYTES = 2
+ I16S = 3
+ I32S = 4
+ I64S = 5
+ DOUBLES = 6
+ STRINGS = 7
+ MAPS = 8
+ LISTS = 9
+ SETS = 10
+ HELLOS = 11
+
Thrift::Struct.field_accessor self, :bools, :bytes, :i16s, :i32s, :i64s, :doubles, :strings, :maps, :lists, :sets, :hellos
FIELDS = {
- 1 => {:type => Thrift::Types::LIST, :name => 'bools', :element => {:type => Thrift::Types::BOOL}},
- 2 => {:type => Thrift::Types::LIST, :name => 'bytes', :element => {:type => Thrift::Types::BYTE}},
- 3 => {:type => Thrift::Types::LIST, :name => 'i16s', :element => {:type => Thrift::Types::I16}},
- 4 => {:type => Thrift::Types::LIST, :name => 'i32s', :element => {:type => Thrift::Types::I32}},
- 5 => {:type => Thrift::Types::LIST, :name => 'i64s', :element => {:type => Thrift::Types::I64}},
- 6 => {:type => Thrift::Types::LIST, :name => 'doubles', :element => {:type => Thrift::Types::DOUBLE}},
- 7 => {:type => Thrift::Types::LIST, :name => 'strings', :element => {:type => Thrift::Types::STRING}},
- 8 => {:type => Thrift::Types::LIST, :name => 'maps', :element => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => {:type => Thrift::Types::I16}}},
- 9 => {:type => Thrift::Types::LIST, :name => 'lists', :element => {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
- 10 => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
- 11 => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}}
+ BOOLS => {:type => Thrift::Types::LIST, :name => 'bools', :element => {:type => Thrift::Types::BOOL}},
+ BYTES => {:type => Thrift::Types::LIST, :name => 'bytes', :element => {:type => Thrift::Types::BYTE}},
+ I16S => {:type => Thrift::Types::LIST, :name => 'i16s', :element => {:type => Thrift::Types::I16}},
+ I32S => {:type => Thrift::Types::LIST, :name => 'i32s', :element => {:type => Thrift::Types::I32}},
+ I64S => {:type => Thrift::Types::LIST, :name => 'i64s', :element => {:type => Thrift::Types::I64}},
+ DOUBLES => {:type => Thrift::Types::LIST, :name => 'doubles', :element => {:type => Thrift::Types::DOUBLE}},
+ STRINGS => {:type => Thrift::Types::LIST, :name => 'strings', :element => {:type => Thrift::Types::STRING}},
+ MAPS => {:type => Thrift::Types::LIST, :name => 'maps', :element => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => {:type => Thrift::Types::I16}}},
+ LISTS => {:type => Thrift::Types::LIST, :name => 'lists', :element => {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
+ SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
+ HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}}
}
end