Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 1 | require 'thrift' |
| 2 | |
| 3 | module 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 | } |
| 11 | end |
| 12 | |
| 13 | class OneByte |
| 14 | include Thrift::Struct |
| 15 | attr_accessor :byte |
| 16 | FIELDS = { |
| 17 | 1 => {:type => Thrift::Types::BYTE, :name => 'byte'} |
| 18 | } |
| 19 | end |
| 20 | |
| 21 | class OneI16 |
| 22 | include Thrift::Struct |
| 23 | attr_accessor :i16 |
| 24 | FIELDS = { |
| 25 | 1 => {:type => Thrift::Types::I16, :name => 'i16'} |
| 26 | } |
| 27 | end |
| 28 | |
| 29 | class OneI32 |
| 30 | include Thrift::Struct |
| 31 | attr_accessor :i32 |
| 32 | FIELDS = { |
| 33 | 1 => {:type => Thrift::Types::I32, :name => 'i32'} |
| 34 | } |
| 35 | end |
| 36 | |
| 37 | class OneI64 |
| 38 | include Thrift::Struct |
| 39 | attr_accessor :i64 |
| 40 | FIELDS = { |
| 41 | 1 => {:type => Thrift::Types::I64, :name => 'i64'} |
| 42 | } |
| 43 | end |
| 44 | |
| 45 | class OneDouble |
| 46 | include Thrift::Struct |
| 47 | attr_accessor :double |
| 48 | FIELDS = { |
| 49 | 1 => {:type => Thrift::Types::DOUBLE, :name => 'double'} |
| 50 | } |
| 51 | end |
| 52 | |
| 53 | class OneString |
| 54 | include Thrift::Struct |
| 55 | attr_accessor :string |
| 56 | FIELDS = { |
| 57 | 1 => {:type => Thrift::Types::STRING, :name => 'string'} |
| 58 | } |
| 59 | end |
| 60 | |
| 61 | class OneMap |
| 62 | include Thrift::Struct |
| 63 | attr_accessor :map |
| 64 | FIELDS = { |
| 65 | 1 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRING}} |
| 66 | } |
| 67 | end |
| 68 | |
| 69 | class NestedMap |
| 70 | include Thrift::Struct |
| 71 | attr_accessor :map |
| 72 | FIELDS = { |
| 73 | 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}}} |
| 74 | } |
| 75 | end |
| 76 | |
| 77 | class OneList |
| 78 | include Thrift::Struct |
| 79 | attr_accessor :list |
| 80 | FIELDS = { |
| 81 | 1 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::STRING}} |
| 82 | } |
| 83 | end |
| 84 | |
| 85 | class NestedList |
| 86 | include Thrift::Struct |
| 87 | attr_accessor :list |
| 88 | FIELDS = { |
| 89 | 0 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::LIST, :element => { :type => Thrift::Types::I32 } } } |
| 90 | } |
| 91 | end |
| 92 | |
| 93 | class OneSet |
| 94 | include Thrift::Struct |
| 95 | attr_accessor :set |
| 96 | FIELDS = { |
| 97 | 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::STRING}} |
| 98 | } |
| 99 | end |
| 100 | |
| 101 | class NestedSet |
| 102 | include Thrift::Struct |
| 103 | attr_accessor :set |
| 104 | FIELDS = { |
| 105 | 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::SET, :element => { :type => Thrift::Types::STRING } }} |
| 106 | } |
| 107 | end |
| 108 | |
| 109 | # struct OneOfEach { |
| 110 | # 1: bool im_true, |
| 111 | # 2: bool im_false, |
| 112 | # 3: byte a_bite, |
| 113 | # 4: i16 integer16, |
| 114 | # 5: i32 integer32, |
| 115 | # 6: i64 integer64, |
| 116 | # 7: double double_precision, |
| 117 | # 8: string some_characters, |
| 118 | # 9: string zomg_unicode, |
| 119 | # 10: bool what_who, |
| 120 | # 11: binary base64, |
| 121 | # } |
| 122 | class OneOfEach |
| 123 | include Thrift::Struct |
| 124 | attr_accessor :im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64 |
| 125 | FIELDS = { |
| 126 | 1 => {:type => Thrift::Types::BOOL, :name => 'im_true'}, |
| 127 | 2 => {:type => Thrift::Types::BOOL, :name => 'im_false'}, |
| 128 | 3 => {:type => Thrift::Types::BYTE, :name => 'a_bite'}, |
| 129 | 4 => {:type => Thrift::Types::I16, :name => 'integer16'}, |
| 130 | 5 => {:type => Thrift::Types::I32, :name => 'integer32'}, |
| 131 | 6 => {:type => Thrift::Types::I64, :name => 'integer64'}, |
| 132 | 7 => {:type => Thrift::Types::DOUBLE, :name => 'double_precision'}, |
| 133 | 8 => {:type => Thrift::Types::STRING, :name => 'some_characters'}, |
| 134 | 9 => {:type => Thrift::Types::STRING, :name => 'zomg_unicode'}, |
| 135 | 10 => {:type => Thrift::Types::BOOL, :name => 'what_who'}, |
| 136 | 11 => {:type => Thrift::Types::STRING, :name => 'base64'} |
| 137 | } |
| 138 | |
| 139 | # Added for assert_equal |
| 140 | def ==(other) |
| 141 | [:im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64].each do |f| |
| 142 | var = "@#{f}" |
| 143 | return false if instance_variable_get(var) != other.instance_variable_get(var) |
| 144 | end |
| 145 | true |
| 146 | end |
| 147 | end |
| 148 | |
| 149 | # struct Nested1 { |
| 150 | # 1: list<OneOfEach> a_list |
| 151 | # 2: map<i32, OneOfEach> i32_map |
| 152 | # 3: map<i64, OneOfEach> i64_map |
| 153 | # 4: map<double, OneOfEach> dbl_map |
| 154 | # 5: map<string, OneOfEach> str_map |
| 155 | # } |
| 156 | class Nested1 |
| 157 | include Thrift::Struct |
| 158 | attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map |
| 159 | FIELDS = { |
| 160 | 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, |
| 161 | 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, |
| 162 | 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, |
| 163 | 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}, |
| 164 | 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}} |
| 165 | } |
| 166 | end |
| 167 | |
| 168 | # struct Nested2 { |
| 169 | # 1: list<Nested1> a_list |
| 170 | # 2: map<i32, Nested1> i32_map |
| 171 | # 3: map<i64, Nested1> i64_map |
| 172 | # 4: map<double, Nested1> dbl_map |
| 173 | # 5: map<string, Nested1> str_map |
| 174 | # } |
| 175 | class Nested2 |
| 176 | include Thrift::Struct |
| 177 | attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map |
| 178 | FIELDS = { |
| 179 | 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested1}}, |
| 180 | 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}, |
| 181 | 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}, |
| 182 | 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}, |
| 183 | 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}} |
| 184 | } |
| 185 | end |
| 186 | |
| 187 | # struct Nested3 { |
| 188 | # 1: list<Nested2> a_list |
| 189 | # 2: map<i32, Nested2> i32_map |
| 190 | # 3: map<i64, Nested2> i64_map |
| 191 | # 4: map<double, Nested2> dbl_map |
| 192 | # 5: map<string, Nested2> str_map |
| 193 | # } |
| 194 | class Nested3 |
| 195 | include Thrift::Struct |
| 196 | attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map |
| 197 | FIELDS = { |
| 198 | 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested2}}, |
| 199 | 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}, |
| 200 | 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}, |
| 201 | 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}, |
| 202 | 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}} |
| 203 | } |
| 204 | end |
| 205 | |
| 206 | # struct Nested4 { |
| 207 | # 1: list<Nested3> a_list |
| 208 | # 2: map<i32, Nested3> i32_map |
| 209 | # 3: map<i64, Nested3> i64_map |
| 210 | # 4: map<double, Nested3> dbl_map |
| 211 | # 5: map<string, Nested3> str_map |
| 212 | # } |
| 213 | class Nested4 |
| 214 | include Thrift::Struct |
| 215 | attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map |
| 216 | FIELDS = { |
| 217 | 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested3}}, |
| 218 | 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}, |
| 219 | 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}, |
| 220 | 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}, |
| 221 | 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}} |
| 222 | } |
| 223 | end |
| 224 | end |
| 225 | end |