blob: 0f0cfa82e7d294958631730b9f7070c20af4af7d [file] [log] [blame]
Kevin Clark4bd89162008-07-08 00:47:49 +00001require 'thrift'
2
3module Fixtures
4 module Structs
5 class OneBool
6 include Thrift::Struct
7 attr_accessor :bool
8 FIELDS = {
9 1 => {:type => Thrift::Types::BOOL, :name => 'bool'}
10 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000011
12 def validate
13 end
Kevin Clark4bd89162008-07-08 00:47:49 +000014 end
15
16 class OneByte
17 include Thrift::Struct
18 attr_accessor :byte
19 FIELDS = {
20 1 => {:type => Thrift::Types::BYTE, :name => 'byte'}
21 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000022
23 def validate
24 end
Kevin Clark4bd89162008-07-08 00:47:49 +000025 end
26
27 class OneI16
28 include Thrift::Struct
29 attr_accessor :i16
30 FIELDS = {
31 1 => {:type => Thrift::Types::I16, :name => 'i16'}
32 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000033
34 def validate
35 end
Kevin Clark4bd89162008-07-08 00:47:49 +000036 end
37
38 class OneI32
39 include Thrift::Struct
40 attr_accessor :i32
41 FIELDS = {
42 1 => {:type => Thrift::Types::I32, :name => 'i32'}
43 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000044
45 def validate
46 end
Kevin Clark4bd89162008-07-08 00:47:49 +000047 end
48
49 class OneI64
50 include Thrift::Struct
51 attr_accessor :i64
52 FIELDS = {
53 1 => {:type => Thrift::Types::I64, :name => 'i64'}
54 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000055
56 def validate
57 end
Kevin Clark4bd89162008-07-08 00:47:49 +000058 end
59
60 class OneDouble
61 include Thrift::Struct
62 attr_accessor :double
63 FIELDS = {
64 1 => {:type => Thrift::Types::DOUBLE, :name => 'double'}
65 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000066
67 def validate
68 end
Kevin Clark4bd89162008-07-08 00:47:49 +000069 end
70
71 class OneString
72 include Thrift::Struct
73 attr_accessor :string
74 FIELDS = {
75 1 => {:type => Thrift::Types::STRING, :name => 'string'}
76 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000077
78 def validate
79 end
Kevin Clark4bd89162008-07-08 00:47:49 +000080 end
81
82 class OneMap
83 include Thrift::Struct
84 attr_accessor :map
85 FIELDS = {
86 1 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRING}}
87 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000088
89 def validate
90 end
Kevin Clark4bd89162008-07-08 00:47:49 +000091 end
92
93 class NestedMap
94 include Thrift::Struct
95 attr_accessor :map
96 FIELDS = {
97 0 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::I32}}}
98 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000099
100 def validate
101 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000102 end
103
104 class OneList
105 include Thrift::Struct
106 attr_accessor :list
107 FIELDS = {
108 1 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::STRING}}
109 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000110
111 def validate
112 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000113 end
114
115 class NestedList
116 include Thrift::Struct
117 attr_accessor :list
118 FIELDS = {
119 0 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::LIST, :element => { :type => Thrift::Types::I32 } } }
120 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000121
122 def validate
123 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000124 end
125
126 class OneSet
127 include Thrift::Struct
128 attr_accessor :set
129 FIELDS = {
130 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::STRING}}
131 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000132
133 def validate
134 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000135 end
136
137 class NestedSet
138 include Thrift::Struct
139 attr_accessor :set
140 FIELDS = {
141 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::SET, :element => { :type => Thrift::Types::STRING } }}
142 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000143
144 def validate
145 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000146 end
147
148 # struct OneOfEach {
149 # 1: bool im_true,
150 # 2: bool im_false,
151 # 3: byte a_bite,
152 # 4: i16 integer16,
153 # 5: i32 integer32,
154 # 6: i64 integer64,
155 # 7: double double_precision,
156 # 8: string some_characters,
157 # 9: string zomg_unicode,
158 # 10: bool what_who,
159 # 11: binary base64,
160 # }
161 class OneOfEach
162 include Thrift::Struct
163 attr_accessor :im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64
164 FIELDS = {
165 1 => {:type => Thrift::Types::BOOL, :name => 'im_true'},
166 2 => {:type => Thrift::Types::BOOL, :name => 'im_false'},
167 3 => {:type => Thrift::Types::BYTE, :name => 'a_bite'},
168 4 => {:type => Thrift::Types::I16, :name => 'integer16'},
169 5 => {:type => Thrift::Types::I32, :name => 'integer32'},
170 6 => {:type => Thrift::Types::I64, :name => 'integer64'},
171 7 => {:type => Thrift::Types::DOUBLE, :name => 'double_precision'},
172 8 => {:type => Thrift::Types::STRING, :name => 'some_characters'},
173 9 => {:type => Thrift::Types::STRING, :name => 'zomg_unicode'},
174 10 => {:type => Thrift::Types::BOOL, :name => 'what_who'},
175 11 => {:type => Thrift::Types::STRING, :name => 'base64'}
176 }
177
178 # Added for assert_equal
179 def ==(other)
180 [:im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64].each do |f|
181 var = "@#{f}"
182 return false if instance_variable_get(var) != other.instance_variable_get(var)
183 end
184 true
185 end
Kevin Clarkc85fd502009-01-14 23:55:10 +0000186
187 def validate
188 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000189 end
190
191 # struct Nested1 {
192 # 1: list<OneOfEach> a_list
193 # 2: map<i32, OneOfEach> i32_map
194 # 3: map<i64, OneOfEach> i64_map
195 # 4: map<double, OneOfEach> dbl_map
196 # 5: map<string, OneOfEach> str_map
197 # }
198 class Nested1
199 include Thrift::Struct
200 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
201 FIELDS = {
202 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
203 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
204 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
205 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
206 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}
207 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000208
209 def validate
210 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000211 end
212
213 # struct Nested2 {
214 # 1: list<Nested1> a_list
215 # 2: map<i32, Nested1> i32_map
216 # 3: map<i64, Nested1> i64_map
217 # 4: map<double, Nested1> dbl_map
218 # 5: map<string, Nested1> str_map
219 # }
220 class Nested2
221 include Thrift::Struct
222 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
223 FIELDS = {
224 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested1}},
225 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}},
226 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}},
227 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}},
228 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}
229 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000230
231 def validate
232 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000233 end
234
235 # struct Nested3 {
236 # 1: list<Nested2> a_list
237 # 2: map<i32, Nested2> i32_map
238 # 3: map<i64, Nested2> i64_map
239 # 4: map<double, Nested2> dbl_map
240 # 5: map<string, Nested2> str_map
241 # }
242 class Nested3
243 include Thrift::Struct
244 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
245 FIELDS = {
246 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested2}},
247 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}},
248 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}},
249 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}},
250 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}
251 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000252
253 def validate
254 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000255 end
256
257 # struct Nested4 {
258 # 1: list<Nested3> a_list
259 # 2: map<i32, Nested3> i32_map
260 # 3: map<i64, Nested3> i64_map
261 # 4: map<double, Nested3> dbl_map
262 # 5: map<string, Nested3> str_map
263 # }
264 class Nested4
265 include Thrift::Struct
266 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
267 FIELDS = {
268 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested3}},
269 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}},
270 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}},
271 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}},
272 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}
273 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000274
275 def validate
276 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000277 end
278 end
279end